@@ -186,4 +186,127 @@ test_expect_success 'no advice given for explicit detached head state' '
186186 test_cmp expect.no-advice actual
187187'
188188
189+ # Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (new format)
190+ test_expect_success ' describe_detached_head prints no SHA-1 ellipsis when not asked to' "
191+
192+ # The first detach operation is more chatty than the following ones.
193+ cat >1st_detach <<-'EOF' &&
194+ Note: checking out 'HEAD^'.
195+
196+ You are in 'detached HEAD' state. You can look around, make experimental
197+ changes and commit them, and you can discard any commits you make in this
198+ state without impacting any branches by performing another checkout.
199+
200+ If you want to create a new branch to retain commits you create, you may
201+ do so (now or later) by using -b with the checkout command again. Example:
202+
203+ git checkout -b <new-branch-name>
204+
205+ HEAD is now at 7c7cd714e262 three
206+ EOF
207+
208+ # The remaining ones just show info about previous and current HEADs.
209+ cat >2nd_detach <<-'EOF' &&
210+ Previous HEAD position was 7c7cd714e262 three
211+ HEAD is now at 139b20d8e6c5 two
212+ EOF
213+
214+ cat >3rd_detach <<-'EOF' &&
215+ Previous HEAD position was 139b20d8e6c5 two
216+ HEAD is now at d79ce1670bdc one
217+ EOF
218+
219+ reset &&
220+ check_not_detached &&
221+
222+ # Various ways of *not* asking for ellipses
223+
224+ sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
225+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
226+ check_detached &&
227+ test_i18ncmp 1st_detach actual &&
228+
229+ GIT_PRINT_SHA1_ELLIPSIS=" no" git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
230+ check_detached &&
231+ test_i18ncmp 2nd_detach actual &&
232+
233+ GIT_PRINT_SHA1_ELLIPSIS= git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
234+ check_detached &&
235+ test_i18ncmp 3rd_detach actual &&
236+
237+ sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
238+
239+ # We only have four commits, but we can re-use them
240+ reset &&
241+ check_not_detached &&
242+
243+ # Make no mention of the env var at all
244+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
245+ check_detached &&
246+ test_i18ncmp 1st_detach actual &&
247+
248+ GIT_PRINT_SHA1_ELLIPSIS='nope' &&
249+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
250+ check_detached &&
251+ test_i18ncmp 2nd_detach actual &&
252+
253+ GIT_PRINT_SHA1_ELLIPSIS=nein &&
254+ git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
255+ check_detached &&
256+ test_i18ncmp 3rd_detach actual &&
257+
258+ true
259+ "
260+
261+ # Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (old format)
262+ test_expect_success ' describe_detached_head does print SHA-1 ellipsis when asked to' "
263+
264+ # The first detach operation is more chatty than the following ones.
265+ cat >1st_detach <<-'EOF' &&
266+ Note: checking out 'HEAD^'.
267+
268+ You are in 'detached HEAD' state. You can look around, make experimental
269+ changes and commit them, and you can discard any commits you make in this
270+ state without impacting any branches by performing another checkout.
271+
272+ If you want to create a new branch to retain commits you create, you may
273+ do so (now or later) by using -b with the checkout command again. Example:
274+
275+ git checkout -b <new-branch-name>
276+
277+ HEAD is now at 7c7cd714e262... three
278+ EOF
279+
280+ # The remaining ones just show info about previous and current HEADs.
281+ cat >2nd_detach <<-'EOF' &&
282+ Previous HEAD position was 7c7cd714e262... three
283+ HEAD is now at 139b20d8e6c5... two
284+ EOF
285+
286+ cat >3rd_detach <<-'EOF' &&
287+ Previous HEAD position was 139b20d8e6c5... two
288+ HEAD is now at d79ce1670bdc... one
289+ EOF
290+
291+ reset &&
292+ check_not_detached &&
293+
294+ # Various ways of asking for ellipses...
295+ # The user can just use any kind of quoting (including none).
296+
297+ GIT_PRINT_SHA1_ELLIPSIS=yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
298+ check_detached &&
299+ test_i18ncmp 1st_detach actual &&
300+
301+ GIT_PRINT_SHA1_ELLIPSIS=Yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
302+ check_detached &&
303+ test_i18ncmp 2nd_detach actual &&
304+
305+ GIT_PRINT_SHA1_ELLIPSIS=YES git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
306+ check_detached &&
307+ test_i18ncmp 3rd_detach actual &&
308+
309+ true
310+ "
311+
189312test_done
0 commit comments