3 test_description
='git-filter-branch'
7 lower
=$
(echo $1 |
tr '[A-Z]' '[a-z]')
15 test_expect_success
'setup' '
18 git checkout -b branch B
34 test_expect_success
'rewrite identically' '
35 git-filter-branch branch
37 test_expect_success
'result is really identical' '
38 test $H = $(git rev-parse HEAD)
41 test_expect_success
'rewrite, renaming a specific file' '
42 git-filter-branch -f --tree-filter "mv d doh || :" HEAD
45 test_expect_success
'test that the file was renamed' '
46 test d = "$(git show HEAD:doh --)" &&
52 test_expect_success
'rewrite, renaming a specific directory' '
53 git-filter-branch -f --tree-filter "mv dir diroh || :" HEAD
56 test_expect_success
'test that the directory was renamed' '
57 test dir/d = "$(git show HEAD:diroh/d --)" &&
60 ! test -d diroh/dir &&
62 test dir/d = "$(cat diroh/d)"
66 test_expect_success
'rewrite one branch, keeping a side branch' '
67 git branch modD oldD &&
68 git-filter-branch -f --tree-filter "mv b boh || :" D..modD
71 test_expect_success
'common ancestor is still common (unchanged)' '
72 test "$(git merge-base modD D)" = "$(git rev-parse B)"
75 test_expect_success
'filter subdirectory only' '
80 git commit -m "subdir" &&
83 git commit -m "not subdir" a &&
84 echo A > subdir/new &&
86 git commit -m "again subdir" subdir/new &&
89 git commit -m "again not subdir" &&
91 git-filter-branch -f --subdirectory-filter subdir refs/heads/sub
94 test_expect_success
'subdirectory filter result looks okay' '
95 test 2 = $(git rev-list sub | wc -l) &&
97 test_must_fail git show sub:subdir
100 test_expect_success
'setup and filter history that requires --full-history' '
101 git checkout master &&
103 echo A > subdir/new &&
104 git add subdir/new &&
106 git commit -m "subdir on master" subdir/new &&
109 git commit -m "again subdir on master" &&
111 git branch sub-master &&
112 git-filter-branch -f --subdirectory-filter subdir sub-master
115 test_expect_success
'subdirectory filter result looks okay' '
116 test 3 = $(git rev-list -1 --parents sub-master | wc -w) &&
117 git show sub-master^:new &&
118 git show sub-master^2:new &&
119 test_must_fail git show sub:subdir
122 test_expect_success
'use index-filter to move into a subdirectory' '
123 git branch directorymoved &&
124 git-filter-branch -f --index-filter \
125 "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
126 GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
127 git update-index --index-info &&
128 mv \"\$GIT_INDEX_FILE.new\" \"\$GIT_INDEX_FILE\"" directorymoved &&
129 test -z "$(git diff HEAD directorymoved:newsubdir)"'
131 test_expect_success
'stops when msg filter fails' '
132 old=$(git rev-parse HEAD) &&
133 test_must_fail git-filter-branch -f --msg-filter false HEAD &&
134 test $old = $(git rev-parse HEAD) &&
138 test_expect_success
'author information is preserved' '
142 GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
143 git branch preserved-author &&
144 git-filter-branch -f --msg-filter "cat; \
145 test \$GIT_COMMIT != $(git rev-parse master) || \
148 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
151 test_expect_success
"remove a certain author's commits" '
155 git branch removed-author &&
156 git-filter-branch -f --commit-filter "\
157 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
161 git commit-tree \"\$@\";\
162 fi" removed-author &&
163 cnt1=$(git rev-list master | wc -l) &&
164 cnt2=$(git rev-list removed-author | wc -l) &&
165 test $cnt1 -eq $(($cnt2 + 1)) &&
166 test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l)
169 test_expect_success
'barf on invalid name' '
170 test_must_fail git filter-branch -f master xy-problem &&
171 test_must_fail git filter-branch -f HEAD^
174 test_expect_success
'"map" works in commit filter' '
175 git filter-branch -f --commit-filter "\
176 parent=\$(git rev-parse \$GIT_COMMIT^) &&
177 mapped=\$(map \$parent) &&
178 actual=\$(echo \"\$@\" | sed \"s/^.*-p //\") &&
179 test \$mapped = \$actual &&
180 git commit-tree \"\$@\";" master~2..master &&
181 git rev-parse --verify master
184 test_expect_success
'Name needing quotes' '
186 git checkout -b rerere A &&
191 git commit -m "Adding a file" &&
192 git filter-branch --tree-filter "rm -fr foo" &&
193 test_must_fail git ls-files --error-unmatch "foo/$name" &&
194 test $(git rev-parse --verify rerere) != $(git rev-parse --verify A)
198 test_expect_success
'Subdirectory filter with disappearing trees' '
200 git checkout master &&
206 git commit -m "Adding foo" &&
210 git commit -m "Removing foo" &&
216 git commit -m "Re-adding foo" &&
218 git filter-branch -f --subdirectory-filter foo &&
219 test $(git rev-list master | wc -l) = 3