git_describe.sh 693 B

1234567891011121314151617
  1. #!/bin/bash
  2. if git rev-parse --git-dir 2>&1 >/dev/null; then
  3. gitversion=$(git describe --tags --long --match "$1*" --abbrev=7 || echo "0.0.0-dirty-0-g$(git describe --tags --match "$1*" --always --abbrev=7 2>/dev/null)")
  4. patch=$(sed -r -e 's/[0-9]+\.[0-9]+\.([0-9]+).*/\1/' <<< ${gitversion#$1})
  5. let patch+=1
  6. version=$(sed -r -e 's/-0-(g[0-9a-f]{7})//' <<< ${gitversion#$1})
  7. version=$(sed -r -e "s/\.[0-9]+-([0-9]+)-(g[0-9a-f]{7})/.${patch}-dev\1+\2/" <<< ${version})
  8. version=$(sed -r -e "s/-([0-9]+)-(g[0-9a-f]{7})/+p\1+\2/" <<< ${version})
  9. echo "Git version: '$version'" >&2
  10. echo $version
  11. else
  12. echo "No Git repository: '0.0.0-nogit'" >&2
  13. echo "0.0.0-nogit"
  14. fi
  15. exit 0