Repository: JuliaLang/julia
File: base/version_git.sh (Shell)

Code before:
    origin="origin/"
fi
git_time=$(git log -1 --pretty=format:%ct)

#collect the contents
commit=$(git rev-parse HEAD)
commit_short=$(git rev-parse --short HEAD)
if [ -n "$(git status --porcelain)" ]; then
    # append dirty mark '*' if the repository has uncommitted changes
    commit_short="$commit_short"*
fi

# Our CI system checks commits out as a detached head, and so we must
# use the provided branch name, as we cannot autodetect this commit as
# the tip of any such branch.
if [ -n "${BUILDKITE_BRANCH}" ]; then
    branch="${BUILDKITE_BRANCH}"
else
    branch=$(git rev-parse --abbrev-ref HEAD)
fi

topdir=$(git rev-parse --show-toplevel)
verchanged=$(git blame -L ,1 -sl -- "$topdir/VERSION" | cut -f 1 -d " ")
if [ $verchanged = 0000000000000000000000000000000000000000 ]; then
    # uncommitted change to VERSION
    build_number=0
else
    build_number=$(git rev-list --count HEAD "^$verchanged")
fi

case $(uname) in
  Darwin | FreeBSD)
    if (date --version 2>/dev/null | grep -q 'GNU coreutils')
    then # GNU date installed and earlier on PATH than BSD date
        date_string="$(date --date="@$git_time" -u '+%Y-%m-%d %H:%M %Z')"
    else # otherwise assume BSD date
        date_string="$(date -jr $git_time -u '+%Y-%m-%d %H:%M %Z')"
    fi
    ;;
  MINGW*)
    git_time=$(git log -1 --pretty=format:%ci)
    date_string="$(date --date="$git_time" -u '+%Y-%m-%d %H:%M %Z')"
    ;;
  *)
    date_string="$(date --date="@$git_time" -u '+%Y-%m-%d %H:%M %Z')"
    ;;
esac
if [ $(git describe --tags --exact-match 2> /dev/null) ]; then
    tagged_commit="true"
else
    tagged_commit="false"

Review comment (bug):
Could we instead change this to `git status --porcelain ${COMPILER_SRCS} ${BASE_SRCS} ${STDLIB_SRCS}` (these variables are defined during sysimage.mk), which seems like it should have the equivalent effect, but without the awkward build stickiness of this current implementation just failing to track a particular changed file, and now just generally does not correctly report whether the build was dirty (or not) when the sysimage was built?

Code after:
echo "    else"
echo "        return getfield(info, s)"
echo "    end"
echo "end"
echo ""

cd $1

# If the script didn't ask not to use git info
if [  "$#" = "2"  -a "$2" = "NO_GIT" ]; then
    # this comment is used in base/Makefile to distinguish boilerplate
    echo "# Default output if git is not available."
    echo 'const GIT_VERSION_INFO = GitVersionInfo("", "", "", 0, "", true, 0, 0.0, "", "")'
    exit 0
fi
# Collect temporary variables
origin=$(git config -l 2>/dev/null | grep 'remote\.\w*\.url.*JuliaLang/julia' | sed -n 's/remote\.\([a-zA-Z]*\)\..*/\1\//p')
if [ -z "$origin" ]; then
    origin="origin/"
fi
git_time=$(git log -1 --pretty=format:%ct)

#collect the contents
commit=$(git rev-parse HEAD)
commit_short=$(git rev-parse --short HEAD)
if [ -n "$(git status --porcelain)" ]; then
    dirty="true"
else
    dirty="false"
fi

# Our CI system checks commits out as a detached head, and so we must
# use the provided branch name, as we cannot autodetect this commit as
# the tip of any such branch.
if [ -n "${BUILDKITE_BRANCH}" ]; then
    branch="${BUILDKITE_BRANCH}"
else
    branch=$(git rev-parse --abbrev-ref HEAD)
fi

topdir=$(git rev-parse --show-toplevel)
verchanged=$(git blame -L ,1 -sl -- "$topdir/VERSION" | cut -f 1 -d " ")
if [ $verchanged = 0000000000000000000000000000000000000000 ]; then
    # uncommitted change to VERSION
    build_number=0
else
    build_number=$(git rev-list --count HEAD "^$verchanged")
fi

case $(uname) in
  Darwin | FreeBSD)