Created
December 24, 2010 02:31
-
-
Save vi/753824 to your computer and use it in GitHub Desktop.
Script to extract submodules from git repositories. Depends on --split-submodule filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The --split-submodule patch for git is mirrored at http://vi-server.org/vi/bin/git-extract-submodule.patch
The script itself is mirrored at http://vi-server.org/vi/bin/git-extract-submodule