Created
October 27, 2013 06:48
-
-
Save klen/7178623 to your computer and use it in GitHub Desktop.
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/sh | |
# | |
# Kirill Klenov | |
# Oct 27, 2013 | |
# | |
# Usage: Add it to your PATH and `git submodule-remove path/to/submodule`. | |
ROOT=$(git rev-parse --show-toplevel) | |
SUBMODULE_NAME=$(echo "$1" | sed 's/\/$//'); shift | |
test -z "$SUBMODULE_NAME" && echo "You should define path to submodule." 1>&2 && exit 1 | |
git submodule status "$SUBMODULE_NAME" >/dev/null 2>&1 || { | |
echo "Submodule '$SUBMODULE_NAME' not found" 1>&2 && exit 1 | |
} | |
test ! -f $ROOT/.gitmodules && echo "File .gitmodules not found" 1>&2 && exit 2 | |
git submodule deinit -f "$SUBMODULE_NAME" && git rm -f "$SUBMODULE_NAME" && { | |
SUBMODULE_PATH=$(python -c "import os.path; print os.path.relpath('$SUBMODULE_NAME','$ROOT')") | |
git config -f $ROOT/.gitmodules --remove-section "submodule.$SUBMODULE_PATH" | |
if [ -z "$(cat $ROOT/.gitmodules)" ]; then | |
git rm -f $ROOT/.gitmodules | |
else | |
git add $ROOT/.gitmodules | |
fi | |
if [ -d "$ROOT/.git/modules/$SUBMODULE_PATH" ]; then | |
echo "rm .git/modules/$SUBMODULE_PATH" | |
rm -rf "$ROOT/.git/modules/$SUBMODULE_PATH" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment