{"thread":{"id":"32004","subject":"[PATCH] Add rm to submodule command.","startedAt":"2012-11-02T17:26:11Z","lastAt":"2012-11-04T14:29:02Z","messageCount":3,"participants":["Alex Linden Levy","Jeff King","Jens Lehmann"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"202453","messageId":"1351877171-3176-1-git-send-email-lindenle@gmail.com","threadId":"32004","inReplyTo":null,"subject":"[PATCH] Add rm to submodule command.","fromName":"Alex Linden Levy","fromEmail":"lindenle@gmail.com","sentAt":"2012-11-02T17:26:11Z","receivedAt":"2012-11-02T17:26:11Z","isPatch":true,"sender":{"key":"lindenle@gmail.com","avatar":null},"body":"This change removes the config entries in .gitmodules and adds it.\n---\n git-submodule.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 61 insertions(+), 1 deletion(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ab6b110..29d950f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -6,6 +6,7 @@\n \n dashless=$(basename \"$0\" | sed -e 's/-/ /')\n USAGE=\"[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]\n+   or: $dashless [--quiet] rm [-b branch] [-f|--force] [--] [<path>]\n    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]\n    or: $dashless [--quiet] init [--] [<path>...]\n    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]\n@@ -370,6 +371,65 @@ Use -f if you really want to add it.\" >&2\n \tdie \"$(eval_gettext \"Failed to register submodule '\\$sm_path'\")\"\n }\n \n+cmd_rm()\n+{\n+\t# parse $args after \"submodule ... rm\".\n+\twhile test $# -ne 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-b | --branch)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tbranch=$2\n+\t\t\tshift\n+\t\t\t;;\n+\t\t-f | --force)\n+\t\t\tforce=$1\n+\t\t\t;;\n+\t\t-q|--quiet)\n+\t\t\tGIT_QUIET=1\n+\t\t\t;;\n+\t\t--)\n+\t\t\tshift\n+\t\t\tbreak\n+\t\t\t;;\n+\t\t-*)\n+\t\t\tusage\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\t\n+\tsm_path=$1\n+\n+\t# normalize path:\n+\t# multiple //; leading ./; /./; /../; trailing /\n+\tsm_path=$(printf '%s/\\n' \"$sm_path\" |\n+\t\tsed -e '\n+\t\t\ts|//*|/|g\n+\t\t\ts|^\\(\\./\\)*||\n+\t\t\ts|/\\./|/|g\n+\t\t\t:start\n+\t\t\ts|\\([^/]*\\)/\\.\\./||\n+\t\t\ttstart\n+\t\t\ts|/*$||\n+\t\t')\n+\n+\n+\t#edit .gitmodules\n+\tgit config -f .gitmodules --remove-section submodule.\"$sm_path\" ||\n+\tdie \"$(eval_gettext \"Failed to rm submodule '\\$sm_path' section\")\"\n+\n+\t#get rid of the submodule\n+\tgit rm --cached $force \"$sm_path\" ||\n+\tdie \"$(eval_gettext \"Failed to rm submodule '\\$sm_path'\")\"\n+\t\n+\t#now add the .gitmodules change\n+\tgit add ${force} .gitmodules ||\n+\tdie \"$(eval_gettext \"Failed to remove submodule '\\$sm_path'\")\"\n+}\n #\n # Execute an arbitrary command sequence in each checked out\n # submodule\n@@ -1076,7 +1136,7 @@ cmd_sync()\n while test $# != 0 && test -z \"$command\"\n do\n \tcase \"$1\" in\n-\tadd | foreach | init | update | status | summary | sync)\n+\tadd | rm | foreach | init | update | status | summary | sync)\n \t\tcommand=$1\n \t\t;;\n \t-q|--quiet)\n-- \n1.8.0.1.g3039071.dirty\n"},{"id":"202513","messageId":"20121104134324.GA31623@sigill.intra.peff.net","threadId":"32004","inReplyTo":"1351877171-3176-1-git-send-email-lindenle@gmail.com","subject":"Re: [PATCH] Add rm to submodule command.","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-11-04T13:43:24Z","receivedAt":"2012-11-04T13:43:24Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Nov 02, 2012 at 10:26:11AM -0700, Alex Linden Levy wrote:\n\n> This change removes the config entries in .gitmodules and adds it.\n> ---\n\nSignoff?\n\n>  git-submodule.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n>  1 file changed, 61 insertions(+), 1 deletion(-)\n\nNo documentation or tests?\n\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index ab6b110..29d950f 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n\nI'd defer to submodule experts on whether the steps to 'rm' the\nsubmodule make sense. Jens?\n\n-Peff\n"},{"id":"202516","messageId":"50967BAE.4030102@web.de","threadId":"32004","inReplyTo":"20121104134324.GA31623@sigill.intra.peff.net","subject":"Re: [PATCH] Add rm to submodule command.","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-11-04T14:29:02Z","receivedAt":"2012-11-04T14:29:02Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 04.11.2012 14:43, schrieb Jeff King:\n> On Fri, Nov 02, 2012 at 10:26:11AM -0700, Alex Linden Levy wrote:\n> \n>> This change removes the config entries in .gitmodules and adds it.\n>> ---\n> \n> Signoff?\n> \n>>  git-submodule.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n>>  1 file changed, 61 insertions(+), 1 deletion(-)\n> \n> No documentation or tests?\n> \n>> diff --git a/git-submodule.sh b/git-submodule.sh\n>> index ab6b110..29d950f 100755\n>> --- a/git-submodule.sh\n>> +++ b/git-submodule.sh\n> \n> I'd defer to submodule experts on whether the steps to 'rm' the\n> submodule make sense. Jens?\n\nHmm, this change adds the --quiet and --branch options to rm\nwhich aren't used (and at least --branch makes no sense to me\nhere). Remainders of copy & paste? It also only affects the\n.gitmodules setting and leaves the submodules work tree alone,\nwhile I think it should - at least optionally - remove the work\ntree just like \"git rm\" removes files too (of course only if\nthere is no .git directory found in it and no modifications are\npresent, as that would possibly lose data).\n\nMe also thinks such a command should use my recent rm submodule\nwork to remove the work tree (found in your current master and\nJunio's next branch), which does all necessary checks before it\nremoves the work tree together with the index entry. This could\nbe tweaked via a --cached option or such if the user wants to\nkeep the work tree.\n\nBut apart from those issues I'm not convinced that adding a\n\"git submodule rm\" command is the best option. While working on\nteaching \"git mv\" to move submodules I came to the conclusion\nthat it might be a better solution to let \"git rm\" remove the\nsubmodule entry from the .gitmodules file itself (but of course\nonly if that file is found and contains such an entry, if not\nit will silently do nothing to not disturb submodule users who\ndon't have a .gitmodules file and are using plain gitlinks).\n\nThe reason is that git core commands like status, diff and\nfetch already use the path -> name mapping found in .gitmodules\nand will behave strange when this is out of sync with the work\ntree. So I strongly believe that doing a \"git mv\" should change\nthe path -> name mapping in .gitmodules too while moving the\nsubmodule's work tree and updating the index (of course again\nonly if .gitmodules is found and contains such an entry, if not\nit'll just move the work tree and update the index). Then we\nwon't need a new \"git submodule mv\" command as everything is\ndone inside the mv command. And for consistency I think \"git rm\"\nshould also remove the path -> name mapping (even though that is\nnot required for a rm to do its job, as no one will use that\nsetting later when the submodule is gone from the index). Then\nwe won't need a new \"git submodule rm\" at all.\n\nDoes that make sense?\n"}]}