updateSubmodule.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash -eu
  2. # This script generates a commit that updates the lib/ve submodule
  3. # ./bin/updateSubmodule.sh updates to master
  4. # ./bin/updateSubmodule.sh hash updates to specified hash
  5. # cd to the VisualEditor directory
  6. cd $(cd $(dirname $0)/..; pwd)
  7. # Check that both working directories are clean
  8. if git status -uno --ignore-submodules | grep -i changes > /dev/null
  9. then
  10. echo >&2 "Working directory must be clean"
  11. exit 1
  12. fi
  13. cd lib/ve
  14. if git status -uno --ignore-submodules | grep -i changes > /dev/null
  15. then
  16. echo >&2 "lib/ve working directory must be clean"
  17. exit 1
  18. fi
  19. cd ../..
  20. git fetch origin
  21. # Create sync-repos branch if needed and reset it to master
  22. git checkout -B sync-repos origin/master
  23. git submodule update
  24. cd lib/ve
  25. git fetch origin
  26. # Figure out what to set the submodule to
  27. if [ -n "${1:-}" ]
  28. then
  29. TARGET="$1"
  30. TARGETDESC="$1"
  31. else
  32. TARGET=origin/master
  33. TARGETDESC="master ($(git rev-parse --short origin/master))"
  34. fi
  35. # Generate commit summary
  36. # TODO recurse
  37. NEWCHANGES=$(git log ..$TARGET --oneline --no-merges --reverse --color=never)
  38. NEWCHANGESDISPLAY=$(git log ..$TARGET --oneline --no-merges --reverse --color=always)
  39. COMMITMSG=$(cat <<END
  40. Update VE core submodule to $TARGETDESC
  41. New changes:
  42. $NEWCHANGES
  43. END
  44. )
  45. # Check out master of VE core
  46. git checkout $TARGET
  47. # Commit
  48. cd ../..
  49. git commit lib/ve -m "$COMMITMSG" > /dev/null
  50. if [ "$?" == "1" ]
  51. then
  52. echo >&2 "No changes"
  53. else
  54. cat >&2 <<END
  55. Created commit with changes:
  56. $NEWCHANGESDISPLAY
  57. END
  58. fi