01_src-update.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. if [ -n "$2" ]; then
  3. cd "$2" # update given directory only
  4. else
  5. cd "$(dirname $0)"/../../mods_src
  6. fi
  7. VERBOSE="$1"
  8. GIT="git --no-pager"
  9. GITPARAM="--color=always"
  10. if [ "$VERBOSE" == "" ]; then
  11. VERBOSE=0
  12. fi
  13. # 0: just update relevant infos
  14. # 1 display "branch -vaa" + local changes
  15. # 2 display log on current branch
  16. # 3 display "remote -v"
  17. find . -name ".git" -type d | while read repo; do
  18. echo ''
  19. echo '--------------------------------------'
  20. echo "$(dirname "$repo")"
  21. echo '--------------------------------------'
  22. cd "$(dirname "$repo")"
  23. # fetch all connected remotes
  24. for repo in $(git remote); do
  25. $GIT fetch "$repo" --prune
  26. done
  27. # Display repo status in different verbosity
  28. if [ "$VERBOSE" -ge 1 ]; then
  29. $GIT branch -vva $GITPARAM
  30. fi
  31. # create log range
  32. currentbranch="$(git branch | grep '^*' | sed 's:\* ::g')"
  33. remotebranch="$(git branch -avv | grep '^\*' | sed 's@.*\[@@g;s@[]:].*@@g' | grep -v '^\*')"
  34. # print the log information
  35. if [ "$VERBOSE" -ge 2 ]; then
  36. if [ "$remotebranch" == "" ]; then
  37. echo '!!!!! No remote branch for' $currentbranch '!!!!!!'
  38. else
  39. echo $currentbranch '=>' "$remotebranch"
  40. $GIT log $currentbranch..$remotebranch
  41. fi
  42. if [ "$VERBOSE" -ge 3 ]; then
  43. $GIT remote -v
  44. fi
  45. fi
  46. # Now pull+merge
  47. # git pull. (from man git-pull: git pull is shorthand for git fetch followed by git merge FETCH_HEAD.)
  48. if [ ! "$remotebranch" == "" ]; then
  49. $GIT merge "$remotebranch"
  50. fi
  51. # display local changes
  52. if [ $VERBOSE -ge 1 ]; then
  53. $GIT diff $GITPARAM #display local changes
  54. fi
  55. echo "last commit: $(git log -1 --format=%cd)"
  56. cd - >/dev/null
  57. done
  58. #########################################
  59. # Find all ".hg" and pull them
  60. find . -name ".hg" -type d | while read repo; do
  61. echo "$(dirname "$repo")"
  62. cd "$(dirname "$repo")"
  63. hg pull
  64. cd - >/dev/null
  65. done