Skip to content

built-in rebase: pick up the ORIG_HEAD fix early #2112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 7, 2019

Conversation

dscho
Copy link
Member

@dscho dscho commented Mar 7, 2019

It was reported (a bit belatedly) that there was a regression in v2.21.0 where the built-in rebase would update ORIG_HEAD one times too many, so that it would not point at the pre-rebase state immediately after a rebase completed.

This regression is related (but not identical) to one that was already reported in early January (which was fixed immediately), and for which a regression test had been promised, but which did not materialize until after v2.21.0. Which is too bad, because that re-regression was totally avoidable.

This patch series fixes that problem, and adds a regression test (better late than never, right?) to avoid re-introducing that regression a third time.

This made it (in a slightly different form, see range-diff below) into git.git's next already, via git@f805f820b4b4. Let's take this early, to let Git for Windows' users benefit from the fix as soon as possible.

The range-diff (demonstrating that the RESET_HEAD_RUN_POST_CHECKOUT_HOOK constant requires an adjustment to the RESET_ORIG_HEAD constant):

$ git range-diff cbd29ead92d8~4..cbd29ead92d8 1c5bf602cb63~4..1c5bf602cb63
1:  e6aac8177d02 ! 1:  626431089390 built-in rebase: no need to check out `onto` twice
    @@ -21,7 +21,6 @@
         passing that flag.
     
         Signed-off-by: Johannes Schindelin <[email protected]>
    -    Signed-off-by: Junio C Hamano <[email protected]>
     
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
2:  eaf81605b8d1 ! 2:  f13cff1f6457 built-in rebase: use the correct reflog when switching branches
    @@ -5,7 +5,6 @@
         By mistake, we used the reflog intended for ORIG_HEAD.
     
         Signed-off-by: Johannes Schindelin <[email protected]>
    -    Signed-off-by: Junio C Hamano <[email protected]>
     
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
3:  c2d96293602b ! 3:  3dfe7f7bb92d built-in rebase: demonstrate that ORIG_HEAD is not set correctly
    @@ -11,7 +11,6 @@
         Reported by Nazri Ramliy.
     
         Signed-off-by: Johannes Schindelin <[email protected]>
    -    Signed-off-by: Junio C Hamano <[email protected]>
     
      diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
      --- a/t/t3400-rebase.sh
4:  cbd29ead92d8 ! 4:  1c5bf602cb63 built-in rebase: set ORIG_HEAD just once, before the rebase
    @@ -16,22 +16,21 @@
         So let's do that.
     
         Signed-off-by: Johannes Schindelin <[email protected]>
    -    Signed-off-by: Junio C Hamano <[email protected]>
     
      diff --git a/builtin/rebase.c b/builtin/rebase.c
      --- a/builtin/rebase.c
      +++ b/builtin/rebase.c
     @@
    - #define RESET_HEAD_DETACH (1<<0)
      #define RESET_HEAD_HARD (1<<1)
    - #define RESET_HEAD_REFS_ONLY (1<<2)
    -+#define RESET_ORIG_HEAD (1<<3)
    + #define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
    + #define RESET_HEAD_REFS_ONLY (1<<3)
    ++#define RESET_ORIG_HEAD (1<<4)
      
      static int reset_head(struct object_id *oid, const char *action,
      		      const char *switch_to_branch, unsigned flags,
     @@
    - 	unsigned detach_head = flags & RESET_HEAD_DETACH;
      	unsigned reset_hard = flags & RESET_HEAD_HARD;
    + 	unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
      	unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
     +	unsigned update_orig_head = flags & RESET_ORIG_HEAD;
      	struct object_id head_oid;
    @@ -75,8 +74,10 @@
      	strbuf_addf(&msg, "%s: checkout %s",
      		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
      	if (reset_head(&options.onto->object.oid, "checkout", NULL,
    --		       RESET_HEAD_DETACH, NULL, msg.buf))
    -+		       RESET_HEAD_DETACH | RESET_ORIG_HEAD, NULL, msg.buf))
    +-		       RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK,
    +-		       NULL, msg.buf))
    ++		       RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK |
    ++		       RESET_ORIG_HEAD, NULL, msg.buf))
      		die(_("Could not detach HEAD"));
      	strbuf_release(&msg);
      

dscho added 4 commits March 7, 2019 10:22
In the case that the rebase boils down to a fast-forward, the built-in
rebase reset the working tree twice: once to start the rebase at `onto`,
then realizing that the original (pre-rebase) HEAD was an ancestor and
we basically already fast-forwarded to the post-rebase HEAD,
`reset_head()` was called to update the original ref and to point HEAD
back to it.

That second `reset_head()` call does not need to touch the working tree,
though, as it does not change the actual tip commit (and therefore the
working tree should stay unchanged anyway): only the ref needs to be
updated (because the rebase detached the HEAD, and we want to go back to
the branch on which the rebase was started).

But that second `reset_head()` was called without the flag to leave the
working tree alone (the reason: when that call was introduced, that flag
was not yet even thought of). Let's avoid that unnecessary work by
passing that flag.

Signed-off-by: Johannes Schindelin <[email protected]>
By mistake, we used the reflog intended for ORIG_HEAD.

Signed-off-by: Johannes Schindelin <[email protected]>
The ORIG_HEAD pseudo ref is supposed to refer to the original,
pre-rebase state after a successful rebase. Let's add a regression test
to prove that this regressed: With GIT_TEST_REBASE_USE_BUILTIN=false,
this test case passes, with GIT_TEST_REBASE_USE_BUILTIN=true (or unset),
it fails.

Reported by Nazri Ramliy.

Signed-off-by: Johannes Schindelin <[email protected]>
Technically, the scripted version set ORIG_HEAD only in two spots (which
really could have been one, because it called `git checkout $onto^0` to
start the rebase and also if it could take a shortcut, and in both cases
it called `git update-ref $orig_head`).

Practically, it *implicitly* reset ORIG_HEAD whenever `git reset --hard`
was called.

However, what we really want is that it is set exactly once, at the
beginning of the rebase.

So let's do that.

Signed-off-by: Johannes Schindelin <[email protected]>
@dscho dscho requested a review from orgads March 7, 2019 09:30
@orgads
Copy link

orgads commented Mar 7, 2019

👍

@dscho
Copy link
Member Author

dscho commented Mar 7, 2019

@orgads thank you for reviewing!

@dscho dscho merged commit 6b27cae into git-for-windows:master Mar 7, 2019
@dscho dscho deleted the gfw/rebase-am-and-orig-head branch March 7, 2019 11:56
@dscho dscho added this to the v2.21.0(2) milestone Mar 7, 2019
git-for-windows-ci pushed a commit that referenced this pull request Mar 7, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Mar 7, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Mar 11, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Mar 11, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Mar 11, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Mar 11, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Mar 18, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Apr 5, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Apr 5, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Apr 11, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request Apr 16, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Apr 27, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request May 8, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request May 9, 2019
built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request May 10, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit to dscho/git that referenced this pull request May 13, 2019
…orig-head

built-in rebase: pick up the ORIG_HEAD fix early
git-for-windows-ci pushed a commit that referenced this pull request May 14, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request May 21, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request May 22, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request May 25, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Jun 4, 2019
built-in rebase: pick up the ORIG_HEAD fix early
dscho added a commit that referenced this pull request Jun 8, 2019
built-in rebase: pick up the ORIG_HEAD fix early
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