Skip to content

Instantly share code, notes, and snippets.

@klen
Created October 27, 2013 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klen/7178623 to your computer and use it in GitHub Desktop.
Save klen/7178623 to your computer and use it in GitHub Desktop.
#!/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