]> git.ipfire.org Git - thirdparty/git.git/commit - git-filter-branch.sh
filter-branch: Fix fatal error on bare repositories
authorEric Kidd <git@randomhacks.net>
Tue, 3 Feb 2009 18:27:03 +0000 (13:27 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Feb 2009 05:54:02 +0000 (21:54 -0800)
commit9273b56278e64dd47b1a96a705ddf46aeaf6afe3
tree38456640aff7b731721603219362a9516bd94248
parent281907574ca420cc9a800190509adbf89bf9a2d1
filter-branch: Fix fatal error on bare repositories

When git filter-branch is run on a bare repository, it prints out a fatal
error message:

  $ git filter-branch branch
  Rewrite 476c4839280c219c2317376b661d9d95c1727fc3 (9/9)
  WARNING: Ref 'refs/heads/branch' is unchanged
  fatal: This operation must be run in a work tree

Note that this fatal error message doesn't prevent git filter-branch from
exiting successfully. (Why doesn't git filter-branch actually exit with an
error when a shell command fails? I'm not sure why it was designed this
way.)

This error message is caused by the following section of code at the end of
git-filter-branch.sh:

  if [ "$(is_bare_repository)" = false ]; then
          unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
          test -z "$ORIG_GIT_DIR" || {
                  GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
          }
          ... elided ...
          git read-tree -u -m HEAD
  fi

The problem is the call to $(is_bare_repository), which is made before
GIT_DIR and GIT_WORK_TREE are restored.  This call always returns "false",
even when we're running in a bare repository.  But this means that we will
attempt to call 'git read-tree' even in a bare repository, which will fail
and print an error.

This patch modifies git-filter-branch.sh to restore the original
environment variables before trying to call is_bare_repository.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-filter-branch.sh
t/t7003-filter-branch.sh