Skip to content

Commit 429cda1

Browse files
committed
git-version.sh: add support for shallow clones
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.
1 parent 1653491 commit 429cda1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

git-version.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
if test -d ${GIT_DIR:-.git} -o -f .git
44
then
5-
git describe --abbrev=7 --match "v*" --dirty
5+
GDOUT=`git describe --abbrev=7 --match "v*" --dirty 2>&1`
66
if [[ $? -eq 0 ]]; then
7+
echo ${GDOUT}
78
git describe --abbrev=7 --match "v*" | cut -f1 -d'-' > version.txt
89
else
9-
var=`cat version.txt`
10-
echo ${var}-dirty
10+
if git diff --quiet --exit-code
11+
then
12+
cat version.txt
13+
else
14+
var=`cat version.txt`
15+
echo ${var}-dirty
16+
fi
1117
fi
1218
else
1319
cat version.txt

0 commit comments

Comments
 (0)