add-subtree.sh 536 B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. set -e
  3. if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
  4. echo "Usage: git add-subtree <path> <repo> <branch> [subdir]"
  5. exit
  6. fi
  7. path=${1%/}
  8. repo=${2%/}
  9. branch=${3}
  10. subdir=${4%/}
  11. if [ "${subdir}" = "" ]; then
  12. git subtree add -P ${path} ${repo} ${branch} -m "Add ${path} from ${repo}"
  13. else
  14. bash .utils/subtree-subdir-helper.sh ${path} ${repo} ${branch} ${subdir} add
  15. fi
  16. gitsubtree=${path}/.gitsubtree
  17. echo ${repo} ${branch} ${subdir} > ${gitsubtree}
  18. git add ${gitsubtree}
  19. git commit --amend --no-edit