Fix checkout-dash to work with rebase
v2 cover Fix checkout-dash to work with rebase
So after extensive discussions with Junio, I have updated [5/6] to special-case rebase and rebase -i instead of dropping the "HEAD detached from" message altogether. Also, [1/6] includes two more tests, as suggested by Junio.
Junio: The message is now the constant "rebase in progress; onto $ONTO". Feel free to tweak it before applying.
Thanks.
Ramkumar Ramachandra (6):
t/checkout-last: checkout - doesn't work after rebase
rebase: prepare to write reflog message for checkout rebase -i: prepare to write reflog message for checkout
wt-status: remove unused field in grab_1st_switch_cbdata
status: do not depend on rebase reflog messages
checkout: respect GIT_REFLOG_ACTION
builtin/checkout.c | 11 ++++++++--- git-rebase--interactive.sh | 2 ++ git-rebase.sh | 2 ++ t/t2012-checkout-last.sh | 34 ++++++++++++++++++++++++++++++++++ t/t7512-status-help.sh | 37 +++++++++++++++++-------------------- wt-status.c | 7 ++++--- 6 files changed, 67 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.3.1.443.g4fd77b9
PATCH v2 1/6 t/checkout-last: checkout - doesn't work after rebase
The following command
$ git checkout -
does not work as expected after a rebase. Every kind of rebase must behave in the exactly same way: for the purposes of checkout -, the rebase event should be inconsequential.
Add four failing tests documenting this bug: two for a normal rebase, and another two for an interactive rebase.
--- t/t2012-checkout-last.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
t/t2012-checkout-last.sh +34 -0
@@ -116,4 +116,38 @@ test_expect_success 'master...' ' test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)" ' +test_expect_failure '"checkout -" works after a rebase A' ' + git checkout master && + git checkout other && + git rebase master && + git checkout - && + test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" +' + +test_expect_failure '"checkout -" works after a rebase A B' ' + git branch moodle master~1 && + git checkout master && + git checkout other && + git rebase master moodle && + git checkout - && + test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" +' + +test_expect_failure '"checkout -" works after a rebase -i A' ' + git checkout master && + git checkout other && + git rebase -i master && + git checkout - && + test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" +' + +test_expect_failure '"checkout -" works after a rebase -i A B' ' + git branch foodle master~1 && + git checkout master && + git checkout other && + git rebase master foodle && + git checkout - && + test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" +' + test_done
Signature · 1 line
1.8.3.1.443.g4fd77b9
PATCH v2 2/6 rebase: prepare to write reflog message for checkout
In reply to Ramkumar RamachandraThe branch-flipping rebase internally does is not 'checkout' as far as the end-user is concerned; therefore, rebase should never write "checkout: " messages to the reflog. To achieve this, set a sensible GIT_REFLOG_ACTION; checkout does not respect this variable yet, but a future patch will change this.
After that patch, rebase will write the following line to the reflog when started:
rebase: checkout master
This is much better than the confusing message it currently writes:
checkout: moving from master to 1462b67
--- git-rebase.sh | 2 ++ 1 file changed, 2 insertions(+)
git-rebase.sh +2 -0
@@ -568,6 +568,8 @@ test "$type" = interactive && run_specific_rebase # Detach HEAD and reset the tree say "$(gettext "First, rewinding head to replay your work on top of it...")" + +GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $orig_head
Signature · 1 line
1.8.3.1.443.g4fd77b9
PATCH v2 3/6 rebase -i: prepare to write reflog message for checkout
In reply to Ramkumar RamachandraThe branch-flipping rebase -i internally does is not 'checkout' as far as the end-user is concerned; therefore, rebase -i should never write "checkout: " messages to the reflog. To achieve this, set a sensible GIT_REFLOG_ACTION; checkout does not respect this variable yet, but a future patch will change this.
After that patch, rebase -i will write the following line to the reflog when started:
rebase -i (start): checkout master
This is much better than the confusing message it currently writes:
checkout: moving from master to 1462b67
--- git-rebase--interactive.sh | 2 ++ 1 file changed, 2 insertions(+)
git-rebase--interactive.sh +2 -0
@@ -838,6 +838,7 @@ comment_for_reflog start if test ! -z "$switch_to" then + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" output git checkout "$switch_to" -- || die "Could not checkout $switch_to" fi
@@ -981,6 +982,7 @@ has_action "$todo" || test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks +GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" output git checkout $onto || die_abort "could not detach HEAD" git update-ref ORIG_HEAD $orig_head do_rest
Signature · 1 line
1.8.3.1.443.g4fd77b9
PATCH v2 4/6 wt-status: remove unused field in grab_1st_switch_cbdata
In reply to Ramkumar RamachandraThe struct grab_1st_switch_cbdata has the field "found", which is set in grab_1st_switch() when a match is found. This information is redundant and unused by any caller: the return value of the function serves to communicate this information anyway. Remove the field.
--- wt-status.c | 2 -- 1 file changed, 2 deletions(-)
wt-status.c +0 -2
@@ -1035,7 +1035,6 @@ got_nothing: }struct grab_1st_switch_cbdata { -int found;struct strbuf buf;unsigned char nsha1[20 ]; };
@@ -1059,7 +1058,6 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,for (end = target; *end && *end !='\n' ; end++) ;strbuf_add (&cb->buf, target, end - target); - cb->found =1 ;return 1 ; }
Signature · 1 line
1.8.3.1.443.g4fd77b9
PATCH v2 5/6 status: do not depend on rebase reflog messages
In reply to Ramkumar Ramachandrab397ea4 (status: show more info than "currently not on any branch", 2013-03-13) made the output of 'git status' richer in the case of a detached HEAD. Before this patch, with a detached HEAD:
$ git status # Not currently on any branch.
After the patch:
$ git checkout v1.8.2 $ git status # HEAD detached at v1.8.2.
It works by digging the reflog for the most recent message of the form "checkout: moving from xxxx to yyyy". It then asserts that HEAD and "yyyy" are the same, and displays this message. When they aren't equal, it displays:
$ git status # HEAD detached from fe11db.
In case of a rebase [-i] operation in progress, this message depends on the implementation of rebase writing "checkout: " messages to the reflog. To remove this dependency so that rebase can be updated to write better reflog messages, replace this "HEAD detached from" message with the constant:
# rebase in progress; onto $ONTO
The issue is not isolated to rebase at all. Several other scripts like bisect write "checkout: " messages to the reflog, and the tests in t/status-help depend on them. Fixing them is left as an exercise to other contributors.
--- t/t7512-status-help.sh | 37 +++++++++++++++++-------------------- wt-status.c | 5 ++++- 2 files changed, 21 insertions(+), 21 deletions(-)
t/t7512-status-help.sh +17 -20
@@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts' ONTO=$(git rev-parse --short HEAD^^) && test_must_fail git rebase HEAD^ --onto HEAD^^ && cat >expected <<-EOF && - # HEAD detached at $ONTO + # rebase in progress; onto $ONTO # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. # (fix conflicts and then run "git rebase --continue") # (use "git rebase --skip" to skip this patch)
@@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' ' echo three >main.txt && git add main.txt && cat >expected <<-EOF && - # HEAD detached at $ONTO + # rebase in progress; onto $ONTO # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. # (all conflicts fixed: run "git rebase --continue") #
@@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' ' ONTO=$(git rev-parse --short rebase_i_conflicts) && test_must_fail git rebase -i rebase_i_conflicts && cat >expected <<-EOF && - # HEAD detached at $ONTO + # rebase in progress; onto $ONTO # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. # (fix conflicts and then run "git rebase --continue") # (use "git rebase --skip" to skip this patch)
@@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' ' test_must_fail git rebase -i rebase_i_conflicts && git add main.txt && cat >expected <<-EOF && - # HEAD detached at $ONTO + # rebase in progress; onto $ONTO # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. # (all conflicts fixed: run "git rebase --continue") #
@@ -188,10 +188,9 @@ test_expect_success 'status when rebasing -i in edit mode' ' export FAKE_LINES && test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD~2) && - TGT=$(git rev-parse --short two_rebase_i) && git rebase -i HEAD~2 && cat >expected <<-EOF && - # HEAD detached from $TGT + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -216,9 +215,8 @@ test_expect_success 'status when splitting a commit' ' ONTO=$(git rev-parse --short HEAD~3) && git rebase -i HEAD~3 && git reset HEAD^ && - TGT=$(git rev-parse --short HEAD) && cat >expected <<-EOF && - # HEAD detached at $TGT + # rebase in progress; onto $ONTO # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''. # (Once your working directory is clean, run "git rebase --continue") #
@@ -246,11 +244,10 @@ test_expect_success 'status after editing the last commit with --amend during a export FAKE_LINES && test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD~3) && - TGT=$(git rev-parse --short three_amend) && git rebase -i HEAD~3 && git commit --amend -m "foo" && cat >expected <<-EOF && - # HEAD detached from $TGT + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -280,7 +277,7 @@ test_expect_success 'status: (continue first edit) second edit' ' git rebase -i HEAD~3 && git rebase --continue && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -302,7 +299,7 @@ test_expect_success 'status: (continue first edit) second edit and split' ' git rebase --continue && git reset HEAD^ && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (Once your working directory is clean, run "git rebase --continue") #
@@ -329,7 +326,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' ' git rebase --continue && git commit --amend -m "foo" && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -351,7 +348,7 @@ test_expect_success 'status: (amend first edit) second edit' ' git commit --amend -m "a" && git rebase --continue && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -374,7 +371,7 @@ test_expect_success 'status: (amend first edit) second edit and split' ' git rebase --continue && git reset HEAD^ && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (Once your working directory is clean, run "git rebase --continue") #
@@ -402,7 +399,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' ' git rebase --continue && git commit --amend -m "d" && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -426,7 +423,7 @@ test_expect_success 'status: (split first edit) second edit' ' git commit -m "e" && git rebase --continue && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -451,7 +448,7 @@ test_expect_success 'status: (split first edit) second edit and split' ' git rebase --continue && git reset HEAD^ && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (Once your working directory is clean, run "git rebase --continue") #
@@ -481,7 +478,7 @@ test_expect_success 'status: (split first edit) second edit and amend' ' git rebase --continue && git commit --amend -m "h" && cat >expected <<-EOF && - # HEAD detached from $ONTO + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
@@ -601,7 +598,7 @@ test_expect_success 'status when rebase conflicts with statushints disabled' ' ONTO=$(git rev-parse --short HEAD^^) && test_must_fail git rebase HEAD^ --onto HEAD^^ && cat >expected <<-EOF && - # HEAD detached at $ONTO + # rebase in progress; onto $ONTO # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''. # # Unmerged paths:
wt-status.c +4 -1
@@ -1174,7 +1174,10 @@ void wt_status_print(struct wt_status *s) branch_name +=11 ; else if (!strcmp(branch_name, "HEAD")) { branch_status_color =color (WT_STATUS_NOBRANCH , s); -if (state.detached_from) { +if (state.rebase_in_progress || state.rebase_interactive_in_progress) { + on_what =_ ("rebase in progress; onto " ); + branch_name = state.onto; + }else if (state.detached_from) {unsigned char sha1[20 ]; branch_name = state.detached_from; if (!get_sha1("HEAD", sha1) &&
Signature · 1 line
1.8.3.1.443.g4fd77b9
Re: [PATCH v2 5/6] status: do not depend on rebase reflog messages
Quoted 6 lines · Ramkumar Ramachandra
t/t7512-status-help.sh +0
-0@@ -188,10 +188,9 @@ test_expect_success 'status when rebasing -i in edit mode' ' export FAKE_LINES &&
t/t7512-status-help.sh test_expect_success 'status when rebasing -i in edit mode' ' · line 196
Quoted 10 lines
t/t7512-status-help.sh +1
-2test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD~2) && - TGT=$(git rev-parse --short two_rebase_i) && git rebase -i HEAD~2 && cat >expected <<-EOF && - # HEAD detached from $TGT + # rebase in progress; onto $ONTO # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''. # (use "git commit --amend" to amend the current commit) # (use "git rebase --continue" once you are satisfied with your changes)
This hunk (and others that used to use $TGT) shows that the original test was depending too much on the implementation detail (i.e. that rebase/rebase-i internally uses checkout to affect the reflog, making the info shown as "detached from/at" not useful during "rebase"). This step may have started as a workaround against the fallout from 6/6, but I think this is a good change by itself independent of "checkut -" fix, which is the main topic of this series.
wt-status.c void wt_status_print(struct wt_status *s) · line 1179
Quoted 12 lines
wt-status.c +3
-1@@ -1174,7 +1174,10 @@ void wt_status_print(struct wt_status *s) branch_name +=11 ; else if (!strcmp(branch_name, "HEAD")) { branch_status_color =color (WT_STATUS_NOBRANCH , s); -if (state.detached_from) { +if (state.rebase_in_progress || state.rebase_interactive_in_progress) { + on_what =_ ("rebase in progress; onto " ); + branch_name = state.onto;
The part after "||" is what I missed in the "how about an approach along this line" patch.
Good job.
Quoted 4 lines
wt-status.c +1
-0+ }else if (state.detached_from) {unsigned char sha1[20 ]; branch_name = state.detached_from; if (!get_sha1("HEAD", sha1) &&
PATCH v2 6/6 checkout: respect GIT_REFLOG_ACTION
In reply to Ramkumar RamachandraGIT_REFLOG_ACTION is an environment variable specifying the reflog message to write after an action is completed. Several other commands including merge, reset, and commit respect it.
Fix the failing tests in t/checkout-last by making checkout respect it too. You can now expect
$ git checkout -
to work as expected after any rebase operation.
--- builtin/checkout.c | 11 ++++++++--- t/t2012-checkout-last.sh | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-)
builtin/checkout.c +8 -3
@@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, struct branch_info *new) {struct strbuf msg =STRBUF_INIT ; -const char *old_desc; +const char *old_desc, *reflog_msg;if (opts->new_branch) {if (opts->new_orphan_branch) {if (opts->new_branch_log && !log_all_ref_updates) {
@@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts, old_desc = old->name;if (!old_desc && old->commit) old_desc =sha1_to_hex (old->commit->object.sha1); -strbuf_addf (&msg,"checkout: moving from %s to %s" , - old_desc ? old_desc :"(invalid)" , new->name); + + reflog_msg =getenv ("GIT_REFLOG_ACTION" ); +if (!reflog_msg) +strbuf_addf (&msg,"checkout: moving from %s to %s" , + old_desc ? old_desc :"(invalid)" , new->name); +else +strbuf_insert (&msg,0 , reflog_msg,strlen (reflog_msg));if (!strcmp (new->name,"HEAD" ) && !new->path && !opts->force_detach) {/* Nothing to do. */
t/t2012-checkout-last.sh +4 -4
@@ -116,7 +116,7 @@ test_expect_success 'master...' ' test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)" ' -test_expect_failure '"checkout -" works after a rebase A' ' +test_expect_success '"checkout -" works after a rebase A' ' git checkout master && git checkout other && git rebase master &&
@@ -124,7 +124,7 @@ test_expect_failure '"checkout -" works after a rebase A' ' test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" ' -test_expect_failure '"checkout -" works after a rebase A B' ' +test_expect_success '"checkout -" works after a rebase A B' ' git branch moodle master~1 && git checkout master && git checkout other &&
@@ -133,7 +133,7 @@ test_expect_failure '"checkout -" works after a rebase A B' ' test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" ' -test_expect_failure '"checkout -" works after a rebase -i A' ' +test_expect_success '"checkout -" works after a rebase -i A' ' git checkout master && git checkout other && git rebase -i master &&
@@ -141,7 +141,7 @@ test_expect_failure '"checkout -" works after a rebase -i A' ' test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" ' -test_expect_failure '"checkout -" works after a rebase -i A B' ' +test_expect_success '"checkout -" works after a rebase -i A B' ' git branch foodle master~1 && git checkout master && git checkout other &&
Signature · 1 line
1.8.3.1.443.g4fd77b9
Quoted 7 lines · Ramkumar Ramachandra
So after extensive discussions with Junio, I have updated [5/6] to special-case rebase and rebase -i instead of dropping the "HEAD detached from" message altogether. Also, [1/6] includes two more tests, as suggested by Junio.
Junio: The message is now the constant "rebase in progress; onto $ONTO".
That message is better than I was anticipating.
I was actually assuming that you would leave them as they are i.e. "# HEAD detached at xxx", as we agreed that we will see them improved anyway by the other topic.
I am still puzzled to see that the change to checkout comes at the very end. With "do not depend on rebase reflog messages" done before the "checkout: respect reflog-action", I was hoping that we can have changes to the actual reflog message made to rebase (patch 2 and 3) can be done at the very end. Was I missing something else?
In other words, the order I was anticipating to see after the discussion (this is different from saying "A series that is not ordered like this is unacceptable") was:
Quoted 1 line
wt-status: remove unused field in
grab_1st_switch_cbdata
This is an unrelated clean-up, and can be done before anything else.
Quoted 1 line
t/checkout-last: checkout - doesn't work after rebase
This spells out what we want to happen at the end and marks the current breakage.
Quoted 1 line
status: do not depend on rebase reflog messages
This compensates for fallouts from the next change.
Quoted 1 line
checkout: respect
GIT_REFLOG_ACTION
And this is the fix, the most important step.
Quoted 2 lines
rebase: prepare to write reflog message for checkout rebase -i: prepare to write reflog message for checkout
And these are icing on the cake, but that cannot be done before status is fixed.
Quoted 19 lines · Junio C Hamano
In other words, the order I was anticipating to see after the discussion (this is different from saying "A series that is not ordered like this is unacceptable") was:
Quoted 1 line
wt-status: remove unused field in
grab_1st_switch_cbdataThis is an unrelated clean-up, and can be done before anything else.
Quoted 1 line
t/checkout-last: checkout - doesn't work after rebase
This spells out what we want to happen at the end and marks the current breakage.
Quoted 1 line
status: do not depend on rebase reflog messages
This compensates for fallouts from the next change.
Quoted 1 line
checkout: respect
GIT_REFLOG_ACTION
Quoted 7 lines
And this is the fix, the most important step.
Quoted 2 lines
rebase: prepare to write reflog message for checkout rebase -i: prepare to write reflog message for checkout
And these are icing on the cake, but that cannot be done before status is fixed.
I actually tried to reorder the patches and they seem to work OK as expected. And I think it makes sense to order them the way I've been suggesting, so I'll tentatively queue the result of reordering on 'rr/rebase-checkout-reflog' and push it out as a part of 'pu'.
Please check to see if I introduced a new bug while doing so.
Regardless of the ordering, however, I suspect two patches that change the message recorded in reflog in "rebase" need further fixing.
For example, the one in "git reabse" does this:
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $orig_head
...
run_specific_rebase
But the specific rebase, e.g. git-rebase--interactive, does this:
case $head_name in
refs/*)
message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
git update-ref -m "$message" $head_name $newhead $orig_head &&
git symbolic-ref \
-m "$GIT_REFLOG_ACTION: returning to $head_name" \
HEAD $head_name
;;
esac && {I think the message you added to "git reabse" is only meant for that specific "checkout $onto", but it is set globally. Wouldn't it affect later use, which expected it to be "rebase" and nothing else?
Perhaps something like this on top of the entire series may be sufficient (which will be queued as "SQUASH???" at the tip).
Hint for anybody (not limited to Ram):
There also are other 'git checkout' invocations in git-rebase\*.sh that are not yet covered by these "nicer reflog message" patches, which may want to be fixed up before these two icing-on-cake patches become ready to be merged; see output of
git grep -C2 'git checkout' -- git-rebase\*.sh
Thanks.
git-rebase--interactive.sh | 15 ++++++++++----- git-rebase.sh | 4 ++-- t/t3404-rebase-interactive.sh | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-)
git-rebase--interactive.sh +10 -5
@@ -837,9 +837,11 @@ comment_for_reflog start if test ! -z "$switch_to" then - GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" - output git checkout "$switch_to" -- || - die "Could not checkout $switch_to" + ( + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" + export GIT_REFLOG_ACTION + output git checkout "$switch_to" -- + ) || die "Could not checkout $switch_to" fi orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
@@ -981,7 +983,10 @@ has_action "$todo" || test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks -GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" -output git checkout $onto || die_abort "could not detach HEAD" +( + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" + export GIT_REFLOG_ACTION + output git checkout $onto +) || die_abort "could not detach HEAD" git update-ref ORIG_HEAD $orig_head do_rest
git-rebase.sh +2 -2
@@ -523,8 +523,8 @@ test "$type" = interactive && run_specific_rebase # Detach HEAD and reset the tree say "$(gettext "First, rewinding head to replay your work on top of it...")" -GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" -git checkout -q "$onto^0" || die "could not detach HEAD" +GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \ + git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $orig_head # If the $onto is a proper descendant of the tip of the branch, then
t/t3404-rebase-interactive.sh +15 -0
@@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test L = $(git cat-file commit HEAD | sed -ne \$p) ' +test_expect_success 'rebase -i produces readable reflog' ' + git reset --hard && + git branch -f branch1 H && + git rebase -i --onto I F branch1 && + cat >expect <<-\EOF && + rebase -i (start): checkout I + rebase -i (pick): G + rebase -i (pick): H + rebase -i (finish): returning to refs/heads/branch1 + EOF + tail -n 4 .git/logs/HEAD | + sed -e "s/.* //" >actual && + test_cmp expect actual +' + test_expect_success 'rebase -i respects core.commentchar' ' git reset --hard && git checkout E^0 &&
t/t3404-rebase-interactive.sh test_expect_success 'rebase --edit-todo can be used to modify todo' ' · line 937
Quoted 9 lines · Junio C Hamano
t/t3404-rebase-interactive.sh +1
-0@@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test L = $(git cat-file commit HEAD | sed -ne \$p) ' +test_expect_success 'rebase -i produces readable reflog' '
I don't know if this test is a good idea at all. We never directly check the messages written by a command to the reflog, and I suspect that there is a good reason for this: the format of .git/logs is not guaranteed to be stable, and the messages written by various commands are not guaranteed to be stable either; the only machine-parsing of reflogs we do is very minimal: interpret_nth_prior_checkout() and grab_1st_switch().
A quick
$ git grep .git/logs -- t
shows that I'm mostly right about this.
Why make an exception in the case of rebase -i? In the worst case, the patch atleast needs to be discussed as an independent patch: it's certainly not obvious enough to sneak into this series. I'll submit a re-roll without this hunk.
Quoted 9 lines · Ramkumar Ramachandra
Quoted 8 lines · Junio C Hamano
t/t3404-rebase-interactive.sh +0
-0@@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test L = $(git cat-file commit HEAD | sed -ne \$p) '
Quoted 3 lines
t/t3404-rebase-interactive.sh test_expect_success 'rebase --edit-todo can be used to modify todo' ' · line 937
Quoted 1 line
t/t3404-rebase-interactive.sh +1
-0+test_expect_success 'rebase -i produces readable reflog' 'I don't know if this test is a good idea at all.
It is.
This catches "a change to GIT_REFLOG_ACTION that is meant to only apply to checkout done internally in git-rebase leaks to the later codepath and affects the reflog message left by rebase--interactive".
Apply the test change without the "do not leak" part in the fix-up (queued as a single "SQUASH???" commit on 'pu') to what you posted earlier and see how it breaks.
# rr/rebase-checkout-reflog with fix-up
$ git checkout 33b1cdeb
# revert the fix but keep the test
$ git checkout HEAD^ -- git-rebase--interactive.sh git-rebase.sh
# run the test
$ make && cd t && sh ./t3404-*.sh -v -iThe test fails with this:
--- expect 2013-06-18 16:09:21.000000000 +0000
+++ actual 2013-06-18 16:09:21.000000000 +0000
@@ -1,4 +1,4 @@
-rebase -i (start): checkout I
+rebase -i (start): checkout branch-reflog-test: checkout I
rebase -i (pick): G
rebase -i (pick): H
rebase -i (finish): returning to refs/heads/branch-reflog-test
"checkout branch-reflog-test" part is leaking from your setting of GIT_REFLOG_ACTION for "git checkout" in "git rebase"; it is only necessary to affect that "checkout" and it should not affect later commands that write reflog entries, but we see the breakage.
And that is why I did the fix-up to make sure your changes only apply to "git checkout".
If you apply the test part of that fixup to what you posted today, what would you see? I didn't look at the patches very closely, but I wouldn't be surprised if they are still leaking the change meant only to "checkout" to the later stages and breaking that test (the reason why I would not be surprised is because the impression I am getting from reading your responses is that you do not understand why it is bad not to limit the setting only to checkout).
Quoted 1 line
Why make an exception in the case of rebase -i?
Because the whole point of last two patches are "word reflog messages better for rebase", the improvements made by these two patches are better protected from future changes; it also makes sure that deliberate improvements will show up as changes to the tests.
Quoted 13 lines · Junio C Hamano
Apply the test change without the "do not leak" part in the fix-up (queued as a single "SQUASH???" commit on 'pu') to what you posted earlier and see how it breaks.
--- expect 2013-06-18 16:09:21.000000000 +0000
+++ actual 2013-06-18 16:09:21.000000000 +0000
@@ -1,4 +1,4 @@
-rebase -i (start): checkout I
+rebase -i (start): checkout branch-reflog-test: checkout I
rebase -i (pick): G
rebase -i (pick): H
rebase -i (finish): returning to refs/heads/branch-reflog-test
Quoted 2 lines
If you apply the test part of that fixup to what you posted today, what would you see?
Damn it! I didn't realize that your subshell was for a do-not-leak. I'm feeling especially stupid now.
Will post a re-roll in a bit.
Quoted 6 lines · Junio C Hamano
I actually tried to reorder the patches and they seem to work OK as expected. And I think it makes sense to order them the way I've been suggesting, so I'll tentatively queue the result of reordering on 'rr/rebase-checkout-reflog' and push it out as a part of 'pu'.
Please check to see if I introduced a new bug while doing so.
Thanks for the reorder and commit message tweaks. I'm working on the series you put up on pu now.
Quoted 20 lines
For example, the one in "git reabse" does this:
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref
ORIG_HEAD$orig_head
...
run_specific_rebaseBut the specific rebase, e.g. git-rebase--interactive, does this:
case $head_name in refs/*) message="$GIT_REFLOG_ACTION: $head_name onto $onto" && git update-ref -m "$message" $head_name $newhead $orig_head && git symbolic-ref \ -m "$GIT_REFLOG_ACTION: returning to $head_name" \ HEAD $head_name ;; esac && {
Quoted 3 lines
I think the message you added to "git reabse" is only meant for that specific "checkout $onto", but it is set globally. Wouldn't it affect later use, which expected it to be "rebase" and nothing else?
Both rebase.sh and rebase--interactive.sh set a sane GIT_REFLOG_ACTION right on top (using set_reflog_action), so no worries. I'll just double-check to make sure that no bogus/ incorrect messages are printed.
Quoted 2 lines
Perhaps something like this on top of the entire series may be sufficient (which will be queued as "SQUASH???" at the tip).
I think this takes the wrong approach to the problem. In my opinion, the correct approach is to actually overshadow die() with a function that clears GIT_REFLOG_ACTION before calling die().
Quoted 1 line
git grep -C2 'git checkout' -- git-rebase\*.sh
Ugh. I'll check all the codepaths thoroughly before submitting a re-roll.
Thanks.
Quoted 2 lines · Ramkumar Ramachandra
Thanks for the reorder and commit message tweaks. I'm working on the series you put up on
punow.
That said, I do not agree with one of your commit message updates:
checkout: respect GIT_REFLOG_ACTION
GIT_REFLOG_ACTION is an environment variable specifying the reflog message to write after an action is completed. Several other commands including merge, reset, and commit respect it.
Fix the failing tests in t/checkout-last by making checkout respect it too. You can now expect
$ git checkout -
to work as expected after any operation that internally uses "checkout" as its implementation detail, e.g. "rebase".
After the patch you _cannot_ expect checkout-dash to work after any operation that internally uses checkout; it's limited to rebase. Many other scripts (eg. bisect) do _not_ set GIT_REFLOG_ACTION at all.