filter-branch: fix variable export logic
authorJeff King <peff@peff.net>
Tue, 13 May 2008 08:46:38 +0000 (04:46 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 14 May 2008 04:45:28 +0000 (21:45 -0700)
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>
No differences found