@matheusbsbs / matheus-bagliano / commits / 88e38808cd
Fork 0

filter-branch -d: Export GIT_DIR earlier

The improved error handling catches a bug in filter-branch when using -d pointing to a path outside any git repository: $ git filter-branch -d /tmp/foo master fatal: Not a git repository (or any of the parent directories): .git This error message comes from git for-each-ref in line 224. GIT_DIR is set correctly by git-sh-setup (to the foo.git repository), but not exported (yet). Signed-off-by: Lars Noschinski <lars@public.noschinski.de> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Noschinski committed Feb 18, 2009 at 09:35 UTC 88e38808cd52aaed327a82d6a6ffdb8b9da621f2
2 files changed +18 -6
git-filter-branch.sh
+6 -6
@@ -220,6 +220,12 @@ die ""
220 # Remove tempdir on exit
221 trap 'cd ../..; rm -rf "$tempdir"' 0
222
223 +ORIG_GIT_DIR="$GIT_DIR"
224 +ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
225 +ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE"
226 +GIT_WORK_TREE=.
227 +export GIT_DIR GIT_WORK_TREE
228 +
229 # Make sure refs/original is empty
230 git for-each-ref > "$tempdir"/backup-refs || exit
231 while read sha1 type name
@@ -234,12 +240,6 @@ do
240 esac
241 done < "$tempdir"/backup-refs
242
237 -ORIG_GIT_DIR="$GIT_DIR"
238 -ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
239 -ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE"
240 -GIT_WORK_TREE=.
241 -export GIT_DIR GIT_WORK_TREE
242 -
243 # The refs should be updated if their heads were rewritten
244 git rev-parse --no-flags --revs-only --symbolic-full-name \
245 --default HEAD "$@" > "$tempdir"/raw-heads || exit
t/t7003-filter-branch.sh
+12
@@ -48,6 +48,18 @@ test_expect_success 'result is really identical' '
48 test $H = $(git rev-parse HEAD)
49 '
50
51 +TRASHDIR=$(pwd)
52 +test_expect_success 'correct GIT_DIR while using -d' '
53 + mkdir drepo &&
54 + ( cd drepo &&
55 + git init &&
56 + test_commit drepo &&
57 + git filter-branch -d "$TRASHDIR/dfoo" \
58 + --index-filter "cp \"$TRASHDIR\"/dfoo/backup-refs \"$TRASHDIR\"" \
59 + ) &&
60 + grep drepo "$TRASHDIR/backup-refs"
61 +'
62 +
63 test_expect_success 'Fail if commit filter fails' '
64 test_must_fail git filter-branch -f --commit-filter "exit 1" HEAD
65 '