config: unify code paths to get global config paths
[git] / t / t6004-rev-list-path-optim.sh
1 #!/bin/sh
2
3 test_description='git rev-list trivial path optimization test
4
5    d/z1
6    b0                             b1
7    o------------------------*----o main
8   /                        /
9  o---------o----o----o----o side
10  a0        c0   c1   a1   c2
11  d/f0      d/f1
12  d/z0
13
14 '
15
16 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
17 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18
19 . ./test-lib.sh
20
21 test_expect_success setup '
22         echo Hello >a &&
23         mkdir d &&
24         echo World >d/f &&
25         echo World >d/z &&
26         git add a d &&
27         test_tick &&
28         git commit -m "Initial commit" &&
29         git rev-parse --verify HEAD &&
30         git tag initial
31 '
32
33 test_expect_success path-optimization '
34         test_tick &&
35         commit=$(echo "Unchanged tree" | git commit-tree "HEAD^{tree}" -p HEAD) &&
36         test $(git rev-list $commit | wc -l) = 2 &&
37         test $(git rev-list $commit -- . | wc -l) = 1
38 '
39
40 test_expect_success 'further setup' '
41         git checkout -b side &&
42         echo Irrelevant >c &&
43         echo Irrelevant >d/f &&
44         git add c d/f &&
45         test_tick &&
46         git commit -m "Side makes an irrelevant commit" &&
47         git tag side_c0 &&
48         echo "More Irrelevancy" >c &&
49         git add c &&
50         test_tick &&
51         git commit -m "Side makes another irrelevant commit" &&
52         echo Bye >a &&
53         git add a &&
54         test_tick &&
55         git commit -m "Side touches a" &&
56         git tag side_a1 &&
57         echo "Yet more Irrelevancy" >c &&
58         git add c &&
59         test_tick &&
60         git commit -m "Side makes yet another irrelevant commit" &&
61         git checkout main &&
62         echo Another >b &&
63         echo Munged >d/z &&
64         git add b d/z &&
65         test_tick &&
66         git commit -m "Main touches b" &&
67         git tag main_b0 &&
68         git merge side &&
69         echo Touched >b &&
70         git add b &&
71         test_tick &&
72         git commit -m "Main touches b again"
73 '
74
75 test_expect_success 'path optimization 2' '
76         git rev-parse side_a1 initial >expected &&
77         git rev-list HEAD -- a >actual &&
78         test_cmp expected actual
79 '
80
81 test_expect_success 'pathspec with leading path' '
82         git rev-parse main^ main_b0 side_c0 initial >expected &&
83         git rev-list HEAD -- d >actual &&
84         test_cmp expected actual
85 '
86
87 test_expect_success 'pathspec with glob (1)' '
88         git rev-parse main^ main_b0 side_c0 initial >expected &&
89         git rev-list HEAD -- "d/*" >actual &&
90         test_cmp expected actual
91 '
92
93 test_expect_success 'pathspec with glob (2)' '
94         git rev-parse side_c0 initial >expected &&
95         git rev-list HEAD -- "d/[a-m]*" >actual &&
96         test_cmp expected actual
97 '
98
99 test_done