threads / patch / 34162

v2, 6 partsFix checkout-dash to work with rebase

Subject: [PATCH v2 0/6] Fix checkout-dash to work with rebase

## tl;dr

15 messages between Jun 16, 2013 and Jun 18, 2013. Diffs are folded; open one to read it.

replies: 14people: 2as markdown or json

Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · lore

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(-)
-- 
1.8.3.1.443.g4fd77b9
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[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.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 t/t2012-checkout-last.sh | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Show changes to t/t2012-checkout-last.sh +34 −0
diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh
index b44de9d..6ad6edf 100755
--- a/t/t2012-checkout-last.sh
+++ b/t/t2012-checkout-last.sh
@@ -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
-- 
1.8.3.1.443.g4fd77b9
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[PATCH v2 2/6] rebase: prepare to write reflog message for checkout

The 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
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-rebase.sh | 2 ++
 1 file changed, 2 insertions(+)
Show changes to git-rebase.sh +2 −0
diff --git a/git-rebase.sh b/git-rebase.sh
index d0c11a9..6587019 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -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
 
-- 
1.8.3.1.443.g4fd77b9
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[PATCH v2 3/6] rebase -i: prepare to write reflog message for checkout

The 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
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 git-rebase--interactive.sh | 2 ++
 1 file changed, 2 insertions(+)
Show changes to git-rebase--interactive.sh +2 −0
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f953d8d..0f04425 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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
-- 
1.8.3.1.443.g4fd77b9
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[PATCH v2 4/6] wt-status: remove unused field in grab_1st_switch_cbdata

The 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.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 wt-status.c | 2 --
 1 file changed, 2 deletions(-)
Show changes to wt-status.c +0 −2
diff --git a/wt-status.c b/wt-status.c
index bf84a86..2511270 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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;
 }
 
-- 
1.8.3.1.443.g4fd77b9
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[PATCH v2 5/6] status: do not depend on rebase reflog messages

b397ea4 (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.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 t/t7512-status-help.sh | 37 +++++++++++++++++--------------------
 wt-status.c            |  5 ++++-
 2 files changed, 21 insertions(+), 21 deletions(-)
Show changes to 2 files +21 −21

t/t7512-status-help.sh, wt-status.c

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index bf08d4e..739624e 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -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:
diff --git a/wt-status.c b/wt-status.c
index 2511270..85a00f1 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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) &&
-- 
1.8.3.1.443.g4fd77b9
Junio C Hamano· Jun 17, 2013, 17:54 UTC · re: Ramkumar Ramachandra · lore

Re: [PATCH v2 5/6] status: do not depend on rebase reflog messages

Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 16 quoted lines
> diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
> index bf08d4e..739624e 100755
> --- a/t/t7512-status-help.sh
> +++ b/t/t7512-status-help.sh
> @@ -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)

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.

Show 12 quoted lines
> diff --git a/wt-status.c b/wt-status.c
> index 2511270..85a00f1 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -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.
> +			} else if (state.detached_from) {
>  				unsigned char sha1[20];
>  				branch_name = state.detached_from;
>  				if (!get_sha1("HEAD", sha1) &&
Ramkumar Ramachandra· Jun 16, 2013, 08:45 UTC · re: Ramkumar Ramachandra · lore

[PATCH v2 6/6] 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 rebase operation.
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/checkout.c       | 11 ++++++++---
 t/t2012-checkout-last.sh |  8 ++++----
 2 files changed, 12 insertions(+), 7 deletions(-)
Show changes to 2 files +12 −7

builtin/checkout.c, t/t2012-checkout-last.sh

diff --git a/builtin/checkout.c b/builtin/checkout.c
index f5b50e5..1e2af85 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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. */
diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh
index 6ad6edf..e7ba8c5 100755
--- a/t/t2012-checkout-last.sh
+++ b/t/t2012-checkout-last.sh
@@ -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 &&
-- 
1.8.3.1.443.g4fd77b9
Junio C Hamano· Jun 17, 2013, 04:52 UTC · re: Ramkumar Ramachandra · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 7 quoted lines
> 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:

>   wt-status: remove unused field in grab_1st_switch_cbdata
This is an unrelated clean-up, and can be done before anything else.
>   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.

>   status: do not depend on rebase reflog messages
This compensates for fallouts from the next change.
>   checkout: respect GIT_REFLOG_ACTION
And this is the fix, the most important step.
>   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.

Junio C Hamano· Jun 17, 2013, 17:56 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Junio C Hamano <gitster@pobox.com> writes:
Show 26 quoted lines
> 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:
>
>>   wt-status: remove unused field in grab_1st_switch_cbdata
>
> This is an unrelated clean-up, and can be done before anything else.
>
>>   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.
>
>>   status: do not depend on rebase reflog messages
>
> This compensates for fallouts from the next change.
>
>>   checkout: respect GIT_REFLOG_ACTION
>
> And this is the fix, the most important step.
>
>>   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(-)
Show changes to 3 files +27 −7

git-rebase--interactive.sh, git-rebase.sh, t/t3404-rebase-interactive.sh

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a05a6e4..f21ff7c 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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
diff --git a/git-rebase.sh b/git-rebase.sh
index 7d55372..2344eef 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -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
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index a58406d..c175ef1 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -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 &&
Ramkumar Ramachandra· Jun 18, 2013, 09:30 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Junio C Hamano wrote:
Show 6 quoted lines
> 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.

Show 23 quoted 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_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?

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.

> 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().

>         git grep -C2 'git checkout' -- git-rebase\*.sh
Ugh.  I'll check all the codepaths thoroughly before submitting a re-roll.
Thanks.
Ramkumar Ramachandra· Jun 18, 2013, 09:50 UTC · re: Ramkumar Ramachandra · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Ramkumar Ramachandra wrote:
> Thanks for the reorder and commit message tweaks.  I'm working on the
> series you put up on `pu` now.
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.

Ramkumar Ramachandra· Jun 18, 2013, 10:36 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Junio C Hamano wrote:
Show 9 quoted lines
> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index a58406d..c175ef1 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -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.

Junio C Hamano· Jun 18, 2013, 16:15 UTC · re: Ramkumar Ramachandra · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Ramkumar Ramachandra <artagnon@gmail.com> writes:
Show 12 quoted lines
> Junio C Hamano wrote:
>> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
>> index a58406d..c175ef1 100755
>> --- a/t/t3404-rebase-interactive.sh
>> +++ b/t/t3404-rebase-interactive.sh
>> @@ -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.
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 -i
The 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).

> 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.

Ramkumar Ramachandra· Jun 18, 2013, 16:51 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 0/6] Fix checkout-dash to work with rebase

Junio C Hamano wrote:
Show 15 quoted lines
> 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
>
> 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.

← back to recent threads