@matheusbsbs / matheus-bagliano / commits / 5b044ac387
Fork 0

filter-branch: handle "disappearing tree" case correctly in subdir filter

The subdirectory filter had a bug to notice that the commit in question did not have anything in the path-limited part of the tree. $commit:$path does not name an empty tree when $path does not appear in $commit. This should fix it. The additional test in t7003 is originally from Kevin Ballard but with fixups. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 8, 2008 at 12:25 UTC 5b044ac3879b0950675f0e762f1dccbbb9f4001e
2 files changed +34 -1
git-filter-branch.sh
+10 -1
@@ -252,7 +252,16 @@ while read commit parents; do
252 git read-tree -i -m $commit
253 ;;
254 *)
255 - git read-tree -i -m $commit:"$filter_subdir"
255 + # The commit may not have the subdirectory at all
256 + err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || {
257 + if ! git rev-parse --verify $commit:"$filter_subdir" 2>/dev/null
258 + then
259 + rm -f "$GIT_INDEX_FILE"
260 + else
261 + echo >&2 "$err"
262 + false
263 + fi
264 + }
265 esac || die "Could not initialize the index"
266
267 GIT_COMMIT=$commit
t/t7003-filter-branch.sh
+24
@@ -179,4 +179,28 @@ test_expect_success 'Name needing quotes' '
179
180 '
181
182 +test_expect_success 'Subdirectory filter with disappearing trees' '
183 + git reset --hard &&
184 + git checkout master &&
185 +
186 + mkdir foo &&
187 + touch foo/bar &&
188 + git add foo &&
189 + test_tick &&
190 + git commit -m "Adding foo" &&
191 +
192 + git rm -r foo &&
193 + test_tick &&
194 + git commit -m "Removing foo" &&
195 +
196 + mkdir foo &&
197 + touch foo/bar &&
198 + git add foo &&
199 + test_tick &&
200 + git commit -m "Re-adding foo" &&
201 +
202 + git filter-branch -f --subdirectory-filter foo &&
203 + test $(git rev-list master | wc -l) = 3
204 +'
205 +
206 test_done