Skip to content

Conversation

@axosoft-ramint
Copy link
Contributor

@axosoft-ramint axosoft-ramint commented Nov 19, 2024

Fixes #3747

Updates property names to be clearer in rebase command, and uses the correct side of the left-right commit count to:

  1. Determine if the current branch is caught up to the destination
  2. Determine how many commits will be rebased on top of the destination

Repro steps:

  1. Choose a rebase command: "rebase current branch onto branch", "rebase current branch onto tip", or "GitLens: Git Rebase" command palette command.

  2. Before: Quickpick prevents rebase and states that the current branch is already up-to-date with the destination when it is not. After: Quickpick should allow the rebase, and give the correct number of commits that will be rebased on top of the destination.

Updates property names to be clearer
Comment on lines +222 to +228
createRevisionRange(state.destination.ref, context.branch.ref, '...'),
{ excludeMerges: true },
);

const title = `${context.title} ${getReferenceLabel(state.reference, { icon: false, label: false })}`;
const count = counts != null ? counts.left : 0;
if (count === 0) {
const title = `${context.title} ${getReferenceLabel(state.destination, { icon: false, label: false })}`;
const ahead = counts != null ? counts.right : 0;
const behind = counts != null ? counts.left : 0;
Copy link
Contributor Author

@axosoft-ramint axosoft-ramint Nov 19, 2024

Choose a reason for hiding this comment

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

The core of the bug lies in these lines. The ref that is passed into the rebase command via state is the destination of the rebase, not the source. The rebase command is rebasing the current branch (previously housed in context.destination, renamed now to context.branch onto the chosen branch (previously housed in state.reference, renamed here to state.destination).

When we get the counts in container.git.getLeftRightCommitCount, we consistently put the "destination" on the left of the git revision range. In this case, because of the mislabeling, we were putting the source (current branch) on the left side and calling it the "destination", and the actual destination (chosen branch) is on the right side. So counts.left was giving us "how many commits ahead the current branch is" when we really wanted to know "how many commits behind the current branch is". In the messaging further down though, we say "will rebase by applying X commits on top of". Here, we want to know "how many commits ahead the current branch is".

So I split the counts into clearly labeled ahead and behind variables, put the "destination" and "source" into the correct slots of the revision range, and renamed everywhere so that it's clear that the destination is the argument provided to the command in the state/initial state, and the source is the current branch that we load into the context.

@axosoft-ramint axosoft-ramint merged commit 5b38c36 into main Nov 21, 2024
3 checks passed
@axosoft-ramint axosoft-ramint deleted the bugs/3747-rebase-current-branch branch November 21, 2024 15:17
d13 pushed a commit that referenced this pull request Nov 21, 2024
* Uses correct counts in rebase condition/messaging

Updates property names to be clearer

* Updates placeholder wording
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.

"Rebase Current Branch onto Branch" incorrectly shows that the current branch is caught up to the destination

3 participants