Skip to content

Conversation

@him0
Copy link
Owner

@him0 him0 commented Jul 16, 2025

Summary

  • Fixed a bug where currentBranch variable was not updated after branch deletion and checkout
  • This caused incorrect behavior when syncing after merging a feature branch
  • Now matches hub sync behavior exactly

Problem

When using gh-sync after merging a feature branch:

  • hub sync: Switches to main branch cleanly with no staged changes
  • gh-sync (before fix): Switches to main but stages differences between feature branch and main

Root Cause

The currentBranch variable was passed by value to processBranch(), so when a branch was deleted and checkout occurred, the main loop still thought the deleted branch was current. This caused the default branch to be processed incorrectly on the next iteration.

Solution

  • Changed currentBranch parameter to a pointer in processBranch()
  • Update *currentBranch = defaultBranch after checkout when deleting current branch
  • This ensures subsequent branch processing uses the correct current branch

Test Plan

  1. Create a feature branch and make commits
  2. Create a PR and merge it on GitHub
  3. Run gh sync while still on the feature branch locally
  4. Verify that it switches to main/master with no staged changes

🤖 Generated with Claude Code

When a feature branch is deleted during sync, the currentBranch variable
was not being updated after checkout. This caused the new current branch
(default branch) to be processed incorrectly in subsequent iterations,
leading to staging of differences between the deleted feature branch
and the default branch.

This fix updates currentBranch to track the actual current branch after
checkout, matching hub sync behavior exactly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@him0 him0 requested a review from Copilot July 16, 2025 17:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the currentBranch variable was not properly updated after branch deletion and checkout operations, causing incorrect behavior during subsequent branch processing in the sync loop.

  • Changed currentBranch parameter from pass-by-value to pass-by-pointer in processBranch()
  • Added proper update of current branch tracking after checkout when deleting the current branch
  • Updated all references to currentBranch to use pointer dereferencing

@him0 him0 merged commit c7d895a into main Jul 16, 2025
@him0 him0 deleted the fix-current-branch-sync branch July 16, 2025 17:02
@him0
Copy link
Owner Author

him0 commented Jul 16, 2025

@claude hi

@claude
Copy link

claude bot commented Jul 16, 2025

Claude finished @him0's task —— View job


Hi there! 👋

Thanks for the greeting! I see this PR about fixing current branch tracking after deletion has already been merged - nice work on that fix!

I'm here to help with code reviews, answer questions about your codebase, or implement changes when you need them. Feel free to tag me on issues or PRs whenever you'd like assistance with:

  • Code reviews and feedback
  • Bug fixes and feature implementations
  • Questions about your code
  • Analyzing and improving existing functionality

Just let me know what you'd like me to help with!


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants