diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-03-25 14:00:29 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-25 14:00:29 -0700 |
commit | b03b41e24c84731742e132d86ef3e449dcd6ec25 (patch) | |
tree | c6ce8797dcf0c8ff0f71fd03f2b6b4e184f10cd3 /git-submodule.sh | |
parent | Merge branch 'jc/describe' (diff) | |
parent | submodule: add 'deinit' command (diff) | |
download | tgif-b03b41e24c84731742e132d86ef3e449dcd6ec25.tar.xz |
Merge branch 'jl/submodule-deinit'
There was no Porcelain way to say "I no longer am interested in
this submodule", once you express your interest in a submodule with
"submodule init". "submodule deinit" is the way to do so.
* jl/submodule-deinit:
submodule: add 'deinit' command
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-x | git-submodule.sh | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index ab29bfeb73..204bc78a9f 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -8,6 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /') USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>] or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...] or: $dashless [--quiet] init [--] [<path>...] + or: $dashless [--quiet] deinit [-f|--force] [--] <path>... or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] or: $dashless [--quiet] foreach [--recursive] <command> @@ -547,6 +548,80 @@ cmd_init() } # +# Unregister submodules from .git/config and remove their work tree +# +# $@ = requested paths (use '.' to deinit all submodules) +# +cmd_deinit() +{ + # parse $args after "submodule ... deinit". + while test $# -ne 0 + do + case "$1" in + -f|--force) + force=$1 + ;; + -q|--quiet) + GIT_QUIET=1 + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift + done + + if test $# = 0 + then + die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")" + fi + + module_list "$@" | + while read mode sha1 stage sm_path + do + die_if_unmatched "$mode" + name=$(module_name "$sm_path") || exit + + # Remove the submodule work tree (unless the user already did it) + if test -d "$sm_path" + then + # Protect submodules containing a .git directory + if test -d "$sm_path/.git" + then + echo >&2 "$(eval_gettext "Submodule work tree '\$sm_path' contains a .git directory")" + die "$(eval_gettext "(use 'rm -rf' if you really want to remove it including all of its history)")" + fi + + if test -z "$force" + then + git rm -n "$sm_path" || + die "$(eval_gettext "Submodule work tree '\$sm_path' contains local modifications; use '-f' to discard them")" + fi + rm -rf "$sm_path" || say "$(eval_gettext "Could not remove submodule work tree '\$sm_path'")" + fi + + mkdir "$sm_path" || say "$(eval_gettext "Could not create empty submodule directory '\$sm_path'")" + + # Remove the .git/config entries (unless the user already did it) + if test -n "$(git config --get-regexp submodule."$name\.")" + then + # Remove the whole section so we have a clean state when + # the user later decides to init this submodule again + url=$(git config submodule."$name".url) + git config --remove-section submodule."$name" 2>/dev/null && + say "$(eval_gettext "Submodule '\$name' (\$url) unregistered for path '\$sm_path'")" + fi + done +} + +# # Update each submodule path to correct revision, using clone and checkout as needed # # $@ = requested paths (default to all) @@ -1162,7 +1237,7 @@ cmd_sync() while test $# != 0 && test -z "$command" do case "$1" in - add | foreach | init | update | status | summary | sync) + add | foreach | init | deinit | update | status | summary | sync) command=$1 ;; -q|--quiet) |