| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test worktree ref store api' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | RWT="test-tool ref-store worktree:wt" |
| 11 | RMAIN="test-tool ref-store worktree:main" |
| 12 | |
| 13 | test_expect_success 'setup' ' |
| 14 | test_commit first && |
| 15 | git worktree add -b wt-main wt && |
| 16 | ( |
| 17 | cd wt && |
| 18 | test_commit second |
| 19 | ) |
| 20 | ' |
| 21 | |
| 22 | test_expect_success 'resolve_ref(<shared-ref>)' ' |
| 23 | SHA1=`git rev-parse main` && |
| 24 | echo "$SHA1 refs/heads/main 0x0" >expected && |
| 25 | $RWT resolve-ref refs/heads/main 0 >actual && |
| 26 | test_cmp expected actual && |
| 27 | $RMAIN resolve-ref refs/heads/main 0 >actual && |
| 28 | test_cmp expected actual |
| 29 | ' |
| 30 | |
| 31 | test_expect_success 'resolve_ref(<per-worktree-ref>)' ' |
| 32 | SHA1=`git -C wt rev-parse HEAD` && |
| 33 | echo "$SHA1 refs/heads/wt-main 0x1" >expected && |
| 34 | $RWT resolve-ref HEAD 0 >actual && |
| 35 | test_cmp expected actual && |
| 36 | |
| 37 | SHA1=`git rev-parse HEAD` && |
| 38 | echo "$SHA1 refs/heads/main 0x1" >expected && |
| 39 | $RMAIN resolve-ref HEAD 0 >actual && |
| 40 | test_cmp expected actual |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'create_symref(FOO, refs/heads/main)' ' |
| 44 | $RWT create-symref FOO refs/heads/main nothing && |
| 45 | echo refs/heads/main >expected && |
| 46 | git -C wt symbolic-ref FOO >actual && |
| 47 | test_cmp expected actual && |
| 48 | |
| 49 | $RMAIN create-symref FOO refs/heads/wt-main nothing && |
| 50 | echo refs/heads/wt-main >expected && |
| 51 | git symbolic-ref FOO >actual && |
| 52 | test_cmp expected actual |
| 53 | ' |
| 54 | |
| 55 | test_done |