From 229b832bc029ec80d7fabc7f87322a17644c909e Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Tue, 20 Dec 2011 15:26:13 +0800 Subject: [PATCH] Added function to remove a git submodule --- lib/git/tools.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index 85efd99..ee7c21e 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -80,3 +80,19 @@ git_bisect_grep() { git bisect bad git bisect run grep -qRE "$2" $search_path } + + +# Removes a git submodule +# (from http://stackoverflow.com/a/7646931/304706) +# Deletes the sections from .gitmodules, .git/config, +# and runs git rm --cached path/to/submodule. +git_submodule_rm() { + if [ -z "$1" ]; then + echo "Usage: git_submodule_rm path/to/submodule (no trailing slash)" + exit 1 + fi + git config -f .git/config --remove-section "submodule.$1" + git config -f .gitmodules --remove-section "submodule.$1" + git add .gitmodules + git rm --cached "$1" +}