Skip to content

Commit

Permalink
git-version.sh: add support for shallow clones
Browse files Browse the repository at this point in the history
In shallow clones, `git describe` cannot help us (as we have no tags to
describe the version). Therefore, we fall back to `git diff` (with
`--quiet`) to check if the working directory is clean.

github actions use a shallow clone by default, so `git-version.sh` used
to incorreclty report `-dirty` there.
  • Loading branch information
hcmh committed Feb 27, 2024
1 parent 1653491 commit 429cda1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions git-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

if test -d ${GIT_DIR:-.git} -o -f .git
then
git describe --abbrev=7 --match "v*" --dirty
GDOUT=`git describe --abbrev=7 --match "v*" --dirty 2>&1`
if [[ $? -eq 0 ]]; then
echo ${GDOUT}
git describe --abbrev=7 --match "v*" | cut -f1 -d'-' > version.txt
else
var=`cat version.txt`
echo ${var}-dirty
if git diff --quiet --exit-code
then
cat version.txt
else
var=`cat version.txt`
echo ${var}-dirty
fi
fi
else
cat version.txt
Expand Down

0 comments on commit 429cda1

Please sign in to comment.