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.

125 lines
2.4KB

  1. #!/bin/bash
  2. set -o errexit -o pipefail -o noclobber -o nounset
  3. SCRIPT=$0
  4. # function for printing the usage information
  5. function usage()
  6. {
  7. echo "$SCRIPT <options>"
  8. echo -e "\t -h|--help print usage information"
  9. echo -e "\t -a|--all print all found git repositories not only ones with changes"
  10. echo -e "\t -p|--push push all committed changes to origin"
  11. }
  12. # ceck if getopt is available for us
  13. ! getopt --test > /dev/null
  14. if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
  15. echo "I’m sorry, `getopt --test` failed in this environment."
  16. exit 1
  17. fi
  18. # setup available command line options
  19. OPTIONS=ahp
  20. LONGOPTS=all,help,push
  21. # parse the command line
  22. ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
  23. if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
  24. usage
  25. exit 2
  26. fi
  27. eval set -- "$PARSED"
  28. h=n a=n p=n
  29. while true; do
  30. case "$1" in
  31. -a|--all)
  32. a=y
  33. shift
  34. ;;
  35. -h|--help)
  36. h=y
  37. shift
  38. ;;
  39. -p|--push)
  40. p=y
  41. shift
  42. ;;
  43. --)
  44. shift
  45. break
  46. ;;
  47. *)
  48. echo "Programming error"
  49. exit 3
  50. ;;
  51. esac
  52. done
  53. # just print usage information on -h | --help
  54. if [ $h == "y" ]; then
  55. usage
  56. exit 1
  57. fi
  58. DIR=`pwd`
  59. if [[ $# -eq 1 ]]; then
  60. DIR=$1
  61. fi
  62. REPOS=`find $DIR -name '.git'`
  63. for r in $REPOS; do
  64. # init
  65. modfiles=0
  66. untracked=0
  67. noorigin=0
  68. # remove .git from path
  69. repo=`echo $r | sed 's/.git$//'`
  70. #check for modified files
  71. if [ $(LANG=en_US.UTF-8 git -C $repo status | grep modified -c) -ne 0 ]; then
  72. modfiles=1
  73. fi
  74. if [ $(LANG=en_US.UTF-8 git -C $repo status | grep Deleted -c) -ne 0 ]; then
  75. modfiles=1
  76. fi
  77. #check for untracked files
  78. if [ $(LANG=en_US.UTF-8 git -C $repo status | grep Untracked -c) -ne 0 ]; then
  79. untracked=1
  80. fi
  81. #check for default origin
  82. if [ $(LANG=en_US.UTF-8 git -C $repo remote | grep origin -c) -ne 1 ]; then
  83. noorigin=1
  84. fi
  85. if [[ $modfiles -eq 1 || $untracked -eq 1 || $noorigin -eq 1 || $a == "y" ]]; then
  86. printf "%50s\t" $repo
  87. if [ $modfiles -eq 1 ]; then
  88. echo -n "modified files "
  89. fi
  90. if [ $untracked -eq 1 ]; then
  91. echo -n "untrackted files "
  92. fi
  93. if [ $noorigin -eq 1 ]; then
  94. echo -n "no origin given "
  95. fi
  96. echo
  97. #push repo if requested and origin given
  98. #if [[ $p='y' && $noorigin -eq 0 ]]; then
  99. #
  100. #fi
  101. fi
  102. done