Advertisement
orgads

Generate git version

Jun 12th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.66 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Input: version.h.in that includes $VERSION
  4. # Output: version.h
  5.  
  6. version_file='path/to/version.h'
  7.  
  8. # Useful for e.g. Jenkins builds. Pass "b$BUILD_INFO" as an argument...
  9. while [ $# != 0 ] ; do
  10.   ver="$ver-$1"
  11.   shift
  12. done
  13.  
  14. ver=$(git describe --tags)
  15. stash_hash=$(git stash create)
  16. if [ -n "$stash_hash" ]; then
  17.   ver=$(echo "$ver" | sed "s/-g[^-]*$/-s${stash_hash:0:7}/")
  18. fi
  19.  
  20. echo Using version: $ver
  21.  
  22. sed "s/\$VERSION/$ver/g" "$version_file.in" > "$version_file.tmp"
  23. if [ ! -f "$version_file" ] || ! diff -q "$version_file.tmp" "$version_file" &> /dev/null; then
  24.   mv "$version_file.tmp" "$version_file"
  25. else
  26.   rm -f "$version_file.tmp"
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement