mirror of
https://github.com/tj/git-extras.git
synced 2026-09-16 02:16:17 -04:00
Merge pull request #536 from spacewander/delete_submodule
Update the way to delete submodule
This commit is contained in:
commit
1aadd1c52f
|
|
@ -1,13 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
submodule=$1
|
||||
|
||||
test -z $submodule && echo "submodule required" 1>&2 && exit 1
|
||||
test -z "$1" && echo "submodule required" 1>&2 && exit 1
|
||||
cd "$(git root)"
|
||||
test ! -f .gitmodules && echo ".gitmodules file not found" 1>&2 && exit 2
|
||||
|
||||
NAME=$(echo $submodule | sed 's/\/$//g')
|
||||
test -z $(git config --file=.gitmodules submodule.$NAME.url) && echo "submodule not found" 1>&2 && exit 3
|
||||
NAME="$(echo "$1" | sed 's/\/$//g')"
|
||||
test -z \
|
||||
"$(git config --file=.gitmodules submodule."$NAME".url)" \
|
||||
&& echo "submodule not found" 1>&2 && exit 3
|
||||
|
||||
git submodule deinit $NAME
|
||||
git rm --cached $NAME
|
||||
rm -rf .git/modules/$NAME
|
||||
# 1. Delete the relevant section from .git/config and clean submodule files
|
||||
git submodule deinit -f "$NAME" || exit 4
|
||||
rmdir "$NAME"
|
||||
rm -rf .git/modules/"$NAME"
|
||||
# 2. Delete the relevant line from .gitmodules
|
||||
git config --file=.gitmodules --remove-section submodule."$NAME"
|
||||
git add .gitmodules
|
||||
# 3. Run git rm --cached path_to_submodule
|
||||
git rm --cached -rf "$NAME"
|
||||
# 4. Need to confirm and commit the changes for yourself
|
||||
echo
|
||||
echo "Now submodule $NAME is deleted."
|
||||
echo 'Confirm with `git submodule status` and commit the changes for yourself.'
|
||||
|
|
|
|||
Loading…
Reference in a new issue