3 test_description
='Tests for rev-parse --prefix'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
14 echo file1 >sub1/file1 &&
15 echo file2 >sub1/sub2/file2 &&
16 git add top sub1/file1 sub1/sub2/file2 &&
20 test_expect_success
'empty prefix -- file' '
21 git rev-parse --prefix "" -- top sub1/file1 >actual &&
22 cat <<-\EOF >expected &&
27 test_cmp expected actual
30 test_expect_success
'valid prefix -- file' '
31 git rev-parse --prefix sub1/ -- file1 sub2/file2 >actual &&
32 cat <<-\EOF >expected &&
37 test_cmp expected actual
40 test_expect_success
'valid prefix -- ../file' '
41 git rev-parse --prefix sub1/ -- ../top sub2/file2 >actual &&
42 cat <<-\EOF >expected &&
47 test_cmp expected actual
50 test_expect_success
'empty prefix HEAD:./path' '
51 git rev-parse --prefix "" HEAD:./top >actual &&
52 git rev-parse HEAD:top >expected &&
53 test_cmp expected actual
56 test_expect_success
'valid prefix HEAD:./path' '
57 git rev-parse --prefix sub1/ HEAD:./file1 >actual &&
58 git rev-parse HEAD:sub1/file1 >expected &&
59 test_cmp expected actual
62 test_expect_success
'valid prefix HEAD:../path' '
63 git rev-parse --prefix sub1/ HEAD:../top >actual &&
64 git rev-parse HEAD:top >expected &&
65 test_cmp expected actual
68 test_expect_success
'prefix ignored with HEAD:top' '
69 git rev-parse --prefix sub1/ HEAD:top >actual &&
70 git rev-parse HEAD:top >expected &&
71 test_cmp expected actual
74 test_expect_success
'disambiguate path with valid prefix' '
75 git rev-parse --prefix sub1/ file1 >actual &&
76 cat <<-\EOF >expected &&
79 test_cmp expected actual
82 test_expect_success
'file and refs with prefix' '
83 git rev-parse --prefix sub1/ main file1 >actual &&
84 cat <<-EOF >expected &&
88 test_cmp expected actual
91 test_expect_success
'two-levels deep' '
92 git rev-parse --prefix sub1/sub2/ -- file2 >actual &&
93 cat <<-\EOF >expected &&
97 test_cmp expected actual