Skip to content

Commit

Permalink
Fail gitinfo2.sh gracefully out of git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Apr 28, 2017
1 parent 0261558 commit f535681
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions gitinfo2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,19 @@ set -o errtrace # trace ERR through 'time command' and other functions
set -o nounset # set -u : exit the script if you try to use an uninitialized variable
set -o errexit # set -e : exit the script if any statement returns a non-true return value

# Check that we're in a git repo, or bail out
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || exit 0
function die() {
status="$1"; shift
echo "$0: ${*:-Error extracting version info}" >&2
exit "$status"
}

function silently() {
"$@" > /dev/null 2>&1
}

# Check that we're in a git repo with a proper HEAD commit, or bail out
silently git rev-parse --is-inside-work-tree || die 0 "Not in a git repo"
silently git rev-parse --verify HEAD || die 0 "No parent commit available"

# Get the first tag found in the history from the current HEAD
FIRSTTAG=$(git describe --tags --always --dirty='-*' 2>/dev/null)
Expand Down

0 comments on commit f535681

Please sign in to comment.