]>
Commit | Line | Data |
---|---|---|
6f6826c5 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='git-filter-branch' | |
4 | . ./test-lib.sh | |
5 | ||
6 | make_commit () { | |
40a7ce64 | 7 | lower=$(echo $1 | tr '[A-Z]' '[a-z]') |
6f6826c5 JS |
8 | echo $lower > $lower |
9 | git add $lower | |
aee078bf | 10 | test_tick |
6f6826c5 JS |
11 | git commit -m $1 |
12 | git tag $1 | |
13 | } | |
14 | ||
15 | test_expect_success 'setup' ' | |
16 | make_commit A | |
17 | make_commit B | |
18 | git checkout -b branch B | |
19 | make_commit D | |
90356287 JS |
20 | mkdir dir |
21 | make_commit dir/D | |
6f6826c5 JS |
22 | make_commit E |
23 | git checkout master | |
24 | make_commit C | |
25 | git checkout branch | |
26 | git merge C | |
27 | git tag F | |
28 | make_commit G | |
29 | make_commit H | |
30 | ' | |
31 | ||
5be60078 | 32 | H=$(git rev-parse H) |
6f6826c5 JS |
33 | |
34 | test_expect_success 'rewrite identically' ' | |
dfd05e38 | 35 | git-filter-branch branch |
6f6826c5 | 36 | ' |
6f6826c5 | 37 | test_expect_success 'result is really identical' ' |
dfd05e38 | 38 | test $H = $(git rev-parse HEAD) |
6f6826c5 JS |
39 | ' |
40 | ||
a4661b01 PB |
41 | test_expect_success 'rewrite bare repository identically' ' |
42 | (git config core.bare true && cd .git && git-filter-branch branch) | |
43 | ' | |
44 | git config core.bare false | |
45 | test_expect_success 'result is really identical' ' | |
46 | test $H = $(git rev-parse HEAD) | |
47 | ' | |
48 | ||
6f6826c5 | 49 | test_expect_success 'rewrite, renaming a specific file' ' |
dfd05e38 | 50 | git-filter-branch -f --tree-filter "mv d doh || :" HEAD |
6f6826c5 JS |
51 | ' |
52 | ||
53 | test_expect_success 'test that the file was renamed' ' | |
90356287 JS |
54 | test d = "$(git show HEAD:doh --)" && |
55 | ! test -f d && | |
46eb449c | 56 | test -f doh && |
90356287 JS |
57 | test d = "$(cat doh)" |
58 | ' | |
59 | ||
60 | test_expect_success 'rewrite, renaming a specific directory' ' | |
61 | git-filter-branch -f --tree-filter "mv dir diroh || :" HEAD | |
62 | ' | |
63 | ||
6a589fda | 64 | test_expect_success 'test that the directory was renamed' ' |
90356287 JS |
65 | test dir/d = "$(git show HEAD:diroh/d --)" && |
66 | ! test -d dir && | |
67 | test -d diroh && | |
68 | ! test -d diroh/dir && | |
69 | test -f diroh/d && | |
70 | test dir/d = "$(cat diroh/d)" | |
6f6826c5 JS |
71 | ' |
72 | ||
dfd05e38 | 73 | git tag oldD HEAD~4 |
98409060 | 74 | test_expect_success 'rewrite one branch, keeping a side branch' ' |
dfd05e38 JS |
75 | git branch modD oldD && |
76 | git-filter-branch -f --tree-filter "mv b boh || :" D..modD | |
98409060 JS |
77 | ' |
78 | ||
79 | test_expect_success 'common ancestor is still common (unchanged)' ' | |
5be60078 | 80 | test "$(git merge-base modD D)" = "$(git rev-parse B)" |
98409060 JS |
81 | ' |
82 | ||
685ef546 JS |
83 | test_expect_success 'filter subdirectory only' ' |
84 | mkdir subdir && | |
85 | touch subdir/new && | |
86 | git add subdir/new && | |
87 | test_tick && | |
88 | git commit -m "subdir" && | |
89 | echo H > a && | |
90 | test_tick && | |
91 | git commit -m "not subdir" a && | |
92 | echo A > subdir/new && | |
93 | test_tick && | |
94 | git commit -m "again subdir" subdir/new && | |
95 | git rm a && | |
96 | test_tick && | |
97 | git commit -m "again not subdir" && | |
dfd05e38 | 98 | git branch sub && |
6e84b712 TR |
99 | git branch sub-earlier HEAD~2 && |
100 | git-filter-branch -f --subdirectory-filter subdir \ | |
101 | refs/heads/sub refs/heads/sub-earlier | |
685ef546 JS |
102 | ' |
103 | ||
104 | test_expect_success 'subdirectory filter result looks okay' ' | |
5be60078 | 105 | test 2 = $(git rev-list sub | wc -l) && |
685ef546 | 106 | git show sub:new && |
6e84b712 TR |
107 | test_must_fail git show sub:subdir && |
108 | git show sub-earlier:new && | |
109 | test_must_fail git show sub-earlier:subdir | |
685ef546 JS |
110 | ' |
111 | ||
a17171b4 | 112 | test_expect_success 'more setup' ' |
cfabd6ee JS |
113 | git checkout master && |
114 | mkdir subdir && | |
115 | echo A > subdir/new && | |
116 | git add subdir/new && | |
117 | test_tick && | |
118 | git commit -m "subdir on master" subdir/new && | |
119 | git rm a && | |
120 | test_tick && | |
121 | git commit -m "again subdir on master" && | |
a17171b4 | 122 | git merge branch |
cfabd6ee JS |
123 | ' |
124 | ||
55f22ff2 | 125 | test_expect_success 'use index-filter to move into a subdirectory' ' |
dfd05e38 JS |
126 | git branch directorymoved && |
127 | git-filter-branch -f --index-filter \ | |
5be60078 | 128 | "git ls-files -s | sed \"s-\\t-&newsubdir/-\" | |
55f22ff2 | 129 | GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \ |
5be60078 | 130 | git update-index --index-info && |
f69e836f | 131 | mv \"\$GIT_INDEX_FILE.new\" \"\$GIT_INDEX_FILE\"" directorymoved && |
55f22ff2 JS |
132 | test -z "$(git diff HEAD directorymoved:newsubdir)"' |
133 | ||
8c1ce0f4 | 134 | test_expect_success 'stops when msg filter fails' ' |
dfd05e38 | 135 | old=$(git rev-parse HEAD) && |
c8a08692 | 136 | test_must_fail git-filter-branch -f --msg-filter false HEAD && |
dfd05e38 JS |
137 | test $old = $(git rev-parse HEAD) && |
138 | rm -rf .git-rewrite | |
8c1ce0f4 JS |
139 | ' |
140 | ||
f6b78c6e JS |
141 | test_expect_success 'author information is preserved' ' |
142 | : > i && | |
143 | git add i && | |
144 | test_tick && | |
145 | GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips && | |
dfd05e38 JS |
146 | git branch preserved-author && |
147 | git-filter-branch -f --msg-filter "cat; \ | |
8c1ce0f4 | 148 | test \$GIT_COMMIT != $(git rev-parse master) || \ |
f6b78c6e JS |
149 | echo Hallo" \ |
150 | preserved-author && | |
151 | test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l) | |
152 | ' | |
153 | ||
154 | test_expect_success "remove a certain author's commits" ' | |
155 | echo i > i && | |
156 | test_tick && | |
157 | git commit -m i i && | |
dfd05e38 JS |
158 | git branch removed-author && |
159 | git-filter-branch -f --commit-filter "\ | |
f6b78c6e JS |
160 | if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\ |
161 | then\ | |
f95eef15 | 162 | skip_commit \"\$@\"; |
f6b78c6e JS |
163 | else\ |
164 | git commit-tree \"\$@\";\ | |
165 | fi" removed-author && | |
166 | cnt1=$(git rev-list master | wc -l) && | |
167 | cnt2=$(git rev-list removed-author | wc -l) && | |
168 | test $cnt1 -eq $(($cnt2 + 1)) && | |
169 | test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l) | |
170 | ' | |
171 | ||
dfd05e38 | 172 | test_expect_success 'barf on invalid name' ' |
c8a08692 BC |
173 | test_must_fail git filter-branch -f master xy-problem && |
174 | test_must_fail git filter-branch -f HEAD^ | |
dfd05e38 JS |
175 | ' |
176 | ||
7e0f1704 JS |
177 | test_expect_success '"map" works in commit filter' ' |
178 | git filter-branch -f --commit-filter "\ | |
179 | parent=\$(git rev-parse \$GIT_COMMIT^) && | |
180 | mapped=\$(map \$parent) && | |
181 | actual=\$(echo \"\$@\" | sed \"s/^.*-p //\") && | |
182 | test \$mapped = \$actual && | |
183 | git commit-tree \"\$@\";" master~2..master && | |
184 | git rev-parse --verify master | |
185 | ' | |
186 | ||
1fe32cb9 JH |
187 | test_expect_success 'Name needing quotes' ' |
188 | ||
189 | git checkout -b rerere A && | |
190 | mkdir foo && | |
191 | name="れれれ" && | |
192 | >foo/$name && | |
193 | git add foo && | |
194 | git commit -m "Adding a file" && | |
195 | git filter-branch --tree-filter "rm -fr foo" && | |
c8a08692 | 196 | test_must_fail git ls-files --error-unmatch "foo/$name" && |
1fe32cb9 JH |
197 | test $(git rev-parse --verify rerere) != $(git rev-parse --verify A) |
198 | ||
199 | ' | |
200 | ||
5b044ac3 JH |
201 | test_expect_success 'Subdirectory filter with disappearing trees' ' |
202 | git reset --hard && | |
203 | git checkout master && | |
204 | ||
205 | mkdir foo && | |
206 | touch foo/bar && | |
207 | git add foo && | |
208 | test_tick && | |
209 | git commit -m "Adding foo" && | |
210 | ||
211 | git rm -r foo && | |
212 | test_tick && | |
213 | git commit -m "Removing foo" && | |
214 | ||
215 | mkdir foo && | |
216 | touch foo/bar && | |
217 | git add foo && | |
218 | test_tick && | |
219 | git commit -m "Re-adding foo" && | |
220 | ||
221 | git filter-branch -f --subdirectory-filter foo && | |
222 | test $(git rev-list master | wc -l) = 3 | |
223 | ' | |
224 | ||
1bf6551e BC |
225 | test_expect_success 'Tag name filtering retains tag message' ' |
226 | git tag -m atag T && | |
227 | git cat-file tag T > expect && | |
228 | git filter-branch -f --tag-name-filter cat && | |
229 | git cat-file tag T > actual && | |
3af82863 | 230 | test_cmp expect actual |
1bf6551e BC |
231 | ' |
232 | ||
233 | faux_gpg_tag='object XXXXXX | |
234 | type commit | |
235 | tag S | |
236 | tagger T A Gger <tagger@example.com> 1206026339 -0500 | |
237 | ||
238 | This is a faux gpg signed tag. | |
239 | -----BEGIN PGP SIGNATURE----- | |
240 | Version: FauxGPG v0.0.0 (FAUX/Linux) | |
241 | ||
242 | gdsfoewhxu/6l06f1kxyxhKdZkrcbaiOMtkJUA9ITAc1mlamh0ooasxkH1XwMbYQ | |
243 | acmwXaWET20H0GeAGP+7vow= | |
244 | =agpO | |
245 | -----END PGP SIGNATURE----- | |
246 | ' | |
247 | test_expect_success 'Tag name filtering strips gpg signature' ' | |
248 | sha1=$(git rev-parse HEAD) && | |
249 | sha1t=$(echo "$faux_gpg_tag" | sed -e s/XXXXXX/$sha1/ | git mktag) && | |
250 | git update-ref "refs/tags/S" "$sha1t" && | |
251 | echo "$faux_gpg_tag" | sed -e s/XXXXXX/$sha1/ | head -n 6 > expect && | |
252 | git filter-branch -f --tag-name-filter cat && | |
253 | git cat-file tag S > actual && | |
3af82863 | 254 | test_cmp expect actual |
1bf6551e BC |
255 | ' |
256 | ||
a9da1663 JS |
257 | test_expect_success 'Tag name filtering allows slashes in tag names' ' |
258 | git tag -m tag-with-slash X/1 && | |
259 | git cat-file tag X/1 | sed -e s,X/1,X/2, > expect && | |
260 | git filter-branch -f --tag-name-filter "echo X/2" && | |
261 | git cat-file tag X/2 > actual && | |
262 | test_cmp expect actual | |
263 | ' | |
264 | ||
6f6826c5 | 265 | test_done |