From: Junio C Hamano Date: Wed, 29 Aug 2012 21:49:45 +0000 (-0700) Subject: Merge branch 'jc/maint-protect-sh-from-ifs' X-Git-Tag: v1.8.0-rc0~124 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/72c4dbec2c782fd1f25694352c611374b3e56fe8?hp=-c Merge branch 'jc/maint-protect-sh-from-ifs' When the user exports a non-default IFS without HT, scripts that rely on being able to parse "ls-files -s | while read a b c..." start to fail. Protect them from such a misconfiguration. * jc/maint-protect-sh-from-ifs: sh-setup: protect from exported IFS --- 72c4dbec2c782fd1f25694352c611374b3e56fe8 diff --combined git-sh-setup.sh index 770a86e2b7,69472e4125..ee0e0bc045 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@@ -9,8 -9,12 +9,12 @@@ # you would cause "cd" to be taken to unexpected places. If you # like CDPATH, define it for your interactive shell sessions without # exporting it. + # But we protect ourselves from such a user mistake nevertheless. unset CDPATH + # Similarly for IFS + unset IFS + git_broken_path_fix () { case ":$PATH:" in *:$1:*) : ok ;; @@@ -218,8 -222,27 +222,8 @@@ clear_local_git_env() unset $(git rev-parse --local-env-vars) } -# Make sure we are in a valid repository of a vintage we understand, -# if we require to be in a git repository. -if test -z "$NONGIT_OK" -then - GIT_DIR=$(git rev-parse --git-dir) || exit - if [ -z "$SUBDIRECTORY_OK" ] - then - test -z "$(git rev-parse --show-cdup)" || { - exit=$? - echo >&2 "You need to run this command from the toplevel of the working tree." - exit $exit - } - fi - test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || { - echo >&2 "Unable to determine absolute path of git directory" - exit 1 - } - : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} -fi -# Fix some commands on Windows +# Platform specific tweaks to work around some commands case $(uname -s) in *MINGW*) # Windows has its own (incompatible) sort and find @@@ -229,10 -252,6 +233,10 @@@ find () { /usr/bin/find "$@" } + # git sees Windows-style pwd + pwd () { + builtin pwd -W + } is_absolute_path () { case "$1" in [/\\]* | [A-Za-z]:*) @@@ -250,23 -269,3 +254,23 @@@ return 1 } esac + +# Make sure we are in a valid repository of a vintage we understand, +# if we require to be in a git repository. +if test -z "$NONGIT_OK" +then + GIT_DIR=$(git rev-parse --git-dir) || exit + if [ -z "$SUBDIRECTORY_OK" ] + then + test -z "$(git rev-parse --show-cdup)" || { + exit=$? + echo >&2 "You need to run this command from the toplevel of the working tree." + exit $exit + } + fi + test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || { + echo >&2 "Unable to determine absolute path of git directory" + exit 1 + } + : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} +fi