3 test_description='Test reflog interaction with detached HEAD'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 cp saved_reflog .git/logs/HEAD
14 test_expect_success setup '
16 git commit --allow-empty -m initial &&
19 git commit --allow-empty -m second &&
20 cat .git/logs/HEAD >saved_reflog
23 test_expect_success baseline '
25 git rev-parse main main^ >expect &&
26 git log -g --format=%H >actual &&
27 test_cmp expect actual
30 test_expect_success 'switch to branch' '
32 git rev-parse side main main^ >expect &&
34 git log -g --format=%H >actual &&
35 test_cmp expect actual
38 test_expect_success 'detach to other' '
40 git rev-parse main side main main^ >expect &&
42 git checkout main^0 &&
43 git log -g --format=%H >actual &&
44 test_cmp expect actual
47 test_expect_success 'detach to self' '
49 git rev-parse main main main^ >expect &&
50 git checkout main^0 &&
51 git log -g --format=%H >actual &&
52 test_cmp expect actual
55 test_expect_success 'attach to self' '
57 git rev-parse main main main main^ >expect &&
58 git checkout main^0 &&
60 git log -g --format=%H >actual &&
61 test_cmp expect actual
64 test_expect_success 'attach to other' '
66 git rev-parse side main main main^ >expect &&
67 git checkout main^0 &&
69 git log -g --format=%H >actual &&
70 test_cmp expect actual