{"thread":{"id":"32856","subject":"git filter-branch --prune-empty not removing commits","startedAt":"2013-02-08T15:23:42Z","lastAt":"2013-02-08T16:53:24Z","messageCount":2,"participants":["Martijn van Oosterhout"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"208995","messageId":"CADWG95sHx6Z2Ukon8FAHKa1qUOj4shd4MbCwahwX++FVWJPDDg@mail.gmail.com","threadId":"32856","inReplyTo":null,"subject":"git filter-branch --prune-empty not removing commits","fromName":"Martijn van Oosterhout","fromEmail":"kleptog@gmail.com","sentAt":"2013-02-08T15:23:42Z","receivedAt":"2013-02-08T15:23:42Z","isPatch":false,"sender":{"key":"kleptog@gmail.com","avatar":null},"body":"Hoi,\n\nFound a small issue with git filter-branch not removing empty commits\nif they are the first commit in the tree. Find test script attached\nand example output below.\n\nI think the issue is in the function git_commit_non_empty_tree, which\ndoesn't handle this case. I think something like the following should\nwork:\n\n git_commit_non_empty_tree()\n {\n+        if test $# = 1 && test -z \"$(git ls-tree $1)\" ; then\n+                skip_commit \"$@\"\n+        fi\n         if test $# = 3 && test \"$1\" = $(git rev-parse \"$3^{tree}\"); then\n                 map \"$3\"\n         else\n                 git commit-tree \"$@\"\n         fi\n }\n\nIf you're wondering how I got here, it was by using git svn to import\na tree once converted by cvs2svn, which added empty commits to the svn\nrepo to indicate the creation of branches.\n\nHave a nice day,\n\n---- Test script output (note: destroys the foo subdirectory) ----\n+ git version\ngit version 1.7.9.5\n+ echo ======== Setup ========\n+ git init foo\nInitialized empty Git repository in /tmp/foo/.git/\n+ export GIT_AUTHOR_NAME=foo\n+ export GIT_AUTHOR_EMAIL=foo@example.com\n+ export GIT_COMMITTER_NAME=foo\n+ export GIT_COMMITTER_EMAIL=foo@example.com\n+ cd foo\n+ git write-tree\n+ git commit-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -m Commit 1\n+ COMMIT1=1dc65b84c016320ce0599f2bd78bcbb5e532658f\n+ export GIT_AUTHOR_NAME=bar\n+ export GIT_AUTHOR_EMAIL=bar@example.com\n+ echo Hello World\n+ git add file\n+ git write-tree\n+ git commit-tree 34b512cb05f8b709198d18d916ea6395c237ae0d -m Commit 2\n-p 1dc65b84c016320ce0599f2bd78bcbb5e532658f\n+ COMMIT2=11af492decae1284cd2d27af4c5a92b4aab46510\n+ git branch -f master 11af492decae1284cd2d27af4c5a92b4aab46510\n+ git log master --stat\ncommit 11af492decae1284cd2d27af4c5a92b4aab46510\nAuthor: bar <bar@example.com>\nDate:   Fri Feb 8 16:12:13 2013 +0100\n\n    Commit 2\n\n file |    1 +\n 1 file changed, 1 insertion(+)\n\ncommit 1dc65b84c016320ce0599f2bd78bcbb5e532658f\nAuthor: foo <foo@example.com>\nDate:   Fri Feb 8 16:12:13 2013 +0100\n\n    Commit 1\n+ echo ======== Bug: filter-branch --prune-empty not working ========\n+ git filter-branch --prune-empty master\nRewrite 11af492decae1284cd2d27af4c5a92b4aab46510 (2/2)\nWARNING: Ref 'refs/heads/master' is unchanged\n+ git log master --stat\ncommit 11af492decae1284cd2d27af4c5a92b4aab46510\nAuthor: bar <bar@example.com>\nDate:   Fri Feb 8 16:12:13 2013 +0100\n\n    Commit 2\n\n file |    1 +\n 1 file changed, 1 insertion(+)\n\ncommit 1dc65b84c016320ce0599f2bd78bcbb5e532658f\nAuthor: foo <foo@example.com>\nDate:   Fri Feb 8 16:12:13 2013 +0100\n\n    Commit 1\n\n-- \nMartijn van Oosterhout <kleptog@gmail.com> http://svana.org/kleptog/\n"},{"id":"209000","messageId":"CADWG95skLryj0gxSzmxviP1E=9T8oN0r64gpu3_7P6qMZkDq_g@mail.gmail.com","threadId":"32856","inReplyTo":"CADWG95sHx6Z2Ukon8FAHKa1qUOj4shd4MbCwahwX++FVWJPDDg@mail.gmail.com","subject":"Re: git filter-branch --prune-empty not removing commits","fromName":"Martijn van Oosterhout","fromEmail":"kleptog@gmail.com","sentAt":"2013-02-08T16:53:24Z","receivedAt":"2013-02-08T16:53:24Z","isPatch":false,"sender":{"key":"kleptog@gmail.com","avatar":null},"body":"On 8 February 2013 16:23, Martijn van Oosterhout <kleptog@gmail.com> wrote:\n>  git_commit_non_empty_tree()\n>  {\n> +        if test $# = 1 && test -z \"$(git ls-tree $1)\" ; then\n> +                skip_commit \"$@\"\n> +        fi\n>          if test $# = 3 && test \"$1\" = $(git rev-parse \"$3^{tree}\"); then\n>                  map \"$3\"\n>          else\n>                  git commit-tree \"$@\"\n>          fi\n>  }\n\nThis bit is a but bunk, the fi should be an else, otherwise it does nothing.\n\nHave a nice day,\n-- \nMartijn van Oosterhout <kleptog@gmail.com> http://svana.org/kleptog/\n"}]}