filter-branch: always export GIT_DIR if it is set
[git/git.git] / git-filter-branch.sh
old mode 100755 (executable)
new mode 100644 (file)
index 29e0d02..614f7bd
@@ -184,7 +184,8 @@ USAGE="git-filter-branch [-d TEMPDIR] [FILTERS] DESTBRANCH [REV-RANGE]"
 
 map()
 {
-       [ -r "$workdir/../map/$1" ] || return 1
+       # if it was not rewritten, take the original
+       test -r "$workdir/../map/$1" || echo "$1"
        cat "$workdir/../map/$1"
 }
 
@@ -300,9 +301,10 @@ case "$GIT_DIR" in
 /*)
        ;;
 *)
-       export GIT_DIR="$(pwd)/../../$GIT_DIR"
+       GIT_DIR="$(pwd)/../../$GIT_DIR"
        ;;
 esac
+export GIT_DIR GIT_WORK_TREE=.
 
 export GIT_INDEX_FILE="$(pwd)/../index"
 git-read-tree # seed the index file
@@ -347,14 +349,9 @@ while read commit; do
 
        parentstr=
        for parent in $(get_parents $commit); do
-               if [ -r "../map/$parent" ]; then
-                       for reparent in $(cat "../map/$parent"); do
-                               parentstr="$parentstr -p $reparent"
-                       done
-               else
-                       # if it was not rewritten, take the original
-                       parentstr="$parentstr -p $parent"
-               fi
+               for reparent in $(map "$parent"); do
+                       parentstr="$parentstr -p $reparent"
+               done
        done
        if [ "$filter_parent" ]; then
                parentstr="$(echo "$parentstr" | eval "$filter_parent")"