File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -17,16 +17,14 @@ set -euo pipefail
17
17
18
18
function chaosd::version::get_version_vars() {
19
19
if [[ -n ${GIT_COMMIT-} ]] || GIT_COMMIT=$( git rev-parse " HEAD^{commit}" 2> /dev/null) ; then
20
-
21
20
# Use git describe to find the version based on tags.
22
- if [[ -n ${GIT_VERSION-} ]] || GIT_VERSION=$( git describe --tags --abbrev=14 " ${GIT_COMMIT} ^{commit}" 2> /dev/null) ; then
23
- DASHES_IN_VERSION=$( echo " ${GIT_VERSION} " | sed " s/[^-]//g" )
24
- if [[ " ${DASHES_IN_VERSION} " == " ---" ]] ; then
25
- # We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
26
- GIT_VERSION=$( echo " ${GIT_VERSION} " | sed " s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\+\2/" )
27
- elif [[ " ${DASHES_IN_VERSION} " == " --" ]] ; then
28
- # We have distance to base tag (v1.1.0-1-gCommitHash)
29
- GIT_VERSION=$( echo " ${GIT_VERSION} " | sed " s/-g\([0-9a-f]\{14\}\)$/+\1/" )
21
+ # --always would show the unique abbr commit as fallback.
22
+ if [[ -n ${GIT_VERSION-} ]] || GIT_VERSION=$( git describe --always --tags --abbrev=14 " ${GIT_COMMIT} ^{commit}" 2> /dev/null) ; then
23
+ # if current commit is not on a certain tag
24
+ if ! git describe --tags --exact-match > /dev/null 2>&1 ; then
25
+ # GIT_VERSION=gitBranch-gitCommitHash
26
+ IFS=' -' read -ra GIT_ARRAY <<< " $GIT_VERSION"
27
+ GIT_VERSION=$( git rev-parse --abbrev-ref HEAD) -${GIT_ARRAY[${#GIT_ARRAY[@]} -1]}
30
28
fi
31
29
fi
32
30
fi
You can’t perform that action at this time.
0 commit comments