git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] filter-branch: Fix renaming a directory in the tree-filter

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Mar 31, 2008, 07:14 UTC
Message-ID
<1206947655-20272-2-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<1206947655-20272-1-git-send-email-johannes.sixt@telecom.at>
From: Jean-François Veillette <jean francois veillette@yahoo.ca>

Commit d89c1dfac939623a269f60d4e27e3a2929dca29c replaced a 'ls-files | xargs rm' pipeline by 'git clean'. But since 'git clean' 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'.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 Jean-Francois, there's no sign-off from you. Ok to add it?
 -- Hannes
 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 22b6ed4..ea59015 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 53b5ce6..efd658a 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 &&
-- 
1.5.4.4
Previous: Johannes SixtNext: Johannes Sixt
Message 4 of 9 in “[bug] filter-branch skipping removed files”
  1. Jean-François VeilletteMar 30, 2008
  2. Jean-François VeilletteMar 30, 2008
  3. filter-branch: Test renaming directories in a tree-filterJohannes Sixt, Mar 31, 2008
  4. filter-branch: Fix renaming a directory in the tree-filterJohannes Sixt, Mar 31, 2008
  5. Johannes SixtMar 31, 2008
  6. Junio C HamanoMar 31, 2008
  7. Johannes SixtMar 31, 2008
  8. Johannes SchindelinMar 31, 2008
  9. Jean-François VeilletteMar 31, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.