-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use ansemjo/version.sh for version strings
- Loading branch information
Showing
5 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
setup.py export-subst | ||
makefile export-subst | ||
version.sh export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
archive/ | ||
__pycache__/ | ||
build/ | ||
dist/ | ||
pkg/ | ||
*.egg-info/ | ||
*.apk | ||
*.deb | ||
*.rpm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
|
||
# Copyright (c) 2018 Anton Semjonov | ||
# Licensed under the MIT License | ||
|
||
# add 'VERSION export-subst' in .gitattributes and | ||
# these strings will be substituted by git-archive | ||
COMMIT='$Format:%H$' | ||
REFS='$Format:%D$' | ||
|
||
# constants | ||
FALLBACK_VERSION='commit' | ||
FALLBACK_COMMIT='unknown' | ||
REVISION='.r' | ||
|
||
# check if variable contains a subst value or still has the format string | ||
hasval() { expr match "$1" '$Format' == 0 >/dev/null; } | ||
|
||
# parse the %D reflist to get tag or branch | ||
refparse() { REF="$1"; | ||
tag=$(echo "$REF" | sed -ne 's/.*tag: \([^,]*\).*/\1/p'); test -n "$tag" && echo "$tag" && return 0; | ||
branch=$(echo "$REF" | sed -e 's/HEAD -> //' -e 's/, /\ | ||
/' | sed -ne '/^[a-z0-9._-]*$/p' | sed -n '1p'); test -n "$branch" && echo "$branch" && return 0; | ||
return 1; } | ||
|
||
# git functions to return commit and version in repository | ||
hasgit() { test -d .git; } | ||
gitcommit() { hasgit && git describe --always --abbrev=0 --match '^$' --dirty; } | ||
gitversion() { hasgit \ | ||
&& { V=$(git describe 2>/dev/null) && echo "$V" | sed "s/-\([0-9]*\)-g.*/$REVISION\1/"; } \ | ||
|| { C=$(git rev-list --count HEAD) && printf '0.0.0%s%s' "$REVISION" "$C"; }; | ||
} | ||
|
||
# wrappers | ||
version() { hasval "$REFS" && refparse "$REFS" || gitversion || echo "$FALLBACK_VERSION"; } | ||
commit() { hasval "$COMMIT" && echo "$COMMIT" || gitcommit || echo "$FALLBACK_COMMIT"; } | ||
|
||
# --------------------------------- | ||
|
||
case "$1" in | ||
version) version ;; | ||
commit) commit ;; | ||
describe) | ||
printf '%s-g%.7s\n' "$(version)" "$(commit)" ;; | ||
help) | ||
printf '%s [version|commit|describe]\n' "$0" ;; | ||
*) | ||
printf 'version : %s\ncommit : %s\n' "$(version)" "$(commit)" ;; | ||
esac |