blob: 3e8c42ee0b93cff3be39f42a411e9b32d16c5d5d [file] [log] [blame]
Alex Riesen57c7d9a2006-07-25 01:23:03 +02001#!/bin/sh
2
Junio C Hamanof577b922011-01-31 12:09:53 -08003test_description='git rev-list trivial path optimization test
4
5 d/z1
6 b0 b1
7 o------------------------*----o master
8 / /
9 o---------o----o----o----o side
10 a0 c0 c1 a1 c2
11 d/f0 d/f1
12 d/z0
13
14'
Alex Riesen57c7d9a2006-07-25 01:23:03 +020015
16. ./test-lib.sh
17
18test_expect_success setup '
Junio C Hamanof577b922011-01-31 12:09:53 -080019 echo Hello >a &&
20 mkdir d &&
21 echo World >d/f &&
22 echo World >d/z &&
23 git add a d &&
24 test_tick &&
25 git commit -m "Initial commit" &&
26 git rev-parse --verify HEAD &&
27 git tag initial
Alex Riesen57c7d9a2006-07-25 01:23:03 +020028'
29
30test_expect_success path-optimization '
Junio C Hamanof577b922011-01-31 12:09:53 -080031 test_tick &&
32 commit=$(echo "Unchanged tree" | git commit-tree "HEAD^{tree}" -p HEAD) &&
33 test $(git rev-list $commit | wc -l) = 2 &&
34 test $(git rev-list $commit -- . | wc -l) = 1
Alex Riesen57c7d9a2006-07-25 01:23:03 +020035'
36
Junio C Hamanobab36bf2007-03-22 23:22:07 -070037test_expect_success 'further setup' '
38 git checkout -b side &&
39 echo Irrelevant >c &&
Junio C Hamanof577b922011-01-31 12:09:53 -080040 echo Irrelevant >d/f &&
41 git add c d/f &&
42 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070043 git commit -m "Side makes an irrelevant commit" &&
Junio C Hamanof577b922011-01-31 12:09:53 -080044 git tag side_c0 &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070045 echo "More Irrelevancy" >c &&
46 git add c &&
Junio C Hamanof577b922011-01-31 12:09:53 -080047 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070048 git commit -m "Side makes another irrelevant commit" &&
49 echo Bye >a &&
50 git add a &&
Junio C Hamanof577b922011-01-31 12:09:53 -080051 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070052 git commit -m "Side touches a" &&
Junio C Hamanof577b922011-01-31 12:09:53 -080053 git tag side_a1 &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070054 echo "Yet more Irrelevancy" >c &&
55 git add c &&
Junio C Hamanof577b922011-01-31 12:09:53 -080056 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070057 git commit -m "Side makes yet another irrelevant commit" &&
58 git checkout master &&
59 echo Another >b &&
Junio C Hamanof577b922011-01-31 12:09:53 -080060 echo Munged >d/z &&
61 git add b d/z &&
62 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070063 git commit -m "Master touches b" &&
Junio C Hamanof577b922011-01-31 12:09:53 -080064 git tag master_b0 &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070065 git merge side &&
66 echo Touched >b &&
67 git add b &&
Junio C Hamanof577b922011-01-31 12:09:53 -080068 test_tick &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070069 git commit -m "Master touches b again"
70'
71
72test_expect_success 'path optimization 2' '
Junio C Hamanof577b922011-01-31 12:09:53 -080073 git rev-parse side_a1 initial >expected &&
Junio C Hamanobab36bf2007-03-22 23:22:07 -070074 git rev-list HEAD -- a >actual &&
Jeff King82ebb0b2008-03-12 17:36:36 -040075 test_cmp expected actual
Junio C Hamanobab36bf2007-03-22 23:22:07 -070076'
77
Junio C Hamanof577b922011-01-31 12:09:53 -080078test_expect_success 'pathspec with leading path' '
79 git rev-parse master^ master_b0 side_c0 initial >expected &&
80 git rev-list HEAD -- d >actual &&
81 test_cmp expected actual
82'
83
84test_expect_success 'pathspec with glob (1)' '
85 git rev-parse master^ master_b0 side_c0 initial >expected &&
86 git rev-list HEAD -- "d/*" >actual &&
87 test_cmp expected actual
88'
89
90test_expect_success 'pathspec with glob (2)' '
91 git rev-parse side_c0 initial >expected &&
92 git rev-list HEAD -- "d/[a-m]*" >actual &&
93 test_cmp expected actual
94'
95
Alex Riesen57c7d9a2006-07-25 01:23:03 +020096test_done