Skip to content

Commit 6af9840

Browse files
committed
Merge branch 'rr/rebase-checkout-reflog'
Invocations of "git checkout" used internally by "git rebase" were counted as "checkout", and affected later "git checkout -" to the the user to an unexpected place. * rr/rebase-checkout-reflog: checkout: respect GIT_REFLOG_ACTION status: do not depend on rebase reflog messages t/t2021-checkout-last: "checkout -" should work after a rebase finishes wt-status: remove unused field in grab_1st_switch_cbdata t7512: test "detached from" as well
2 parents 3b8d276 + 3bed291 commit 6af9840

File tree

4 files changed

+72
-27
lines changed

4 files changed

+72
-27
lines changed

builtin/checkout.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
587587
struct branch_info *new)
588588
{
589589
struct strbuf msg = STRBUF_INIT;
590-
const char *old_desc;
590+
const char *old_desc, *reflog_msg;
591591
if (opts->new_branch) {
592592
if (opts->new_orphan_branch) {
593593
if (opts->new_branch_log && !log_all_ref_updates) {
@@ -620,8 +620,13 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
620620
old_desc = old->name;
621621
if (!old_desc && old->commit)
622622
old_desc = sha1_to_hex(old->commit->object.sha1);
623-
strbuf_addf(&msg, "checkout: moving from %s to %s",
624-
old_desc ? old_desc : "(invalid)", new->name);
623+
624+
reflog_msg = getenv("GIT_REFLOG_ACTION");
625+
if (!reflog_msg)
626+
strbuf_addf(&msg, "checkout: moving from %s to %s",
627+
old_desc ? old_desc : "(invalid)", new->name);
628+
else
629+
strbuf_insert(&msg, 0, reflog_msg, strlen(reflog_msg));
625630

626631
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
627632
/* Nothing to do. */

t/t2012-checkout-last.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,38 @@ test_expect_success 'master...' '
116116
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify master^)"
117117
'
118118

119+
test_expect_success '"checkout -" works after a rebase A' '
120+
git checkout master &&
121+
git checkout other &&
122+
git rebase master &&
123+
git checkout - &&
124+
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
125+
'
126+
127+
test_expect_success '"checkout -" works after a rebase A B' '
128+
git branch moodle master~1 &&
129+
git checkout master &&
130+
git checkout other &&
131+
git rebase master moodle &&
132+
git checkout - &&
133+
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
134+
'
135+
136+
test_expect_success '"checkout -" works after a rebase -i A' '
137+
git checkout master &&
138+
git checkout other &&
139+
git rebase -i master &&
140+
git checkout - &&
141+
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
142+
'
143+
144+
test_expect_success '"checkout -" works after a rebase -i A B' '
145+
git branch foodle master~1 &&
146+
git checkout master &&
147+
git checkout other &&
148+
git rebase master foodle &&
149+
git checkout - &&
150+
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master"
151+
'
152+
119153
test_done

t/t7512-status-help.sh

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
7777
ONTO=$(git rev-parse --short HEAD^^) &&
7878
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
7979
cat >expected <<-EOF &&
80-
# HEAD detached at $ONTO
80+
# rebase in progress; onto $ONTO
8181
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
8282
# (fix conflicts and then run "git rebase --continue")
8383
# (use "git rebase --skip" to skip this patch)
@@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' '
104104
echo three >main.txt &&
105105
git add main.txt &&
106106
cat >expected <<-EOF &&
107-
# HEAD detached at $ONTO
107+
# rebase in progress; onto $ONTO
108108
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
109109
# (all conflicts fixed: run "git rebase --continue")
110110
#
@@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
136136
ONTO=$(git rev-parse --short rebase_i_conflicts) &&
137137
test_must_fail git rebase -i rebase_i_conflicts &&
138138
cat >expected <<-EOF &&
139-
# HEAD detached at $ONTO
139+
# rebase in progress; onto $ONTO
140140
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
141141
# (fix conflicts and then run "git rebase --continue")
142142
# (use "git rebase --skip" to skip this patch)
@@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
162162
test_must_fail git rebase -i rebase_i_conflicts &&
163163
git add main.txt &&
164164
cat >expected <<-EOF &&
165-
# HEAD detached at $ONTO
165+
# rebase in progress; onto $ONTO
166166
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
167167
# (all conflicts fixed: run "git rebase --continue")
168168
#
@@ -188,10 +188,9 @@ test_expect_success 'status when rebasing -i in edit mode' '
188188
export FAKE_LINES &&
189189
test_when_finished "git rebase --abort" &&
190190
ONTO=$(git rev-parse --short HEAD~2) &&
191-
TGT=$(git rev-parse --short two_rebase_i) &&
192191
git rebase -i HEAD~2 &&
193192
cat >expected <<-EOF &&
194-
# HEAD detached from $TGT
193+
# rebase in progress; onto $ONTO
195194
# You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
196195
# (use "git commit --amend" to amend the current commit)
197196
# (use "git rebase --continue" once you are satisfied with your changes)
@@ -216,9 +215,8 @@ test_expect_success 'status when splitting a commit' '
216215
ONTO=$(git rev-parse --short HEAD~3) &&
217216
git rebase -i HEAD~3 &&
218217
git reset HEAD^ &&
219-
TGT=$(git rev-parse --short HEAD) &&
220218
cat >expected <<-EOF &&
221-
# HEAD detached at $TGT
219+
# rebase in progress; onto $ONTO
222220
# You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
223221
# (Once your working directory is clean, run "git rebase --continue")
224222
#
@@ -246,11 +244,10 @@ test_expect_success 'status after editing the last commit with --amend during a
246244
export FAKE_LINES &&
247245
test_when_finished "git rebase --abort" &&
248246
ONTO=$(git rev-parse --short HEAD~3) &&
249-
TGT=$(git rev-parse --short three_amend) &&
250247
git rebase -i HEAD~3 &&
251248
git commit --amend -m "foo" &&
252249
cat >expected <<-EOF &&
253-
# HEAD detached from $TGT
250+
# rebase in progress; onto $ONTO
254251
# You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
255252
# (use "git commit --amend" to amend the current commit)
256253
# (use "git rebase --continue" once you are satisfied with your changes)
@@ -280,7 +277,7 @@ test_expect_success 'status: (continue first edit) second edit' '
280277
git rebase -i HEAD~3 &&
281278
git rebase --continue &&
282279
cat >expected <<-EOF &&
283-
# HEAD detached from $ONTO
280+
# rebase in progress; onto $ONTO
284281
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
285282
# (use "git commit --amend" to amend the current commit)
286283
# (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' '
302299
git rebase --continue &&
303300
git reset HEAD^ &&
304301
cat >expected <<-EOF &&
305-
# HEAD detached from $ONTO
302+
# rebase in progress; onto $ONTO
306303
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
307304
# (Once your working directory is clean, run "git rebase --continue")
308305
#
@@ -329,7 +326,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
329326
git rebase --continue &&
330327
git commit --amend -m "foo" &&
331328
cat >expected <<-EOF &&
332-
# HEAD detached from $ONTO
329+
# rebase in progress; onto $ONTO
333330
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
334331
# (use "git commit --amend" to amend the current commit)
335332
# (use "git rebase --continue" once you are satisfied with your changes)
@@ -351,7 +348,7 @@ test_expect_success 'status: (amend first edit) second edit' '
351348
git commit --amend -m "a" &&
352349
git rebase --continue &&
353350
cat >expected <<-EOF &&
354-
# HEAD detached from $ONTO
351+
# rebase in progress; onto $ONTO
355352
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
356353
# (use "git commit --amend" to amend the current commit)
357354
# (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' '
374371
git rebase --continue &&
375372
git reset HEAD^ &&
376373
cat >expected <<-EOF &&
377-
# HEAD detached from $ONTO
374+
# rebase in progress; onto $ONTO
378375
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
379376
# (Once your working directory is clean, run "git rebase --continue")
380377
#
@@ -402,7 +399,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
402399
git rebase --continue &&
403400
git commit --amend -m "d" &&
404401
cat >expected <<-EOF &&
405-
# HEAD detached from $ONTO
402+
# rebase in progress; onto $ONTO
406403
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
407404
# (use "git commit --amend" to amend the current commit)
408405
# (use "git rebase --continue" once you are satisfied with your changes)
@@ -426,7 +423,7 @@ test_expect_success 'status: (split first edit) second edit' '
426423
git commit -m "e" &&
427424
git rebase --continue &&
428425
cat >expected <<-EOF &&
429-
# HEAD detached from $ONTO
426+
# rebase in progress; onto $ONTO
430427
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
431428
# (use "git commit --amend" to amend the current commit)
432429
# (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' '
451448
git rebase --continue &&
452449
git reset HEAD^ &&
453450
cat >expected <<-EOF &&
454-
# HEAD detached from $ONTO
451+
# rebase in progress; onto $ONTO
455452
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
456453
# (Once your working directory is clean, run "git rebase --continue")
457454
#
@@ -481,7 +478,7 @@ test_expect_success 'status: (split first edit) second edit and amend' '
481478
git rebase --continue &&
482479
git commit --amend -m "h" &&
483480
cat >expected <<-EOF &&
484-
# HEAD detached from $ONTO
481+
# rebase in progress; onto $ONTO
485482
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
486483
# (use "git commit --amend" to amend the current commit)
487484
# (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' '
601598
ONTO=$(git rev-parse --short HEAD^^) &&
602599
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
603600
cat >expected <<-EOF &&
604-
# HEAD detached at $ONTO
601+
# rebase in progress; onto $ONTO
605602
# You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
606603
#
607604
# Unmerged paths:
@@ -669,14 +666,22 @@ test_expect_success 'status when cherry-picking after resolving conflicts' '
669666
test_i18ncmp expected actual
670667
'
671668

672-
test_expect_success 'status showing detached from a tag' '
669+
test_expect_success 'status showing detached at and from a tag' '
673670
test_commit atag tagging &&
674671
git checkout atag &&
675672
cat >expected <<-\EOF
676673
# HEAD detached at atag
677674
nothing to commit (use -u to show untracked files)
678675
EOF
679676
git status --untracked-files=no >actual &&
677+
test_i18ncmp expected actual &&
678+
679+
git reset --hard HEAD^ &&
680+
cat >expected <<-\EOF
681+
# HEAD detached from atag
682+
nothing to commit (use -u to show untracked files)
683+
EOF
684+
git status --untracked-files=no >actual &&
680685
test_i18ncmp expected actual
681686
'
682687

wt-status.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ static char *read_and_strip_branch(const char *path)
10371037
}
10381038

10391039
struct grab_1st_switch_cbdata {
1040-
int found;
10411040
struct strbuf buf;
10421041
unsigned char nsha1[20];
10431042
};
@@ -1061,7 +1060,6 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
10611060
for (end = target; *end && *end != '\n'; end++)
10621061
;
10631062
strbuf_add(&cb->buf, target, end - target);
1064-
cb->found = 1;
10651063
return 1;
10661064
}
10671065

@@ -1178,7 +1176,10 @@ void wt_status_print(struct wt_status *s)
11781176
branch_name += 11;
11791177
else if (!strcmp(branch_name, "HEAD")) {
11801178
branch_status_color = color(WT_STATUS_NOBRANCH, s);
1181-
if (state.detached_from) {
1179+
if (state.rebase_in_progress || state.rebase_interactive_in_progress) {
1180+
on_what = _("rebase in progress; onto ");
1181+
branch_name = state.onto;
1182+
} else if (state.detached_from) {
11821183
unsigned char sha1[20];
11831184
branch_name = state.detached_from;
11841185
if (!get_sha1("HEAD", sha1) &&

0 commit comments

Comments
 (0)