Skip to content

Commit 6a589fd

Browse files
veillette@yahoo.cagitster
authored andcommitted
filter-branch: Fix renaming a directory in the tree-filter
Commit d89c1df (filter-branch: don't use xargs -0, 2008-03-12) replaced a 'ls-files | xargs rm' pipeline by 'git clean'. 'git clean' however does not recurse and remove directories by default. Now, consider a tree-filter that renames a directory. 1. For the first commit everything works as expected 2. Then filter-branch checks out the files for the next commit. This leaves the new directory behind because there is no real "branch switching" involved that would notice that the directory can be removed. 3. Then filter-branch invokes 'git clean' to remove exactly those left-overs. But here it does not remove the directory. 4. The next tree-filter does not work as expected because there already exists a directory with the new name. Just add -d to 'git clean', so that empty directories are removed. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 9035628 commit 6a589fd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ while read commit parents; do
281281
die "Could not checkout the index"
282282
# files that $commit removed are now still in the working tree;
283283
# remove them, else they would be added again
284-
git clean -q -f -x
284+
git clean -d -q -f -x
285285
eval "$filter_tree" < /dev/null ||
286286
die "tree filter failed: $filter_tree"
287287

t/t7003-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test_expect_success 'rewrite, renaming a specific directory' '
5353
git-filter-branch -f --tree-filter "mv dir diroh || :" HEAD
5454
'
5555

56-
test_expect_failure 'test that the directory was renamed' '
56+
test_expect_success 'test that the directory was renamed' '
5757
test dir/d = "$(git show HEAD:diroh/d --)" &&
5858
! test -d dir &&
5959
test -d diroh &&

0 commit comments

Comments
 (0)