reflog test: test interaction with detached HEAD

A proposed patch produced broken HEAD reflog entries when checking out anything other than a branch. The testsuite still passed, so it took a few days for the bug to be noticed. Add tests checking the content of the reflog after detaching and reattaching HEAD so we don't have to rely on manual testing to catch such problems in the future. [jn: using 'log -g --format=%H' instead of parsing --oneline output, resetting state in each test so they can be safely reordered or skipped] Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 13, 2014 at 10:52 UTC 014e7db3f5563a61cefbe1f6f5747931c799a37e
1 file changed +70
t/t1413-reflog-detach.sh new
+70
@@ -0,0 +1,70 @@
1 +#!/bin/sh
2 +
3 +test_description='Test reflog interaction with detached HEAD'
4 +. ./test-lib.sh
5 +
6 +reset_state () {
7 + git checkout master &&
8 + cp saved_reflog .git/logs/HEAD
9 +}
10 +
11 +test_expect_success setup '
12 + test_tick &&
13 + git commit --allow-empty -m initial &&
14 + git branch side &&
15 + test_tick &&
16 + git commit --allow-empty -m second &&
17 + cat .git/logs/HEAD >saved_reflog
18 +'
19 +
20 +test_expect_success baseline '
21 + reset_state &&
22 + git rev-parse master master^ >expect &&
23 + git log -g --format=%H >actual &&
24 + test_cmp expect actual
25 +'
26 +
27 +test_expect_success 'switch to branch' '
28 + reset_state &&
29 + git rev-parse side master master^ >expect &&
30 + git checkout side &&
31 + git log -g --format=%H >actual &&
32 + test_cmp expect actual
33 +'
34 +
35 +test_expect_success 'detach to other' '
36 + reset_state &&
37 + git rev-parse master side master master^ >expect &&
38 + git checkout side &&
39 + git checkout master^0 &&
40 + git log -g --format=%H >actual &&
41 + test_cmp expect actual
42 +'
43 +
44 +test_expect_success 'detach to self' '
45 + reset_state &&
46 + git rev-parse master master master^ >expect &&
47 + git checkout master^0 &&
48 + git log -g --format=%H >actual &&
49 + test_cmp expect actual
50 +'
51 +
52 +test_expect_success 'attach to self' '
53 + reset_state &&
54 + git rev-parse master master master master^ >expect &&
55 + git checkout master^0 &&
56 + git checkout master &&
57 + git log -g --format=%H >actual &&
58 + test_cmp expect actual
59 +'
60 +
61 +test_expect_success 'attach to other' '
62 + reset_state &&
63 + git rev-parse side master master master^ >expect &&
64 + git checkout master^0 &&
65 + git checkout side &&
66 + git log -g --format=%H >actual &&
67 + test_cmp expect actual
68 +'
69 +
70 +test_done