Merge branch 'ds/add-rm-with-sparse-index'
[git/debian.git] / t / t1513-rev-parse-prefix.sh
blob5f437be8c9e8c932f5d355e3f8636e5cbcd69791
1 #!/bin/sh
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-lib.sh
10 test_expect_success 'setup' '
11 mkdir -p sub1/sub2 &&
12 echo top >top &&
13 echo file1 >sub1/file1 &&
14 echo file2 >sub1/sub2/file2 &&
15 git add top sub1/file1 sub1/sub2/file2 &&
16 git commit -m commit
19 test_expect_success 'empty prefix -- file' '
20 git rev-parse --prefix "" -- top sub1/file1 >actual &&
21 cat <<-\EOF >expected &&
23 top
24 sub1/file1
25 EOF
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 &&
33 sub1/file1
34 sub1/sub2/file2
35 EOF
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 &&
43 sub1/../top
44 sub1/sub2/file2
45 EOF
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 &&
76 sub1/file1
77 EOF
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 &&
84 $(git rev-parse main)
85 sub1/file1
86 EOF
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 &&
94 sub1/sub2/file2
95 EOF
96 test_cmp expected actual
99 test_done