add-subtree.sh 581 B

1234567891011121314151617181920212223
  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. subdir="/"
  13. git subtree add -P "${path}" "${repo}" "${branch}" -m "Add ${path} from ${repo}"
  14. else
  15. bash .utils/subtree-subdir-helper.sh "${path}" "${repo}" "${branch}" "${subdir}" add
  16. fi
  17. gitsubtree="${path}/.gitsubtree"
  18. echo "${repo} ${branch} ${subdir}" > "${gitsubtree}"
  19. git add "${gitsubtree}"
  20. git commit --amend --no-edit