123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #!/bin/bash
-
-
-
- mkit_import ini
-
- git_bool() {
-
-
-
- local bool_name=$1
- git_present || warn "can't give bool outside git repo: $bool_name"
- case "$bool_name" in
- dirty_files)
- git diff-files | grep -qm 1 .
- ;;
- dirty_index)
- git diff-index HEAD | grep -qm 1 .
- ;;
- dirty)
- git_bool dirty_files || git_bool dirty_index
- ;;
- *)
- warn "unknown git bool asked: $bool_name"
- return 2
- ;;
- esac
- }
-
- git_fact() {
-
-
-
- local fact_name=$1
- git_present || warn "can't give fact outside git repo: $fact_name"
- case "$fact_name" in
- latest_tag)
- git log --format="%d" \
- | sed 's/,/\n/g' \
- | sed 's/^[[:blank:]]*//' \
- | grep -E '^\(?tag' \
- | tr -cd '[[:digit:]].v\n' \
- | grep . -m 1
- ;;
- latest_version)
- git_fact latest_tag | git_tag2ver
- ;;
- current_branch)
- git rev-parse --abbrev-ref HEAD
- ;;
- reldiff)
- git log --oneline "$(git_fact latest_tag)..HEAD" --name-only
- ;;
- latest_sha)
- git log -1 --pretty=format:%h HEAD
- ;;
- *)
- warn "unknown git fact asked: $fact_name"
- ;;
- esac
- }
-
- git_present() {
-
-
-
- git rev-parse HEAD >&/dev/null
- }
-
- git_tag2ver() {
-
-
-
- sed s/^v//
- }
-
- git_ver2tag() {
-
-
-
- sed s/^/v/
- }
-
- git_lasthash() {
-
-
-
-
-
-
-
- local last_hash
- git_present || {
- echo UNKNOWN_HASH
- warn "no git present; could not determine last hash"
- return 3
- }
- last_hash=$(git rev-parse HEAD)
- echo -n "$last_hash"
- git_bool dirty && echo -n ".dirty"
- }
-
- semver() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- local xyz
- local prerl
- local latest_tag
- local commit
- local dirty=F
- local btime
- local suffix
- prerl=$(ini 1value project:prerl)
- case $MKIT_TTAG in
- none) btime= ;;
- btime) btime=$(printf '%08x' "$(date +%s)") ;;
- esac
- grep ":" <<<"$prerl" \
- && warn "colon in project:prerl may corrupt version data: $prerl"
- git_present || {
- echo UNKNOWN_VERSION
- warn "no git present; could not determine SemVer"
- return 3
- }
- latest_tag=$(git_fact latest_tag)
- case $latest_tag in
- v*) xyz=${latest_tag:1} ;;
- "") warn "no tags, using base version from mkit.ini (ok for new project)"
- xyz=$(ini 1value project:version) ;;
- *) warn "bad form of last tag, using base version from mkit.ini: tag is '$latest_tag'"
- xyz=$(ini 1value project:version) ;;
- esac
- if ! git describe --tags --exact-match HEAD >&/dev/null;
- then
- commit="$(git_fact current_branch).g$(git_fact latest_sha)"
- fi
- git_bool dirty && dirty=T
- case "$dirty:$btime:$commit" in
- F:*:) suffix="" ;;
- T::) suffix="+dirty" ;;
- T:*:) suffix="+t$btime.dirty" ;;
- F::*) suffix="+$commit" ;;
- F:*:*) suffix="+t$btime.$commit" ;;
- T::*) suffix="+$commit.dirty" ;;
- T:*:*) suffix="+t$btime.$commit.dirty" ;;
- *) suffix=MKIT_BUG
- warn "MKIT_BUG: bad dirt/commit detection" ;;
- esac
- test -n "$prerl" && suffix="-$prerl$suffix"
- echo "$xyz$suffix"
- }
|