Last active
September 18, 2017 16:17
-
-
Save andsens/93ec745e1184dae56d1e to your computer and use it in GitHub Desktop.
Deinitialize a submodule and merge it as a branch
This file contains 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 -xe | |
deinit() { | |
module_path=$1 | |
test -d $module_path | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
url=$(cd $module_path; git config --get remote.origin.url) | |
remote_name=$(basename $url) | |
branch_name=$(basename $url) | |
head=$(cd $module_path; git rev-parse HEAD) | |
git remote add -f $remote_name $url | |
git checkout -fb $branch_name $head | |
rm -rf $module_path | |
git filter-branch -f --index-filter \ | |
'git ls-files -s | gsed "s-\t\"*-&'$module_path'/-" | | |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \ | |
git update-index --index-info && | |
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' | |
git checkout $current_branch | |
git submodule deinit $module_path | |
git rm -rf $module_path | |
git commit -m "Remove $module_path as a submodule" | |
git merge $branch_name | |
git branch -d $branch_name | |
} | |
deinit $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment