Guest User

Untitled

a guest
Jul 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/bin/bash
  2. # Extract subdirectory into a submodule.
  3.  
  4. if [ -z "$1" ]; then
  5. echo "Usage: extract-submodule subdirectory"
  6. echo "No trailing slash"
  7. echo "Should be run from the root directory of repository"
  8. echo "Everything should be clean prior to running this script"
  9. echo "You need to manually copy submodule somewhere and update .gitmodules file appropriately"
  10. exit 1;
  11. fi
  12. path="$1"
  13.  
  14. set -ex
  15. git filter-branch --split-submodule "$path" --tag-name-filter cat -- --branches --tags
  16. git clone . "$path"
  17. pushd .
  18. cd "$path"
  19. set +e
  20. rm -Rf .git/refs/original
  21. set +x
  22. for i in `git show-ref | cut -b 42-`; do
  23. set -x
  24. git update-ref -m 'submodule conversion' $i $i:$path || git update-ref -d $i
  25. set +x
  26. done
  27. set -x
  28. git reset --hard
  29. popd
  30. cat >> .gitmodules <<EOF
  31.  
  32. [submodule "$path"]
  33. path = $path
  34. url = please://fix/me/
  35. EOF
  36. set +x
  37. echo "You should probably do 'git submodule update --init' now"
Add Comment
Please, Sign In to add comment