Code

Add some basic assertions to test.sh.
[git.git] / test.sh
1 #!/bin/bash
2 . shellopts.sh
3 set -e
5 create()
6 {
7         echo "$1" >"$1"
8         git add "$1"
9 }
11 check()
12 {
13         echo
14         echo "check:" "$@"
15         if "$@"; then
16                 echo ok
17                 return 0
18         else
19                 echo FAILED
20                 exit 1
21         fi
22 }
24 check_equal()
25 {
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
34         fi
35 }
37 fixnl()
38 {       
39         t=""
40         while read x; do
41                 t="$t$x "
42         done
43         echo $t
44 }
46 multiline()
47 {
48         while read x; do
49                 set -- $x
50                 for d in "$@"; do
51                         echo "$d"
52                 done
53         done
54 }
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 split1=$(git subtree split --annotate='*' --prefix subdir --onto FETCH_HEAD --rejoin)
104 echo "split1={$split1}"
105 git branch split1 "$split1"
107 create subdir/main-sub8
108 git commit -m 'main-sub8'
110 cd ../subproj
111 git fetch ../mainline split1
112 git branch split1 FETCH_HEAD
113 git merge FETCH_HEAD
115 create sub9
116 git commit -m 'sub9'
118 cd ../mainline
119 split2=$(git subtree split --annotate='*' --prefix subdir --rejoin)
120 git branch split2 "$split2"
122 create subdir/main-sub10
123 git commit -m 'main-sub10'
125 split3=$(git subtree split --annotate='*' --prefix subdir --rejoin)
126 git branch split3 "$split3"
128 cd ../subproj
129 git fetch ../mainline split3
130 git branch split3 FETCH_HEAD
131 git merge FETCH_HEAD
132 git branch subproj-merge-split3
134 chkm="main4 main6"
135 chkms="main-sub10 main-sub5 main-sub7 main-sub8"
136 chkms_sub=$(echo $chkms | multiline | sed 's,^,subdir/,' | fixnl)
137 chks="sub1 sub2 sub3 sub9"
138 chks_sub=$(echo $chks | multiline | sed 's,^,subdir/,' | fixnl)
140 # make sure exactly the right set of files ends up in the subproj
141 subfiles=$(git ls-files | fixnl)
142 check_equal "$subfiles" "$chkms $chks"
144 # make sure the subproj history *only* contains commits that affect the subdir.
145 allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
146 check_equal "$allchanges" "$chkms $chks"
148 cd ../mainline
149 git fetch ../subproj subproj-merge-split3
150 git branch subproj-merge-split3 FETCH_HEAD
151 git subtree pull --prefix=subdir ../subproj subproj-merge-split3
153 # make sure exactly the right set of files ends up in the mainline
154 mainfiles=$(git ls-files | fixnl)
155 check_equal "$mainfiles" "$chkm $chkms_sub $chks_sub"
157 # make sure each filename changed exactly once in the entire history.
158 # 'main-sub??' and '/subdir/main-sub??' both change, because those are the
159 # changes that were split into their own history.  And 'subdir/sub??' never
160 # change, since they were *only* changed in the subtree branch.
161 allchanges=$(git log --name-only --pretty=format:'' | sort | fixnl)
162 check_equal "$allchanges" "$chkm $chkms $chks $chkms_sub"