git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git filter-branch --prune-empty not removing commits
@ 2013-02-08 15:23 Martijn van Oosterhout
  2013-02-08 16:53 ` Martijn van Oosterhout
  0 siblings, 1 reply; 2+ messages in thread
From: Martijn van Oosterhout @ 2013-02-08 15:23 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 2627 bytes --]

Hoi,

Found a small issue with git filter-branch not removing empty commits
if they are the first commit in the tree. Find test script attached
and example output below.

I think the issue is in the function git_commit_non_empty_tree, which
doesn't handle this case. I think something like the following should
work:

 git_commit_non_empty_tree()
 {
+        if test $# = 1 && test -z "$(git ls-tree $1)" ; then
+                skip_commit "$@"
+        fi
         if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
                 map "$3"
         else
                 git commit-tree "$@"
         fi
 }

If you're wondering how I got here, it was by using git svn to import
a tree once converted by cvs2svn, which added empty commits to the svn
repo to indicate the creation of branches.

Have a nice day,

---- Test script output (note: destroys the foo subdirectory) ----
+ git version
git version 1.7.9.5
+ echo ======== Setup ========
+ git init foo
Initialized empty Git repository in /tmp/foo/.git/
+ export GIT_AUTHOR_NAME=foo
+ export GIT_AUTHOR_EMAIL=foo@example.com
+ export GIT_COMMITTER_NAME=foo
+ export GIT_COMMITTER_EMAIL=foo@example.com
+ cd foo
+ git write-tree
+ git commit-tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -m Commit 1
+ COMMIT1=1dc65b84c016320ce0599f2bd78bcbb5e532658f
+ export GIT_AUTHOR_NAME=bar
+ export GIT_AUTHOR_EMAIL=bar@example.com
+ echo Hello World
+ git add file
+ git write-tree
+ git commit-tree 34b512cb05f8b709198d18d916ea6395c237ae0d -m Commit 2
-p 1dc65b84c016320ce0599f2bd78bcbb5e532658f
+ COMMIT2=11af492decae1284cd2d27af4c5a92b4aab46510
+ git branch -f master 11af492decae1284cd2d27af4c5a92b4aab46510
+ git log master --stat
commit 11af492decae1284cd2d27af4c5a92b4aab46510
Author: bar <bar@example.com>
Date:   Fri Feb 8 16:12:13 2013 +0100

    Commit 2

 file |    1 +
 1 file changed, 1 insertion(+)

commit 1dc65b84c016320ce0599f2bd78bcbb5e532658f
Author: foo <foo@example.com>
Date:   Fri Feb 8 16:12:13 2013 +0100

    Commit 1
+ echo ======== Bug: filter-branch --prune-empty not working ========
+ git filter-branch --prune-empty master
Rewrite 11af492decae1284cd2d27af4c5a92b4aab46510 (2/2)
WARNING: Ref 'refs/heads/master' is unchanged
+ git log master --stat
commit 11af492decae1284cd2d27af4c5a92b4aab46510
Author: bar <bar@example.com>
Date:   Fri Feb 8 16:12:13 2013 +0100

    Commit 2

 file |    1 +
 1 file changed, 1 insertion(+)

commit 1dc65b84c016320ce0599f2bd78bcbb5e532658f
Author: foo <foo@example.com>
Date:   Fri Feb 8 16:12:13 2013 +0100

    Commit 1

-- 
Martijn van Oosterhout <kleptog@gmail.com> http://svana.org/kleptog/

[-- Attachment #2: test --]
[-- Type: application/octet-stream, Size: 671 bytes --]

#!/bin/sh -x

git version

echo "======== Setup ========"
git init foo

export GIT_AUTHOR_NAME="foo"
export GIT_AUTHOR_EMAIL="foo@example.com"
export GIT_COMMITTER_NAME=$GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL=$GIT_AUTHOR_EMAIL

cd foo

COMMIT1=$(git commit-tree $(git write-tree) -m "Commit 1")

export GIT_AUTHOR_NAME="bar"
export GIT_AUTHOR_EMAIL="bar@example.com"   

echo "Hello World" > file
git add file
COMMIT2=$(git commit-tree $(git write-tree) -m "Commit 2" -p $COMMIT1)

git branch -f master $COMMIT2
git log master --stat

echo "======== Bug: filter-branch --prune-empty not working ========"
git filter-branch --prune-empty master
git log master --stat


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git filter-branch --prune-empty not removing commits
  2013-02-08 15:23 git filter-branch --prune-empty not removing commits Martijn van Oosterhout
@ 2013-02-08 16:53 ` Martijn van Oosterhout
  0 siblings, 0 replies; 2+ messages in thread
From: Martijn van Oosterhout @ 2013-02-08 16:53 UTC (permalink / raw)
  To: git

On 8 February 2013 16:23, Martijn van Oosterhout <kleptog@gmail.com> wrote:
>  git_commit_non_empty_tree()
>  {
> +        if test $# = 1 && test -z "$(git ls-tree $1)" ; then
> +                skip_commit "$@"
> +        fi
>          if test $# = 3 && test "$1" = $(git rev-parse "$3^{tree}"); then
>                  map "$3"
>          else
>                  git commit-tree "$@"
>          fi
>  }

This bit is a but bunk, the fi should be an else, otherwise it does nothing.

Have a nice day,
-- 
Martijn van Oosterhout <kleptog@gmail.com> http://svana.org/kleptog/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-02-08 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-08 15:23 git filter-branch --prune-empty not removing commits Martijn van Oosterhout
2013-02-08 16:53 ` Martijn van Oosterhout

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).