From 1d0f6cb7caa74247ab9d520f3c021b7d6ea88bf2 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Sat, 1 Oct 2016 14:45:48 +0200 Subject: [PATCH] Fix broken support for bare repositories MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The change in 6cf9397bd6aadf659efb5104af4d3f37b0753d73 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. --- hg-fast-export.sh | 10 ++++++++-- hg-reset.sh | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hg-fast-export.sh b/hg-fast-export.sh index f3f58f6..d0dd506 100755 --- a/hg-fast-export.sh +++ b/hg-fast-export.sh @@ -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 diff --git a/hg-reset.sh b/hg-reset.sh index d7fbff7..453dbab 100755 --- a/hg-reset.sh +++ b/hg-reset.sh @@ -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 -- 2.11.4.GIT