Add basic git-subtree manpage in asciidoc format.
[git-subtree.git] / test.sh
blob38dff7a41af25e109069ca63d44d481bd6678742
1 #!/bin/bash
2 . shellopts.sh
3 set -e
5 create()
7 echo "$1" >"$1"
8 git add "$1"
11 check()
13 echo
14 echo "check:" "$@"
15 if "$@"; then
16 echo ok
17 return 0
18 else
19 echo FAILED
20 exit 1
24 check_equal()
26 echo
27 echo "check a:" "{$1}"
28 echo " b:" "{$2}"
29 if [ "$1" = "$2" ]; then
30 return 0
31 else
32 echo FAILED
33 exit 1
37 fixnl()
39 t=""
40 while read x; do
41 t="$t$x "
42 done
43 echo $t
46 multiline()
48 while read x; do
49 set -- $x
50 for d in "$@"; do
51 echo "$d"
52 done
53 done
56 rm -rf mainline subproj
57 mkdir mainline subproj
59 cd subproj
60 git init
62 create sub1
63 git commit -m 'sub1'
64 git branch sub1
65 git branch -m master subproj
66 check true
68 create sub2
69 git commit -m 'sub2'
70 git branch sub2
72 create sub3
73 git commit -m 'sub3'
74 git branch sub3
76 cd ../mainline
77 git init
78 create main4
79 git commit -m 'main4'
80 git branch -m master mainline
82 git fetch ../subproj sub1
83 git branch sub1 FETCH_HEAD
84 git subtree add --prefix=subdir FETCH_HEAD
86 # this shouldn't actually do anything, since FETCH_HEAD is already a parent
87 git merge -m 'merge -s -ours' -s ours FETCH_HEAD
89 create subdir/main-sub5
90 git commit -m 'main-sub5'
92 create main6
93 git commit -m 'main6 boring'
95 create subdir/main-sub7
96 git commit -m 'main-sub7'
98 git fetch ../subproj sub2
99 git branch sub2 FETCH_HEAD
100 git subtree merge --prefix=subdir FETCH_HEAD
101 git branch pre-split
103 spl1=$(git subtree split --annotate='*' \
104 --prefix subdir --onto FETCH_HEAD --rejoin)
105 echo "spl1={$spl1}"
106 git branch spl1 "$spl1"
108 create subdir/main-sub8
109 git commit -m 'main-sub8'
111 cd ../subproj
112 git fetch ../mainline spl1
113 git branch spl1 FETCH_HEAD
114 git merge FETCH_HEAD
116 create sub9
117 git commit -m 'sub9'
119 cd ../mainline
120 split2=$(git subtree split --annotate='*' --prefix subdir --rejoin)
121 git branch split2 "$split2"
123 create subdir/main-sub10
124 git commit -m 'main-sub10'
126 spl3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
127 git branch spl3 "$spl3"
129 cd ../subproj
130 git fetch ../mainline spl3
131 git branch spl3 FETCH_HEAD
132 git merge FETCH_HEAD
133 git branch subproj-merge-spl3
135 chkm="main4 main6"
136 chkms="main-sub10 main-sub5 main-sub7 main-sub8"
137 chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
138 chks="sub1 sub2 sub3 sub9"
139 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
141 # make sure exactly the right set of files ends up in the subproj
142 subfiles=$(git ls-files | fixnl)
143 check_equal "$subfiles" "$chkms $chks"
145 # make sure the subproj history *only* contains commits that affect the subdir.
146 allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
147 check_equal "$allchanges" "$chkms $chks"
149 cd ../mainline
150 git fetch ../subproj subproj-merge-spl3
151 git branch subproj-merge-spl3 FETCH_HEAD
152 git subtree pull --prefix=subdir ../subproj subproj-merge-spl3
154 # make sure exactly the right set of files ends up in the mainline
155 mainfiles=$(git ls-files | fixnl)
156 check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
158 # make sure each filename changed exactly once in the entire history.
159 # 'main-sub??' and '/subdir/main-sub??' both change, because those are the
160 # changes that were split into their own history. And 'subdir/sub??' never
161 # change, since they were *only* changed in the subtree branch.
162 allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
163 check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub"
165 # make sure the --rejoin commits never make it into subproj
166 check_equal "$(git log --pretty=format:'%s' HEAD^2 | grep -i split)" ""
168 # make sure no 'git subtree' tagged commits make it into subproj. (They're
169 # meaningless to subproj since one side of the merge refers to the mainline)
170 check_equal "$(git log --pretty=format:'%s%n%b' HEAD^2 | grep 'git-subtree.*:')" ""
172 # make sure no patch changes more than one file. The original set of commits
173 # changed only one file each. A multi-file change would imply that we pruned
174 # commits too aggressively.
175 joincommits()
177 commit=
178 all=
179 while read x y; do
180 echo "{$x}" >&2
181 if [ -z "$x" ]; then
182 continue
183 elif [ "$x" = "commit:" ]; then
184 if [ -n "$commit" ]; then
185 echo "$commit $all"
186 all=
188 commit="$y"
189 else
190 all="$all $y"
192 done
193 echo "$commit $all"
196 git log --pretty=format:'commit: %H' | joincommits |
197 ( while read commit a b; do
198 echo "Verifying commit $commit"
199 check_equal "$b" ""
201 done
202 check_equal "$x" 1
203 ) || exit 1
205 echo
206 echo 'ok'