summaryrefslogtreecommitdiff
path: root/localmrsync
blob: a4d4a4f7511b02a5c4d952f98ac515a3a490d515 (plain)
  1. #!/bin/sh
  2. # Copyright © 2014-2015 Jonas Smedegaard <dr@jones.dk>
  3. # Description: create/update local + remote git and register in mr
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # Depends: git mr
  19. set -eu
  20. for dir in "$@"; do
  21. if [ ! -d "$dir" ]; then
  22. echo "Skipping non-dir \"$dir\""
  23. continue
  24. fi
  25. cd "$dir"
  26. if [ ! -d .git ]; then
  27. if [ -z "$GIT_INIT_BASEURL" ]; then
  28. echo "Skipping non-git dir \"$dir\" (set GIT_INIT_BASEURL to initialize)"
  29. cd ..
  30. continue
  31. fi
  32. touch ../.mrconfig
  33. git init
  34. git add -A
  35. git commit -m "Initial commit."
  36. fi
  37. if ! url=$(git config --get remote.origin.url); then
  38. git remote add origin "$GIT_INIT_BASEURL"/"$dir"
  39. url=$(git config --get remote.origin.url)
  40. mr reg
  41. fi
  42. host=$(echo "$url" | sed -e 's/:.*//')
  43. path=$(echo "$url" | sed -e 's/.*://' -e 's/\.git$//')
  44. if ! ssh "$host" test -d "$path.git"; then
  45. ssh "$host" mkdir -p "$(dirname "$path")"
  46. ssh "$host" git init --bare "$path.git"
  47. fi
  48. git add -A && git commit -m "Sync." || true
  49. git push --set-upstream origin master || true
  50. cd ..
  51. done
  52. printf 'Done (press return)'
  53. read foo