From 54c1f9fcb7384867addd3f9fe2c1bfec76764465 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Wed, 11 Jul 2018 15:14:58 +0100 Subject: [PATCH] better test for git working copy --- bin/cylc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/cylc b/bin/cylc index f85359355c5..acd7a011e5d 100755 --- a/bin/cylc +++ b/bin/cylc @@ -24,12 +24,14 @@ HELP_OPTS=('help' '--help' '-h' 'h' '?') get_version() { # If there is a version file present, use that if [[ -f "${CYLC_DIR}/VERSION" ]]; then - CYLC_VERSION="$(cat ${CYLC_DIR}/VERSION)" - # Otherwise, use git (if in a git repo) to determine version - elif [[ -d "${CYLC_DIR}/.git" ]]; then - CYLC_VERSION="$(cd ${CYLC_DIR} && git describe --abbrev=4 --always)" + CYLC_VERSION="$(cat "${CYLC_DIR}/VERSION")" + # Otherwise, use git (if in a git repo and not a bare clone) + # to determine version + elif git -C "${CYLC_DIR}" rev-parse && \ + [[ -n "$(git -C "${CYLC_DIR}" rev-parse --show-toplevel)" ]]; then + CYLC_VERSION="$(cd "${CYLC_DIR}" && git describe --abbrev=4 --always)" # Append "-dirty" if there are uncommitted changes. - if [[ -n "$(cd ${CYLC_DIR} && git status \ + if [[ -n "$(cd "${CYLC_DIR}" && git status \ --untracked-files=no --porcelain)" ]]; then CYLC_VERSION="${CYLC_VERSION}-dirty" fi