branch: name detached HEAD analogous to status
"git status" carefully names a detached HEAD "at" resp. "from" a rev or ref depending on whether the detached HEAD has moved since. "git branch" always uses "from", which can be confusing, because a status-aware user would interpret this as moved detached HEAD. Make "git branch" use the same logic and wording. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Mar 6, 2015 at 16:04 UTC
4b06318664638d306cad920fd86eb63b69739310
2 files changed
+48
-4
builtin/branch.c
+10
-3
@@ -589,9 +589,16 @@ static char *get_head_description(void)
589
else if (state.bisect_in_progress)
590
strbuf_addf(&desc, _("(no branch, bisect started on %s)"),
591
state.branch);
592
- else if (state.detached_from)
593
- strbuf_addf(&desc, _("(detached from %s)"),
594
- state.detached_from);
592
+ else if (state.detached_from) {
593
+ /* TRANSLATORS: make sure these match _("HEAD detached at ")
594
+ and _("HEAD detached from ") in wt-status.c */
595
+ if (state.detached_at)
596
+ strbuf_addf(&desc, _("(HEAD detached at %s)"),
597
+ state.detached_from);
598
+ else
599
+ strbuf_addf(&desc, _("(HEAD detached from %s)"),
600
+ state.detached_from);
601
+ }
602
else
603
strbuf_addstr(&desc, _("(no branch)"));
604
free(state.branch);
t/t3203-branch-output.sh
+38
-1
@@ -96,7 +96,7 @@ test_expect_success 'git branch -v pattern does not show branch summaries' '
96
97
test_expect_success 'git branch shows detached HEAD properly' '
98
cat >expect <<EOF &&
99
-* (detached from $(git rev-parse --short HEAD^0))
99
+* (HEAD detached at $(git rev-parse --short HEAD^0))
100
branch-one
101
branch-two
102
master
@@ -106,4 +106,41 @@ EOF
106
test_i18ncmp expect actual
107
'
108
109
+test_expect_success 'git branch shows detached HEAD properly after moving' '
110
+ cat >expect <<EOF &&
111
+* (HEAD detached from $(git rev-parse --short HEAD))
112
+ branch-one
113
+ branch-two
114
+ master
115
+EOF
116
+ git reset --hard HEAD^1 &&
117
+ git branch >actual &&
118
+ test_i18ncmp expect actual
119
+'
120
+
121
+test_expect_success 'git branch shows detached HEAD properly from tag' '
122
+ cat >expect <<EOF &&
123
+* (HEAD detached at fromtag)
124
+ branch-one
125
+ branch-two
126
+ master
127
+EOF
128
+ git tag fromtag master &&
129
+ git checkout fromtag &&
130
+ git branch >actual &&
131
+ test_i18ncmp expect actual
132
+'
133
+
134
+test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
135
+ cat >expect <<EOF &&
136
+* (HEAD detached from fromtag)
137
+ branch-one
138
+ branch-two
139
+ master
140
+EOF
141
+ git reset --hard HEAD^1 &&
142
+ git branch >actual &&
143
+ test_i18ncmp expect actual
144
+'
145
+
146
test_done