3 test_description
='Tests for rev-parse --prefix'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success
'setup' '
13 echo file1 >sub1/file1 &&
14 echo file2 >sub1/sub2/file2 &&
15 git add top sub1/file1 sub1/sub2/file2 &&
19 test_expect_success
'empty prefix -- file' '
20 git rev-parse --prefix "" -- top sub1/file1 >actual &&
21 cat <<-\EOF >expected &&
26 test_cmp expected actual
29 test_expect_success
'valid prefix -- file' '
30 git rev-parse --prefix sub1/ -- file1 sub2/file2 >actual &&
31 cat <<-\EOF >expected &&
36 test_cmp expected actual
39 test_expect_success
'valid prefix -- ../file' '
40 git rev-parse --prefix sub1/ -- ../top sub2/file2 >actual &&
41 cat <<-\EOF >expected &&
46 test_cmp expected actual
49 test_expect_success
'empty prefix HEAD:./path' '
50 git rev-parse --prefix "" HEAD:./top >actual &&
51 git rev-parse HEAD:top >expected &&
52 test_cmp expected actual
55 test_expect_success
'valid prefix HEAD:./path' '
56 git rev-parse --prefix sub1/ HEAD:./file1 >actual &&
57 git rev-parse HEAD:sub1/file1 >expected &&
58 test_cmp expected actual
61 test_expect_success
'valid prefix HEAD:../path' '
62 git rev-parse --prefix sub1/ HEAD:../top >actual &&
63 git rev-parse HEAD:top >expected &&
64 test_cmp expected actual
67 test_expect_success
'prefix ignored with HEAD:top' '
68 git rev-parse --prefix sub1/ HEAD:top >actual &&
69 git rev-parse HEAD:top >expected &&
70 test_cmp expected actual
73 test_expect_success
'disambiguate path with valid prefix' '
74 git rev-parse --prefix sub1/ file1 >actual &&
75 cat <<-\EOF >expected &&
78 test_cmp expected actual
81 test_expect_success
'file and refs with prefix' '
82 git rev-parse --prefix sub1/ main file1 >actual &&
83 cat <<-EOF >expected &&
87 test_cmp expected actual
90 test_expect_success
'two-levels deep' '
91 git rev-parse --prefix sub1/sub2/ -- file2 >actual &&
92 cat <<-\EOF >expected &&
96 test_cmp expected actual