| 1 | #!/bin/sh |
| 2 | |
| 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 |
| 6 | |
| 7 | . ./test-lib.sh |
| 8 | |
| 9 | reset_state () { |
| 10 | rm -rf .git && "$TAR" xf .git-saved.tar |
| 11 | } |
| 12 | |
| 13 | test_expect_success setup ' |
| 14 | test_tick && |
| 15 | git commit --allow-empty -m initial && |
| 16 | git branch side && |
| 17 | test_tick && |
| 18 | git commit --allow-empty -m second && |
| 19 | "$TAR" cf .git-saved.tar .git |
| 20 | ' |
| 21 | |
| 22 | test_expect_success baseline ' |
| 23 | reset_state && |
| 24 | git rev-parse main main^ >expect && |
| 25 | git log -g --format=%H >actual && |
| 26 | test_cmp expect actual |
| 27 | ' |
| 28 | |
| 29 | test_expect_success 'switch to branch' ' |
| 30 | reset_state && |
| 31 | git rev-parse side main main^ >expect && |
| 32 | git checkout side && |
| 33 | git log -g --format=%H >actual && |
| 34 | test_cmp expect actual |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'detach to other' ' |
| 38 | reset_state && |
| 39 | git rev-parse main side main main^ >expect && |
| 40 | git checkout side && |
| 41 | git checkout main^0 && |
| 42 | git log -g --format=%H >actual && |
| 43 | test_cmp expect actual |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'detach to self' ' |
| 47 | reset_state && |
| 48 | git rev-parse main main main^ >expect && |
| 49 | git checkout main^0 && |
| 50 | git log -g --format=%H >actual && |
| 51 | test_cmp expect actual |
| 52 | ' |
| 53 | |
| 54 | test_expect_success 'attach to self' ' |
| 55 | reset_state && |
| 56 | git rev-parse main main main main^ >expect && |
| 57 | git checkout main^0 && |
| 58 | git checkout main && |
| 59 | git log -g --format=%H >actual && |
| 60 | test_cmp expect actual |
| 61 | ' |
| 62 | |
| 63 | test_expect_success 'attach to other' ' |
| 64 | reset_state && |
| 65 | git rev-parse side main main main^ >expect && |
| 66 | git checkout main^0 && |
| 67 | git checkout side && |
| 68 | git log -g --format=%H >actual && |
| 69 | test_cmp expect actual |
| 70 | ' |
| 71 | |
| 72 | test_done |