t8*: adjust the references to the default branch name "main"
[git] / t / t6001-rev-list-graft.sh
1 #!/bin/sh
2
3 test_description='Revision traversal vs grafts and path limiter'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success setup '
11         mkdir subdir &&
12         echo >fileA fileA &&
13         echo >subdir/fileB fileB &&
14         git add fileA subdir/fileB &&
15         git commit -a -m "Initial in one history." &&
16         A0=$(git rev-parse --verify HEAD) &&
17
18         echo >fileA fileA modified &&
19         git commit -a -m "Second in one history." &&
20         A1=$(git rev-parse --verify HEAD) &&
21
22         echo >subdir/fileB fileB modified &&
23         git commit -a -m "Third in one history." &&
24         A2=$(git rev-parse --verify HEAD) &&
25
26         rm -f .git/refs/heads/main .git/index &&
27
28         echo >fileA fileA again &&
29         echo >subdir/fileB fileB again &&
30         git add fileA subdir/fileB &&
31         git commit -a -m "Initial in alternate history." &&
32         B0=$(git rev-parse --verify HEAD) &&
33
34         echo >fileA fileA modified in alternate history &&
35         git commit -a -m "Second in alternate history." &&
36         B1=$(git rev-parse --verify HEAD) &&
37
38         echo >subdir/fileB fileB modified in alternate history &&
39         git commit -a -m "Third in alternate history." &&
40         B2=$(git rev-parse --verify HEAD) &&
41         : done
42 '
43
44 check () {
45         type=$1
46         shift
47
48         arg=
49         which=arg
50         rm -f test.expect
51         for a
52         do
53                 if test "z$a" = z--
54                 then
55                         which=expect
56                         child=
57                         continue
58                 fi
59                 if test "$which" = arg
60                 then
61                         arg="$arg$a "
62                         continue
63                 fi
64                 if test "$type" = basic
65                 then
66                         echo "$a"
67                 else
68                         if test "z$child" != z
69                         then
70                                 echo "$child $a"
71                         fi
72                         child="$a"
73                 fi
74         done >test.expect
75         if test "$type" != basic && test "z$child" != z
76         then
77                 echo >>test.expect $child
78         fi
79         if test $type = basic
80         then
81                 git rev-list $arg >test.actual
82         elif test $type = parents
83         then
84                 git rev-list --parents $arg >test.actual
85         elif test $type = parents-raw
86         then
87                 git rev-list --parents --pretty=raw $arg |
88                 sed -n -e 's/^commit //p' >test.actual
89         fi
90         test_cmp test.expect test.actual
91 }
92
93 for type in basic parents parents-raw
94 do
95         test_expect_success 'without grafts' "
96                 rm -f .git/info/grafts &&
97                 check $type $B2 -- $B2 $B1 $B0
98         "
99
100         test_expect_success 'with grafts' "
101                 echo '$B0 $A2' >.git/info/grafts &&
102                 check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0
103         "
104
105         test_expect_success 'without grafts, with pathlimit' "
106                 rm -f .git/info/grafts &&
107                 check $type $B2 subdir -- $B2 $B0
108         "
109
110         test_expect_success 'with grafts, with pathlimit' "
111                 echo '$B0 $A2' >.git/info/grafts &&
112                 check $type $B2 subdir -- $B2 $B0 $A2 $A0
113         "
114
115 done
116
117 test_expect_success 'show advice that grafts are deprecated' '
118         git show HEAD 2>err &&
119         test_i18ngrep "git replace" err &&
120         test_config advice.graftFileDeprecated false &&
121         git show HEAD 2>err &&
122         test_i18ngrep ! "git replace" err
123 '
124
125 test_done