summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2008-05-13 04:46:38 -0400
committerJunio C Hamano <gitster@pobox.com>2008-05-13 21:45:28 -0700
commit0bdf93cbf0afd568384f237378ba368e751a2f0f (patch)
tree91ba78424da9ad1b1cb54fab05b521feb892a8e5
parent6d9878cc60ba97fc99aa92f40535644938cad907 (diff)
downloadgit-0bdf93cbf0afd568384f237378ba368e751a2f0f.tar.gz
filter-branch: fix variable export logic
filter-branch tries to restore "old" copies of some environment variables by using the construct: unset var test -z "$old_var" || var="$old_var" && export var This is just wrong. AND-list and OR-list operators && and || have equal precedence and they bind left to right. The second term, var="$old" assignment always succeeds, so we always end up exporting var. On bash and dash, exporting an unset variable has no effect. However, on some shells (such as FreeBSD's /bin/sh), the shell exports the empty value. This manifested itself in this case as git-filter-branch setting GIT_INDEX_FILE to the empty string, which in turn caused its call to git-read-tree to fail, leaving the working tree pointing at the original HEAD instead of the rewritten one. To fix this, we change the short-circuit logic to better match the intent: test -z "$old_var" || { var="$old_var" && export var } Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xgit-filter-branch.sh12
1 files changed, 9 insertions, 3 deletions
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 333f6a8f3b..80e99e5394 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -435,11 +435,17 @@ rm -rf "$tempdir"
trap - 0
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
-test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
-test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
+test -z "$ORIG_GIT_DIR" || {
+ GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
+}
+test -z "$ORIG_GIT_WORK_TREE" || {
+ GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
export GIT_WORK_TREE
-test -z "$ORIG_GIT_INDEX_FILE" || GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
+}
+test -z "$ORIG_GIT_INDEX_FILE" || {
+ GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
export GIT_INDEX_FILE
+}
git read-tree -u -m HEAD
exit $ret