Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Extract subdirectory into a submodule.
- if [ -z "$1" ]; then
- echo "Usage: extract-submodule subdirectory"
- echo "No trailing slash"
- echo "Should be run from the root directory of repository"
- echo "Everything should be clean prior to running this script"
- echo "You need to manually copy submodule somewhere and update .gitmodules file appropriately"
- exit 1;
- fi
- path="$1"
- set -ex
- git filter-branch --split-submodule "$path" --tag-name-filter cat -- --branches --tags
- git clone . "$path"
- pushd .
- cd "$path"
- set +e
- rm -Rf .git/refs/original
- set +x
- for i in `git show-ref | cut -b 42-`; do
- set -x
- git update-ref -m 'submodule conversion' $i $i:$path || git update-ref -d $i
- set +x
- done
- set -x
- git reset --hard
- popd
- cat >> .gitmodules <<EOF
- [submodule "$path"]
- path = $path
- url = please://fix/me/
- EOF
- set +x
- echo "You should probably do 'git submodule update --init' now"
Add Comment
Please, Sign In to add comment