Merge branch 'jc/push-default-explicit'
[git/debian.git] / t / t1513-rev-parse-prefix.sh
blob87ec3ae714881e8e77b5a8144965618f7dff7b1b
1 #!/bin/sh
3 test_description='Tests for rev-parse --prefix'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 mkdir -p sub1/sub2 &&
9 echo top >top &&
10 echo file1 >sub1/file1 &&
11 echo file2 >sub1/sub2/file2 &&
12 git add top sub1/file1 sub1/sub2/file2 &&
13 git commit -m commit
16 test_expect_success 'empty prefix -- file' '
17 git rev-parse --prefix "" -- top sub1/file1 >actual &&
18 cat <<-\EOF >expected &&
20 top
21 sub1/file1
22 EOF
23 test_cmp expected actual
26 test_expect_success 'valid prefix -- file' '
27 git rev-parse --prefix sub1/ -- file1 sub2/file2 >actual &&
28 cat <<-\EOF >expected &&
30 sub1/file1
31 sub1/sub2/file2
32 EOF
33 test_cmp expected actual
36 test_expect_success 'valid prefix -- ../file' '
37 git rev-parse --prefix sub1/ -- ../top sub2/file2 >actual &&
38 cat <<-\EOF >expected &&
40 sub1/../top
41 sub1/sub2/file2
42 EOF
43 test_cmp expected actual
46 test_expect_success 'empty prefix HEAD:./path' '
47 git rev-parse --prefix "" HEAD:./top >actual &&
48 git rev-parse HEAD:top >expected &&
49 test_cmp expected actual
52 test_expect_success 'valid prefix HEAD:./path' '
53 git rev-parse --prefix sub1/ HEAD:./file1 >actual &&
54 git rev-parse HEAD:sub1/file1 >expected &&
55 test_cmp expected actual
58 test_expect_success 'valid prefix HEAD:../path' '
59 git rev-parse --prefix sub1/ HEAD:../top >actual &&
60 git rev-parse HEAD:top >expected &&
61 test_cmp expected actual
64 test_expect_success 'prefix ignored with HEAD:top' '
65 git rev-parse --prefix sub1/ HEAD:top >actual &&
66 git rev-parse HEAD:top >expected &&
67 test_cmp expected actual
70 test_expect_success 'disambiguate path with valid prefix' '
71 git rev-parse --prefix sub1/ file1 >actual &&
72 cat <<-\EOF >expected &&
73 sub1/file1
74 EOF
75 test_cmp expected actual
78 test_expect_success 'file and refs with prefix' '
79 git rev-parse --prefix sub1/ master file1 >actual &&
80 cat <<-EOF >expected &&
81 $(git rev-parse master)
82 sub1/file1
83 EOF
84 test_cmp expected actual
87 test_expect_success 'two-levels deep' '
88 git rev-parse --prefix sub1/sub2/ -- file2 >actual &&
89 cat <<-\EOF >expected &&
91 sub1/sub2/file2
92 EOF
93 test_cmp expected actual
96 test_done