{"thread":{"id":"12922","subject":"[bug] filter-branch skipping removed files","startedAt":"2008-03-30T14:35:52Z","lastAt":"2008-03-31T12:15:51Z","messageCount":9,"participants":["Jean-François Veillette","Johannes Sixt","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"73359","messageId":"CC52AEE1-2F50-48F2-9A17-CD315E2DCB0A@yahoo.ca","threadId":"12922","inReplyTo":null,"subject":"[bug] filter-branch skipping removed files","fromName":"Jean-François Veillette","fromEmail":"jean_francois_veillette@yahoo.ca","sentAt":"2008-03-30T14:35:52Z","receivedAt":"2008-03-30T14:35:52Z","isPatch":false,"sender":{"key":"jean_francois_veillette@yahoo.ca","avatar":null},"body":"I'm experimenting with git filter-branch to simplify the change  \nhistory.  I would like to rewrite the history and remove unwanted  \nfiles and reformat the sources to remove all the change's noises  \n(whitespace changes, code reformat).\nBut the new history miss some commits of removed files.\nI was preparing a simple test (down bellow) when I thought, why not  \ntry to fix it (my first journey inside git).\nIt turn out I was able to fix the problem, it was almost too easy:\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 22b6ed4..26ebb6c 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -277,7 +277,7 @@ while read commit parents; do\n  \t\tdie \"env filter failed: $filter_env\"\n\n   \tif [ \"$filter_tree\" ]; then\n-\t\tgit checkout-index -f -u -a ||\n+\t\tgit checkout-index -d -f -u -a ||\n  \t\t\tdie \"Could not checkout the index\"\n  \t\t# files that $commit removed are now still in the working tree;\n  \t\t# remove them, else they would be added again\n\n\nIt was my first try, just because I noticed that git-clean was giving  \na 'warning' of non removed directory.  At that point I just wanted to  \nremove the warning ... but that was enough to fix the problem !\nI don't know if it's a real fix, but at least it does correct the  \nproblem I'm having.\nI have no idea of the implication of what I just touched.  the 'real'  \nproblem might very well be somewhere else.\n\n\nHere is a simple test that show the problem.\n\n$: mkdir test ; cd test\n$: git init\nInitialized empty Git repository in .git/\n$: echo 'line A' > a.txt\n$: echo 'line B' > b.txt\n$: mkdir subdir\n$: echo 'line subA' > subdir/a.txt\n$: echo 'line subB' > subdir/b.txt\n$: git add *\n$: git commit -m 'first commit'\nCreated initial commit f264d57: first commit\n  4 files changed, 4 insertions(+), 0 deletions(-)\n  create mode 100644 a.txt\n  create mode 100644 b.txt\n  create mode 100644 subdir/a.txt\n  create mode 100644 subdir/b.txt\n$: git rm b.txt subdir/b.txt\nrm 'b.txt'\nrm 'subdir/b.txt'\n$: git commit -m 'remove b files'\nCreated commit b064598: remove b files\n  2 files changed, 0 insertions(+), 2 deletions(-)\n  delete mode 100644 b.txt\n  delete mode 100644 subdir/b.txt\n$: echo 'line AA' >> a.txt\n$: echo 'line subAA' >> subdir/a.txt\n$: git add *\n$: git commit -m 'modified a files'\nCreated commit 0f914cb: modified a files\n  2 files changed, 2 insertions(+), 0 deletions(-)\n$: git rm subdir/a.txt\nrm 'subdir/a.txt'\n$: git commit -m 'removed all sub files'\nCreated commit 41c0de7: removed all sub files\n  1 files changed, 0 insertions(+), 2 deletions(-)\n  delete mode 100644 subdir/a.txt\n$: ls -la\n...git   a.txt\n$: echo 'line AAA' >> a.txt\n$: git add *\n$: git commit -m 'modified a.txt'\nCreated commit c21e292: modified a.txt\n  1 files changed, 1 insertions(+), 0 deletions(-)\n\n\n\n$: git filter-branch --tree-filter 'ls -lR'   # do nothing, juste  \nrewrite itself\nRewrite f264d57f476858aa4ddbf70358500c3be7298048 (1/5)total 16\n-rw-r--r--   1 jfv  jfv    7 30 mar 09:38 a.txt\n-rw-r--r--   1 jfv  jfv    7 30 mar 09:38 b.txt\ndrwxr-xr-x   4 jfv  jfv  136 30 mar 09:38 subdir\n\n.../subdir:\ntotal 16\n-rw-r--r--   1 jfv  jfv  10 30 mar 09:38 a.txt\n-rw-r--r--   1 jfv  jfv  10 30 mar 09:38 b.txt\nRewrite b064598f57b4679febaeddda6dfbde43a935796a (2/5)total 8\n-rw-r--r--   1 jfv  jfv    7 30 mar 09:38 a.txt\ndrwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n\n.../subdir:\ntotal 8\n-rw-r--r--   1 jfv  jfv  10 30 mar 09:38 a.txt\nRewrite 0f914cb21ab65aac5d966a9552bfb63aa73a996a (3/5)total 8\n-rw-r--r--   1 jfv  jfv   15 30 mar 09:38 a.txt\ndrwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n\n.../subdir:\ntotal 8\n-rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\nRewrite 41c0de77880245c23bb56b0b1936564c7adf63de (4/5)Not removing  \nsubdir/\ntotal 8\n-rw-r--r--   1 jfv  jfv   15 30 mar 09:38 a.txt\ndrwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n\n.../subdir:\ntotal 8\n-rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\nRewrite c21e292486500afa3a0ded69f4edf30de11d42d1 (5/5)Not removing  \nsubdir/\ntotal 8\n-rw-r--r--   1 jfv  jfv   24 30 mar 09:38 a.txt\ndrwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n\n.../subdir:\ntotal 8\n-rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\n\nRef 'refs/heads/master' was rewritten\n\n\n\n$: git log -p\ncommit c3715041ae38ccc6596986fd1927aff65a3d14bf\nAuthor: Jean-François Veillette <jfveillette@os.ca>\nDate:   Sun Mar 30 09:35:01 2008 -0400\n\n     modified a.txt\n\ndiff --git a/a.txt b/a.txt\nindex 457599c..36d130e 100644\n--- a/a.txt\n+++ b/a.txt\n@@ -1,2 +1,3 @@\n  line A\n  line AA\n+line AAA\n\ncommit d45ccff19c3c81f8c78a22ed5c2436c7a5b99f7c\nAuthor: Jean-François Veillette <jfveillette@os.ca>\nDate:   Sun Mar 30 09:33:48 2008 -0400\n\n     removed all sub files\n\ncommit 0f914cb21ab65aac5d966a9552bfb63aa73a996a\nAuthor: Jean-François Veillette <jfveillette@os.ca>\nDate:   Sun Mar 30 09:33:07 2008 -0400\n\n     modified a files\n\ndiff --git a/a.txt b/a.txt\nindex 102c5da..457599c 100644\n--- a/a.txt\n+++ b/a.txt\n@@ -1 +1,2 @@\n  line A\n+line AA\ndiff --git a/subdir/a.txt b/subdir/a.txt\nindex 56e593a..b215539 100644\n--- a/subdir/a.txt\n+++ b/subdir/a.txt\n@@ -1 +1,2 @@\n  line subA\n+line subAA\n\ncommit b064598f57b4679febaeddda6dfbde43a935796a\nAuthor: Jean-François Veillette <jfveillette@os.ca>\nDate:   Sun Mar 30 09:32:13 2008 -0400\n\n     remove b files\n\ndiff --git a/b.txt b/b.txt\ndeleted file mode 100644\nindex 346d560..0000000\n--- a/b.txt\n+++ /dev/null\n@@ -1 +0,0 @@\n-line B\ndiff --git a/subdir/b.txt b/subdir/b.txt\ndeleted file mode 100644\nindex 7cbec67..0000000\n--- a/subdir/b.txt\n+++ /dev/null\n@@ -1 +0,0 @@\n-line subB\n\ncommit f264d57f476858aa4ddbf70358500c3be7298048\nAuthor: Jean-François Veillette <jfveillette@os.ca>\nDate:   Sun Mar 30 09:29:28 2008 -0400\n\n     first commit\n\ndiff --git a/a.txt b/a.txt\nnew file mode 100644\nindex 0000000..102c5da\n--- /dev/null\n+++ b/a.txt\n@@ -0,0 +1 @@\n+line A\ndiff --git a/b.txt b/b.txt\nnew file mode 100644\nindex 0000000..346d560\n--- /dev/null\n+++ b/b.txt\n@@ -0,0 +1 @@\n+line B\ndiff --git a/subdir/a.txt b/subdir/a.txt\nnew file mode 100644\nindex 0000000..56e593a\n--- /dev/null\n+++ b/subdir/a.txt\n@@ -0,0 +1 @@\n+line subA\ndiff --git a/subdir/b.txt b/subdir/b.txt\nnew file mode 100644\nindex 0000000..7cbec67\n--- /dev/null\n+++ b/subdir/b.txt\n@@ -0,0 +1 @@\n+line subB\n\n\n- jfv\n"},{"id":"73375","messageId":"C46D6D0D-44E1-4976-8956-1D84B6351535@yahoo.ca","threadId":"12922","inReplyTo":"CC52AEE1-2F50-48F2-9A17-CD315E2DCB0A@yahoo.ca","subject":"Re: [bug] filter-branch skipping removed files","fromName":"Jean-François Veillette","fromEmail":"jean_francois_veillette@yahoo.ca","sentAt":"2008-03-30T23:05:16Z","receivedAt":"2008-03-30T23:05:16Z","isPatch":false,"sender":{"key":"jean_francois_veillette@yahoo.ca","avatar":null},"body":"\n\n> It turn out I was able to fix the problem, it was almost too easy:\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 22b6ed4..493c81e 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -281,7 +281,7 @@ while read commit parents; do\n                         die \"Could not checkout the index\"\n                 # files that $commit removed are now still in the  \nworking tree;\n                 # remove them, else they would be added again\n-               git clean -q -f -x\n+               git clean -d -q -f -x\n                 eval \"$filter_tree\" < /dev/null ||\n                         die \"tree filter failed: $filter_tree\"\n\n\nPreviously wrong diff, use the one above instead.\n\nwhy? : changed the installed copy, tested, then reapplied the '-d'  \ndiff (from memory) to the wrong line in my git workarea to get the diff.\n\n- jfv\n\n\n> It was my first try, just because I noticed that git-clean was  \n> giving a 'warning' of non removed directory.  At that point I just  \n> wanted to remove the warning ... but that was enough to fix the  \n> problem !\n> I don't know if it's a real fix, but at least it does correct the  \n> problem I'm having.\n> I have no idea of the implication of what I just touched.  the  \n> 'real' problem might very well be somewhere else.\n>\n>\n> Here is a simple test that show the problem.\n>\n> $: mkdir test ; cd test\n> $: git init\n> Initialized empty Git repository in .git/\n> $: echo 'line A' > a.txt\n> $: echo 'line B' > b.txt\n> $: mkdir subdir\n> $: echo 'line subA' > subdir/a.txt\n> $: echo 'line subB' > subdir/b.txt\n> $: git add *\n> $: git commit -m 'first commit'\n> Created initial commit f264d57: first commit\n>  4 files changed, 4 insertions(+), 0 deletions(-)\n>  create mode 100644 a.txt\n>  create mode 100644 b.txt\n>  create mode 100644 subdir/a.txt\n>  create mode 100644 subdir/b.txt\n> $: git rm b.txt subdir/b.txt\n> rm 'b.txt'\n> rm 'subdir/b.txt'\n> $: git commit -m 'remove b files'\n> Created commit b064598: remove b files\n>  2 files changed, 0 insertions(+), 2 deletions(-)\n>  delete mode 100644 b.txt\n>  delete mode 100644 subdir/b.txt\n> $: echo 'line AA' >> a.txt\n> $: echo 'line subAA' >> subdir/a.txt\n> $: git add *\n> $: git commit -m 'modified a files'\n> Created commit 0f914cb: modified a files\n>  2 files changed, 2 insertions(+), 0 deletions(-)\n> $: git rm subdir/a.txt\n> rm 'subdir/a.txt'\n> $: git commit -m 'removed all sub files'\n> Created commit 41c0de7: removed all sub files\n>  1 files changed, 0 insertions(+), 2 deletions(-)\n>  delete mode 100644 subdir/a.txt\n> $: ls -la\n> ...git   a.txt\n> $: echo 'line AAA' >> a.txt\n> $: git add *\n> $: git commit -m 'modified a.txt'\n> Created commit c21e292: modified a.txt\n>  1 files changed, 1 insertions(+), 0 deletions(-)\n>\n>\n>\n> $: git filter-branch --tree-filter 'ls -lR'   # do nothing, juste  \n> rewrite itself\n> Rewrite f264d57f476858aa4ddbf70358500c3be7298048 (1/5)total 16\n> -rw-r--r--   1 jfv  jfv    7 30 mar 09:38 a.txt\n> -rw-r--r--   1 jfv  jfv    7 30 mar 09:38 b.txt\n> drwxr-xr-x   4 jfv  jfv  136 30 mar 09:38 subdir\n>\n> .../subdir:\n> total 16\n> -rw-r--r--   1 jfv  jfv  10 30 mar 09:38 a.txt\n> -rw-r--r--   1 jfv  jfv  10 30 mar 09:38 b.txt\n> Rewrite b064598f57b4679febaeddda6dfbde43a935796a (2/5)total 8\n> -rw-r--r--   1 jfv  jfv    7 30 mar 09:38 a.txt\n> drwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n>\n> .../subdir:\n> total 8\n> -rw-r--r--   1 jfv  jfv  10 30 mar 09:38 a.txt\n> Rewrite 0f914cb21ab65aac5d966a9552bfb63aa73a996a (3/5)total 8\n> -rw-r--r--   1 jfv  jfv   15 30 mar 09:38 a.txt\n> drwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n>\n> .../subdir:\n> total 8\n> -rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\n> Rewrite 41c0de77880245c23bb56b0b1936564c7adf63de (4/5)Not removing  \n> subdir/\n> total 8\n> -rw-r--r--   1 jfv  jfv   15 30 mar 09:38 a.txt\n> drwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n>\n> .../subdir:\n> total 8\n> -rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\n> Rewrite c21e292486500afa3a0ded69f4edf30de11d42d1 (5/5)Not removing  \n> subdir/\n> total 8\n> -rw-r--r--   1 jfv  jfv   24 30 mar 09:38 a.txt\n> drwxr-xr-x   3 jfv  jfv  102 30 mar 09:38 subdir\n>\n> .../subdir:\n> total 8\n> -rw-r--r--   1 jfv  jfv  21 30 mar 09:38 a.txt\n>\n> Ref 'refs/heads/master' was rewritten\n>\n>\n>\n> $: git log -p\n> commit c3715041ae38ccc6596986fd1927aff65a3d14bf\n> Author: Jean-François Veillette <jfveillette@os.ca>\n> Date:   Sun Mar 30 09:35:01 2008 -0400\n>\n>     modified a.txt\n>\n> diff --git a/a.txt b/a.txt\n> index 457599c..36d130e 100644\n> --- a/a.txt\n> +++ b/a.txt\n> @@ -1,2 +1,3 @@\n>  line A\n>  line AA\n> +line AAA\n>\n> commit d45ccff19c3c81f8c78a22ed5c2436c7a5b99f7c\n> Author: Jean-François Veillette <jfveillette@os.ca>\n> Date:   Sun Mar 30 09:33:48 2008 -0400\n>\n>     removed all sub files\n>\n> commit 0f914cb21ab65aac5d966a9552bfb63aa73a996a\n> Author: Jean-François Veillette <jfveillette@os.ca>\n> Date:   Sun Mar 30 09:33:07 2008 -0400\n>\n>     modified a files\n>\n> diff --git a/a.txt b/a.txt\n> index 102c5da..457599c 100644\n> --- a/a.txt\n> +++ b/a.txt\n> @@ -1 +1,2 @@\n>  line A\n> +line AA\n> diff --git a/subdir/a.txt b/subdir/a.txt\n> index 56e593a..b215539 100644\n> --- a/subdir/a.txt\n> +++ b/subdir/a.txt\n> @@ -1 +1,2 @@\n>  line subA\n> +line subAA\n>\n> commit b064598f57b4679febaeddda6dfbde43a935796a\n> Author: Jean-François Veillette <jfveillette@os.ca>\n> Date:   Sun Mar 30 09:32:13 2008 -0400\n>\n>     remove b files\n>\n> diff --git a/b.txt b/b.txt\n> deleted file mode 100644\n> index 346d560..0000000\n> --- a/b.txt\n> +++ /dev/null\n> @@ -1 +0,0 @@\n> -line B\n> diff --git a/subdir/b.txt b/subdir/b.txt\n> deleted file mode 100644\n> index 7cbec67..0000000\n> --- a/subdir/b.txt\n> +++ /dev/null\n> @@ -1 +0,0 @@\n> -line subB\n>\n> commit f264d57f476858aa4ddbf70358500c3be7298048\n> Author: Jean-François Veillette <jfveillette@os.ca>\n> Date:   Sun Mar 30 09:29:28 2008 -0400\n>\n>     first commit\n>\n> diff --git a/a.txt b/a.txt\n> new file mode 100644\n> index 0000000..102c5da\n> --- /dev/null\n> +++ b/a.txt\n> @@ -0,0 +1 @@\n> +line A\n> diff --git a/b.txt b/b.txt\n> new file mode 100644\n> index 0000000..346d560\n> --- /dev/null\n> +++ b/b.txt\n> @@ -0,0 +1 @@\n> +line B\n> diff --git a/subdir/a.txt b/subdir/a.txt\n> new file mode 100644\n> index 0000000..56e593a\n> --- /dev/null\n> +++ b/subdir/a.txt\n> @@ -0,0 +1 @@\n> +line subA\n> diff --git a/subdir/b.txt b/subdir/b.txt\n> new file mode 100644\n> index 0000000..7cbec67\n> --- /dev/null\n> +++ b/subdir/b.txt\n> @@ -0,0 +1 @@\n> +line subB\n>\n>\n> - jfv\n>\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"73417","messageId":"1206947655-20272-1-git-send-email-johannes.sixt@telecom.at","threadId":"12922","inReplyTo":"C46D6D0D-44E1-4976-8956-1D84B6351535@yahoo.ca","subject":"[PATCH] filter-branch: Test renaming directories in a tree-filter","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-03-31T07:14:14Z","receivedAt":"2008-03-31T07:14:14Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"This test currently fails.\n\nIf b is a directory then 'mv a b' is not a plain \"rename\", but really a\n\"move\", so we must also test that the directory does not exist with the\nold name in the directory with the new name.\n\nThere's also some cleanup in the corresponding \"rename file\" test to avoid\nspurious shell syntax errors and \"ambigous ref\" error from 'git show' (but\nthese should show up only if the test would fail anyway). Plus we also\ntest for the non-existence of the old file.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n t/t7003-filter-branch.sh |   20 ++++++++++++++++++--\n 1 files changed, 18 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 6827249..53b5ce6 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -17,6 +17,8 @@ test_expect_success 'setup' '\n \tmake_commit B\n \tgit checkout -b branch B\n \tmake_commit D\n+\tmkdir dir\n+\tmake_commit dir/D\n \tmake_commit E\n \tgit checkout master\n \tmake_commit C\n@@ -41,9 +43,23 @@ test_expect_success 'rewrite, renaming a specific file' '\n '\n \n test_expect_success 'test that the file was renamed' '\n-\ttest d = $(git show HEAD:doh) &&\n+\ttest d = \"$(git show HEAD:doh --)\" &&\n+\t! test -f d &&\n \ttest -f doh &&\n-\ttest d = $(cat doh)\n+\ttest d = \"$(cat doh)\"\n+'\n+\n+test_expect_success 'rewrite, renaming a specific directory' '\n+\tgit-filter-branch -f --tree-filter \"mv dir diroh || :\" HEAD\n+'\n+\n+test_expect_failure 'test that the directory was renamed' '\n+\ttest dir/d = \"$(git show HEAD:diroh/d --)\" &&\n+\t! test -d dir &&\n+\ttest -d diroh &&\n+\t! test -d diroh/dir &&\n+\ttest -f diroh/d &&\n+\ttest dir/d = \"$(cat diroh/d)\"\n '\n \n git tag oldD HEAD~4\n-- \n1.5.4.4\n"},{"id":"73418","messageId":"1206947655-20272-2-git-send-email-johannes.sixt@telecom.at","threadId":"12922","inReplyTo":"1206947655-20272-1-git-send-email-johannes.sixt@telecom.at","subject":"[PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-03-31T07:14:15Z","receivedAt":"2008-03-31T07:14:15Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Jean-François Veillette <jean francois veillette@yahoo.ca>\n\nCommit d89c1dfac939623a269f60d4e27e3a2929dca29c replaced a\n'ls-files | xargs rm' pipeline by 'git clean'. But since 'git clean' does\nnot recurse and remove directories by default. Now, consider a tree-filter\nthat renames a directory.\n\n1. For the first commit everything works as expected\n2. Then filter-branch checks out the files for the next commit. This\n   leaves the new directory behind because there is no real \"branch\n   switching\" involved that would notice that the directory can be\n   removed.\n3. Then filter-branch invokes 'git clean' to remove exactly those\n   left-overs. But here it does not remove the directory.\n4. The next tree-filter does not work as expected because there already\n   exists a directory with the new name.\n\nJust add -d to 'git clean'.\n\nSigned-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n---\n Jean-Francois, there's no sign-off from you. Ok to add it?\n\n -- Hannes\n\n git-filter-branch.sh     |    2 +-\n t/t7003-filter-branch.sh |    2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/git-filter-branch.sh b/git-filter-branch.sh\nindex 22b6ed4..ea59015 100755\n--- a/git-filter-branch.sh\n+++ b/git-filter-branch.sh\n@@ -281,7 +281,7 @@ while read commit parents; do\n \t\t\tdie \"Could not checkout the index\"\n \t\t# files that $commit removed are now still in the working tree;\n \t\t# remove them, else they would be added again\n-\t\tgit clean -q -f -x\n+\t\tgit clean -d -q -f -x\n \t\teval \"$filter_tree\" < /dev/null ||\n \t\t\tdie \"tree filter failed: $filter_tree\"\n \ndiff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh\nindex 53b5ce6..efd658a 100755\n--- a/t/t7003-filter-branch.sh\n+++ b/t/t7003-filter-branch.sh\n@@ -53,7 +53,7 @@ test_expect_success 'rewrite, renaming a specific directory' '\n \tgit-filter-branch -f --tree-filter \"mv dir diroh || :\" HEAD\n '\n \n-test_expect_failure 'test that the directory was renamed' '\n+test_expect_success 'test that the directory was renamed' '\n \ttest dir/d = \"$(git show HEAD:diroh/d --)\" &&\n \t! test -d dir &&\n \ttest -d diroh &&\n-- \n1.5.4.4\n"},{"id":"73419","messageId":"47F09AEA.50806@viscovery.net","threadId":"12922","inReplyTo":"1206947655-20272-2-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-03-31T08:03:54Z","receivedAt":"2008-03-31T08:03:54Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Johannes Sixt schrieb:\n> Commit d89c1dfac939623a269f60d4e27e3a2929dca29c replaced a\n> 'ls-files | xargs rm' pipeline by 'git clean'. But since 'git clean' does\n\ns/since//\n\n> not recurse and remove directories by default. Now, consider a tree-filter\n> that renames a directory.\n\n-- Hannes\n"},{"id":"73422","messageId":"7v3aq7mgly.fsf@gitster.siamese.dyndns.org","threadId":"12922","inReplyTo":"1206947655-20272-2-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-03-31T08:40:09Z","receivedAt":"2008-03-31T08:40:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <johannes.sixt@telecom.at> writes:\n\n> 2. Then filter-branch checks out the files for the next commit. This\n>    leaves the new directory behind because there is no real \"branch\n>    switching\" involved that would notice that the directory can be\n>    removed.\n\nThanks.\n\nIt obviously is a correct fix to use \"clean -d\" here, but I strongly\nsuspect this awkwardness comes from the fact that there is no clear\ninvariant in this loop.\n\nFor example, if you make it the invariant that $T contains the tree that\nmatches the contents of the \"$tempdir/t\" work tree left in the previous\nround of filter-tree (and obviously you would want to do this only\nfilter_tree is in effect), the \"checkout-index + clean\" would become a\nproper \"branch switching\".\n\nThis is obviously untested, and you would need to prime $T with an empty\ntree before entering the loop (but you could cheat by initializing T with\nan empty string), but it might make the code a bit more readable than the\ncurrent mess.  I dunno.\n\n\tif [ \"$filter_tree\" ]; then\n-\t\tgit checkout-index -f -u -a ||\n-\t\t\tdie \"Could not checkout the index\"\n-\t\t# files that $commit removed are now still in the working tree;\n-\t\t# remove them, else they would be added again\n-\t\tgit clean -d -q -f -x\n+\t\tgit read-tree -m -u $T $commit\n\t\teval \"$filter_tree\" < /dev/null ||\n\t\t\tdie \"tree filter failed: $filter_tree\"\n\n-\t\t(\n-\t\t\tgit diff-index -r --name-only $commit\n-\t\t\tgit ls-files --others\n-\t\t) |\n-\t\tgit update-index --add --replace --remove --stdin\n+\t\tgit add -u && git add . && T=$(git write-tree)\n\tfi\n"},{"id":"73424","messageId":"47F0A523.80906@viscovery.net","threadId":"12922","inReplyTo":"7v3aq7mgly.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2008-03-31T08:47:31Z","receivedAt":"2008-03-31T08:47:31Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Junio C Hamano schrieb:\n> For example, if you make it the invariant that $T contains the tree that\n> matches the contents of the \"$tempdir/t\" work tree left in the previous\n> round of filter-tree (and obviously you would want to do this only\n> filter_tree is in effect), the \"checkout-index + clean\" would become a\n> proper \"branch switching\".\n> \n> This is obviously untested, and you would need to prime $T with an empty\n> tree before entering the loop (but you could cheat by initializing T with\n> an empty string), but it might make the code a bit more readable than the\n> current mess.  I dunno.\n> \n> \tif [ \"$filter_tree\" ]; then\n> -\t\tgit checkout-index -f -u -a ||\n> -\t\t\tdie \"Could not checkout the index\"\n> -\t\t# files that $commit removed are now still in the working tree;\n> -\t\t# remove them, else they would be added again\n> -\t\tgit clean -d -q -f -x\n> +\t\tgit read-tree -m -u $T $commit\n> \t\teval \"$filter_tree\" < /dev/null ||\n> \t\t\tdie \"tree filter failed: $filter_tree\"\n> \n> -\t\t(\n> -\t\t\tgit diff-index -r --name-only $commit\n> -\t\t\tgit ls-files --others\n> -\t\t) |\n> -\t\tgit update-index --add --replace --remove --stdin\n> +\t\tgit add -u && git add . && T=$(git write-tree)\n> \tfi\n\nYes. But, ... uhm ..., I'm not that deep into these plumbings; I leave it\nto Dscho to comment on this.\n\n-- Hannes\n"},{"id":"73433","messageId":"6E006B1A-80DC-46DB-AA52-8A70C734C06E@yahoo.ca","threadId":"12922","inReplyTo":"1206947655-20272-2-git-send-email-johannes.sixt@telecom.at","subject":"Re: [PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Jean-François Veillette","fromEmail":"jean_francois_veillette@yahoo.ca","sentAt":"2008-03-31T11:25:06Z","receivedAt":"2008-03-31T11:25:06Z","isPatch":true,"sender":{"key":"jean_francois_veillette@yahoo.ca","avatar":null},"body":"> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>\n> ---\n>  Jean-Francois, there's no sign-off from you. Ok to add it?\n\nYes, just take the credit for yourself, I didn't really know what I  \nwas doing.\n\n- jfv\n"},{"id":"73435","messageId":"alpine.LSU.1.00.0803311412090.18259@racer.site","threadId":"12922","inReplyTo":"7v3aq7mgly.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] filter-branch: Fix renaming a directory in the tree-filter","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-03-31T12:15:51Z","receivedAt":"2008-03-31T12:15:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 31 Mar 2008, Junio C Hamano wrote:\n\n> Johannes Sixt <johannes.sixt@telecom.at> writes:\n> \n> > 2. Then filter-branch checks out the files for the next commit. This \n> >    leaves the new directory behind because there is no real \"branch \n> >    switching\" involved that would notice that the directory can be \n> >    removed.\n> \n> Thanks.\n> \n> It obviously is a correct fix to use \"clean -d\" here, but I strongly \n> suspect this awkwardness comes from the fact that there is no clear \n> invariant in this loop.\n> \n> For example, if you make it the invariant that $T contains the tree that \n> matches the contents of the \"$tempdir/t\" work tree left in the previous \n> round of filter-tree (and obviously you would want to do this only \n> filter_tree is in effect), the \"checkout-index + clean\" would become a \n> proper \"branch switching\".\n>\n> This is obviously untested, and you would need to prime $T with an empty \n> tree before entering the loop (but you could cheat by initializing T \n> with an empty string), but it might make the code a bit more readable \n> than the current mess.  I dunno.\n\nYes, I'd prefer this.\n\nOriginally, I wanted to clean up filter-branch a little, but then somebody \nworked on a builtin version of it, which unfortunately came in after the \ncode freeze, and I always waited for that thing to be picked up and \nenhanced.  (AFAIR there were quite a few issues which made rewrite-commits \nmuch less useful than it should be.)\n\nCiao,\nDscho\n"}]}