Fix broken support for bare repositories

The change in 6cf9397bd6 broke support for
bare repositories. In a bare repo git rev-parse --show-toplevel would
return an empty string and cwd would then be changed to the user's home
directory. In the home directory git rev-parse --git-dir would either
fail or return an unrelated repo.

Problem reported by Ralf Rösch.
This commit is contained in:
Frej Drejhammar
2016-10-01 14:45:48 +02:00
parent 6cf9397bd6
commit 1d0f6cb7ca
2 changed files with 16 additions and 4 deletions

View File

@@ -49,9 +49,15 @@ case "$1" in
exit 0
esac
cd $(git rev-parse --show-toplevel) \
IS_BARE=$(git rev-parse --is-bare-repository) \
|| (echo "Could not find git repo" ; exit 1)
GIT_DIR=$(git rev-parse --git-dir) || exit 1
if test "z$IS_BARE" != ztrue; then
# This is not a bare repo, cd to the toplevel
TOPLEVEL=$(git rev-parse --show-toplevel) \
|| (echo "Could not find git repo toplevel" ; exit 1)
cd $TOPLEVEL || exit 1
fi
GIT_DIR=$(git rev-parse --git-dir) || (echo "Could not find git repo" ; exit 1)
while case "$#" in 0) break ;; esac
do

View File

@@ -24,9 +24,15 @@ Options:
-r Mercurial repository to use
"
cd $(git rev-parse --show-toplevel) \
IS_BARE=$(git rev-parse --is-bare-repository) \
|| (echo "Could not find git repo" ; exit 1)
GIT_DIR=$(git rev-parse --git-dir) || exit 1
if test "z$IS_BARE" != ztrue; then
# This is not a bare repo, cd to the toplevel
TOPLEVEL=$(git rev-parse --show-toplevel) \
|| (echo "Could not find git repo toplevel" ; exit 1)
cd $TOPLEVEL || exit 1
fi
GIT_DIR=$(git rev-parse --git-dir) || (echo "Could not find git repo" ; exit 1)
while case "$#" in 0) break ;; esac
do