1#!/bin/sh
2
3test_description='Test reflog interaction with detached HEAD'
4. ./test-lib.sh
5
6reset_state () {
7 git checkout master &&
8 cp saved_reflog .git/logs/HEAD
9}
10
11test_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
20test_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
27test_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
35test_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
44test_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
52test_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
61test_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
70test_done