repack: fix generating multi-pack-index with only non-local packs
[alt-git.git] / t / t1513-rev-parse-prefix.sh
blobba43387bf167b598de91bea497251d270214f545
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success 'setup' '
12 mkdir -p sub1/sub2 &&
13 echo top >top &&
14 echo file1 >sub1/file1 &&
15 echo file2 >sub1/sub2/file2 &&
16 git add top sub1/file1 sub1/sub2/file2 &&
17 git commit -m commit
20 test_expect_success 'empty prefix -- file' '
21 git rev-parse --prefix "" -- top sub1/file1 >actual &&
22 cat <<-\EOF >expected &&
24 top
25 sub1/file1
26 EOF
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 &&
34 sub1/file1
35 sub1/sub2/file2
36 EOF
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 &&
44 sub1/../top
45 sub1/sub2/file2
46 EOF
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 &&
77 sub1/file1
78 EOF
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 &&
85 $(git rev-parse main)
86 sub1/file1
87 EOF
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 &&
95 sub1/sub2/file2
96 EOF
97 test_cmp expected actual
100 test_done