From 90356287e65181caeaa821d7476b8865d26bc588 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 31 Mar 2008 09:14:14 +0200 Subject: [PATCH 1/2] filter-branch: Test renaming directories in a tree-filter This test currently fails. If b is a directory then 'mv a b' is not a plain "rename", but really a "move", so we must also test that the directory does not exist with the old name in the directory with the new name. There's also some cleanup in the corresponding "rename file" test to avoid spurious shell syntax errors and "ambigous ref" error from 'git show' (but these should show up only if the test would fail anyway). Plus we also test for the non-existence of the old file. Signed-off-by: Johannes Sixt --- t/t7003-filter-branch.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 6827249da5..53b5ce605e 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -17,6 +17,8 @@ test_expect_success 'setup' ' make_commit B git checkout -b branch B make_commit D + mkdir dir + make_commit dir/D make_commit E git checkout master make_commit C @@ -41,9 +43,23 @@ test_expect_success 'rewrite, renaming a specific file' ' ' test_expect_success 'test that the file was renamed' ' - test d = $(git show HEAD:doh) && + test d = "$(git show HEAD:doh --)" && + ! test -f d && test -f doh && - test d = $(cat doh) + test d = "$(cat doh)" +' + +test_expect_success 'rewrite, renaming a specific directory' ' + git-filter-branch -f --tree-filter "mv dir diroh || :" HEAD +' + +test_expect_failure 'test that the directory was renamed' ' + test dir/d = "$(git show HEAD:diroh/d --)" && + ! test -d dir && + test -d diroh && + ! test -d diroh/dir && + test -f diroh/d && + test dir/d = "$(cat diroh/d)" ' git tag oldD HEAD~4 From 6a589fda2e4759e21d66eb2e6814e32baa14beca Mon Sep 17 00:00:00 2001 From: "veillette@yahoo.ca" Date: Mon, 31 Mar 2008 09:14:15 +0200 Subject: [PATCH 2/2] 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 Signed-off-by: Junio C Hamano --- git-filter-branch.sh | 2 +- t/t7003-filter-branch.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 22b6ed4a78..ea59015baa 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -281,7 +281,7 @@ while read commit parents; do die "Could not checkout the index" # files that $commit removed are now still in the working tree; # remove them, else they would be added again - git clean -q -f -x + git clean -d -q -f -x eval "$filter_tree" < /dev/null || die "tree filter failed: $filter_tree" diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 53b5ce605e..efd658adb6 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -53,7 +53,7 @@ test_expect_success 'rewrite, renaming a specific directory' ' git-filter-branch -f --tree-filter "mv dir diroh || :" HEAD ' -test_expect_failure 'test that the directory was renamed' ' +test_expect_success 'test that the directory was renamed' ' test dir/d = "$(git show HEAD:diroh/d --)" && ! test -d dir && test -d diroh &&