You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

  1. #!/bin/sh
  2. set -e
  3. # Text color variables
  4. txtbld=$(tput bold) # Bold
  5. bldred=${txtbld}$(tput setaf 1) # red
  6. bldgre=${txtbld}$(tput setaf 2) # green
  7. bldylw=${txtbld}$(tput setaf 3) # yellow
  8. txtrst=$(tput sgr0) # Reset
  9. err=${bldred}ERROR${txtrst}
  10. info=${bldgre}INFO${txtrst}
  11. warn=${bldylw}WARNING${txtrst}
  12. usage()
  13. {
  14. cat << EOF
  15. Generates a file which contains useful git informations
  16. Usage : $(basename $0) [global|diff]
  17. ex :
  18. Generate git information
  19. $(basename $0) global
  20. Generate diff from latest tag
  21. $(basename $0) diff
  22. EOF
  23. }
  24. if [ $# != 1 ]; then
  25. printf "\n$err : Needs 1 argument\n"
  26. usage
  27. exit 2
  28. fi;
  29. current_commit=$(git rev-parse HEAD)
  30. latest_tag=$(git describe --abbrev=0 --tags)
  31. latest_tag_commit=$(git show-ref -s ${latest_tag})
  32. tags_list=$(git tag --points-at "${latest_tag}")
  33. case ${1} in
  34. "global")
  35. cat<<EOF
  36. deployment date="$(date '+%d-%m-%Y %Hh%M')"
  37. deployment_timestamp=$(date '+%s')
  38. user="$USER"
  39. current commit (HEAD)="${current_commit}"
  40. current_commit_timestamp=$(git log -1 --pretty=format:%ct)
  41. latest tag(s) (current branch)="${tags_list}"
  42. latest tag commit="${latest_tag_commit}"
  43. current branch="$(git rev-parse --abbrev-ref HEAD)"
  44. branches list="$(git describe --contains --all HEAD)"
  45. git root directory="$(git rev-parse --show-toplevel)"
  46. EOF
  47. if ! git diff-index --quiet HEAD --; then
  48. printf "unstaged changes=\"/etc/.git-ansible.diff\""
  49. fi
  50. if [ "${current_commit}" = "${latest_tag_commit}" ]; then
  51. printf "\ncurrent_commit_tag=\"${latest_tag}\""
  52. else
  53. printf "\nlast tag was "$(git describe --tags | awk -F- '{print $2}')" commits ago =\""
  54. printf "$(git log --pretty=format:" %h - %s" ${latest_tag}..HEAD)\""
  55. fi
  56. ;;
  57. "diff")
  58. git diff
  59. ;;
  60. *)
  61. usage
  62. printf "$err: Unknown argument ${1}"
  63. exit 1;
  64. ;;
  65. esac