status: do not depend on rebase reflog messages

b397ea4 (status: show more info than "currently not on any branch", 2013-03-13) attempted to make the output of 'git status' richer in the case of a detached HEAD. Before this patch, with a detached HEAD, we saw: $ git status # Not currently on any branch. But after the patch, we see: $ 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. so that the user can see where the HEAD was first detached. In case of a rebase [-i] operation in progress, this message depends on the implementation of rebase writing "checkout: " messages to the reflog, but that is an implementation detail of "rebase". To remove this dependency so that rebase can be updated to write better reflog messages, replace this "HEAD detached from" message with: # rebase in progress; onto $ONTO Changes to the commit object name in the expected output for some of the tests shows that what the test expected "status" to show during "rebase -i" was not consistent with the output during a vanilla "rebase", which showed on top of what commit the series is being replayed. Now we consistently expect something meaningful to the end user. Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramkumar Ramachandra committed Jun 16, 2013 at 14:15 UTC ec5063106449aa8c6623abbdcca862dd1516c920
2 files changed +21 -21
t/t7512-status-help.sh
+17 -20
@@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
77 ONTO=$(git rev-parse --short HEAD^^) &&
78 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
79 cat >expected <<-EOF &&
80 - # HEAD detached at $ONTO
80 + # rebase in progress; onto $ONTO
81 # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
82 # (fix conflicts and then run "git rebase --continue")
83 # (use "git rebase --skip" to skip this patch)
@@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' '
104 echo three >main.txt &&
105 git add main.txt &&
106 cat >expected <<-EOF &&
107 - # HEAD detached at $ONTO
107 + # rebase in progress; onto $ONTO
108 # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
109 # (all conflicts fixed: run "git rebase --continue")
110 #
@@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
136 ONTO=$(git rev-parse --short rebase_i_conflicts) &&
137 test_must_fail git rebase -i rebase_i_conflicts &&
138 cat >expected <<-EOF &&
139 - # HEAD detached at $ONTO
139 + # rebase in progress; onto $ONTO
140 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
141 # (fix conflicts and then run "git rebase --continue")
142 # (use "git rebase --skip" to skip this patch)
@@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
162 test_must_fail git rebase -i rebase_i_conflicts &&
163 git add main.txt &&
164 cat >expected <<-EOF &&
165 - # HEAD detached at $ONTO
165 + # rebase in progress; onto $ONTO
166 # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
167 # (all conflicts fixed: run "git rebase --continue")
168 #
@@ -188,10 +188,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
188 export FAKE_LINES &&
189 test_when_finished "git rebase --abort" &&
190 ONTO=$(git rev-parse --short HEAD~2) &&
191 - TGT=$(git rev-parse --short two_rebase_i) &&
191 git rebase -i HEAD~2 &&
192 cat >expected <<-EOF &&
194 - # HEAD detached from $TGT
193 + # rebase in progress; onto $ONTO
194 # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
195 # (use "git commit --amend" to amend the current commit)
196 # (use "git rebase --continue" once you are satisfied with your changes)
@@ -216,9 +215,8 @@ test_expect_success 'status when splitting a commit' '
215 ONTO=$(git rev-parse --short HEAD~3) &&
216 git rebase -i HEAD~3 &&
217 git reset HEAD^ &&
219 - TGT=$(git rev-parse --short HEAD) &&
218 cat >expected <<-EOF &&
221 - # HEAD detached at $TGT
219 + # rebase in progress; onto $ONTO
220 # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
221 # (Once your working directory is clean, run "git rebase --continue")
222 #
@@ -246,11 +244,10 @@ test_expect_success 'status after editing the last commit with --amend during a
244 export FAKE_LINES &&
245 test_when_finished "git rebase --abort" &&
246 ONTO=$(git rev-parse --short HEAD~3) &&
249 - TGT=$(git rev-parse --short three_amend) &&
247 git rebase -i HEAD~3 &&
248 git commit --amend -m "foo" &&
249 cat >expected <<-EOF &&
253 - # HEAD detached from $TGT
250 + # rebase in progress; onto $ONTO
251 # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
252 # (use "git commit --amend" to amend the current commit)
253 # (use "git rebase --continue" once you are satisfied with your changes)
@@ -280,7 +277,7 @@ test_expect_success 'status: (continue first edit) second edit' '
277 git rebase -i HEAD~3 &&
278 git rebase --continue &&
279 cat >expected <<-EOF &&
283 - # HEAD detached from $ONTO
280 + # rebase in progress; onto $ONTO
281 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
282 # (use "git commit --amend" to amend the current commit)
283 # (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' '
299 git rebase --continue &&
300 git reset HEAD^ &&
301 cat >expected <<-EOF &&
305 - # HEAD detached from $ONTO
302 + # rebase in progress; onto $ONTO
303 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
304 # (Once your working directory is clean, run "git rebase --continue")
305 #
@@ -329,7 +326,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
326 git rebase --continue &&
327 git commit --amend -m "foo" &&
328 cat >expected <<-EOF &&
332 - # HEAD detached from $ONTO
329 + # rebase in progress; onto $ONTO
330 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
331 # (use "git commit --amend" to amend the current commit)
332 # (use "git rebase --continue" once you are satisfied with your changes)
@@ -351,7 +348,7 @@ test_expect_success 'status: (amend first edit) second edit' '
348 git commit --amend -m "a" &&
349 git rebase --continue &&
350 cat >expected <<-EOF &&
354 - # HEAD detached from $ONTO
351 + # rebase in progress; onto $ONTO
352 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
353 # (use "git commit --amend" to amend the current commit)
354 # (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' '
371 git rebase --continue &&
372 git reset HEAD^ &&
373 cat >expected <<-EOF &&
377 - # HEAD detached from $ONTO
374 + # rebase in progress; onto $ONTO
375 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
376 # (Once your working directory is clean, run "git rebase --continue")
377 #
@@ -402,7 +399,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
399 git rebase --continue &&
400 git commit --amend -m "d" &&
401 cat >expected <<-EOF &&
405 - # HEAD detached from $ONTO
402 + # rebase in progress; onto $ONTO
403 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
404 # (use "git commit --amend" to amend the current commit)
405 # (use "git rebase --continue" once you are satisfied with your changes)
@@ -426,7 +423,7 @@ test_expect_success 'status: (split first edit) second edit' '
423 git commit -m "e" &&
424 git rebase --continue &&
425 cat >expected <<-EOF &&
429 - # HEAD detached from $ONTO
426 + # rebase in progress; onto $ONTO
427 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
428 # (use "git commit --amend" to amend the current commit)
429 # (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' '
448 git rebase --continue &&
449 git reset HEAD^ &&
450 cat >expected <<-EOF &&
454 - # HEAD detached from $ONTO
451 + # rebase in progress; onto $ONTO
452 # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
453 # (Once your working directory is clean, run "git rebase --continue")
454 #
@@ -481,7 +478,7 @@ test_expect_success 'status: (split first edit) second edit and amend' '
478 git rebase --continue &&
479 git commit --amend -m "h" &&
480 cat >expected <<-EOF &&
484 - # HEAD detached from $ONTO
481 + # rebase in progress; onto $ONTO
482 # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
483 # (use "git commit --amend" to amend the current commit)
484 # (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' '
598 ONTO=$(git rev-parse --short HEAD^^) &&
599 test_must_fail git rebase HEAD^ --onto HEAD^^ &&
600 cat >expected <<-EOF &&
604 - # HEAD detached at $ONTO
601 + # rebase in progress; onto $ONTO
602 # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
603 #
604 # Unmerged paths:
wt-status.c
+4 -1
@@ -1174,7 +1174,10 @@ void wt_status_print(struct wt_status *s)
1174 branch_name += 11;
1175 else if (!strcmp(branch_name, "HEAD")) {
1176 branch_status_color = color(WT_STATUS_NOBRANCH, s);
1177 - if (state.detached_from) {
1177 + if (state.rebase_in_progress || state.rebase_interactive_in_progress) {
1178 + on_what = _("rebase in progress; onto ");
1179 + branch_name = state.onto;
1180 + } else if (state.detached_from) {
1181 unsigned char sha1[20];
1182 branch_name = state.detached_from;
1183 if (!get_sha1("HEAD", sha1) &&