{"thread":{"id":"44707","subject":"[PATCHv3 0/4] git-rm absorbs submodule git directory before deletion","startedAt":"2016-12-14T22:41:33Z","lastAt":"2016-12-15T00:03:10Z","messageCount":8,"participants":["Stefan Beller","Brandon Williams","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"307818","messageId":"20161214224101.6211-1-sbeller@google.com","threadId":"44707","inReplyTo":null,"subject":"[PATCHv3 0/4] git-rm absorbs submodule git directory before deletion","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-14T22:40:57Z","receivedAt":"2016-12-14T22:41:33Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"v3:\n* removed the patch to enhance ok_to_remove_submodule to absorb the submodule\n  if needed\n* Removed all the error reporting from git-rm that was related to submodule\n  git directories not absorbed.\n* instead just absorb the git repositories or let the absorb function die\n  with an appropriate error message.\n\nv2:\n* new base where to apply the patch:\n  sb/submodule-embed-gitdir merged with sb/t3600-cleanup.\n  I got merge conflicts and resolved them this way:\n#@@@ -709,9 -687,10 +687,9 @@@ test_expect_success 'checking out a com\n#          git commit -m \"submodule removal\" submod &&\n#          git checkout HEAD^ &&\n#          git submodule update &&\n#-         git checkout -q HEAD^ 2>actual &&\n#+         git checkout -q HEAD^ &&\n#          git checkout -q master 2>actual &&\n# -        echo \"warning: unable to rmdir submod: Directory not empty\" >expected &&\n# -        test_i18ncmp expected actual &&\n# +        test_i18ngrep \"^warning: unable to rmdir submod:\" actual &&\n#          git status -s submod >actual &&\n#          echo \"?? submod/\" >expected &&\n#          test_cmp expected actual &&\n#\n\n* improved commit message in \"ok_to_remove_submodule: absorb the submodule git dir\"\n  (David Turner offered me some advice on how to write better English off list)\n* simplified code in last patch:\n  -> dropped wrong comment for fallthrough\n  -> moved redundant code out of both bodies of an if-clause.\n* Fixed last patchs commit message to have \"or_die\" instead of or_dir.\n\nv1:\nThe \"checkout --recurse-submodules\" series got too large to comfortably send\nit out for review, so I had to break it up into smaller series'; this is the\nfirst subseries, but it makes sense on its own.\n\nThis series teaches git-rm to absorb the git directory of a submodule instead\nof failing and complaining about the git directory preventing deletion.\n\nIt applies on origin/sb/submodule-embed-gitdir.\n\nAny feedback welcome!\n\nThanks,\nStefan\n\n\nStefan Beller (4):\n  submodule.h: add extern keyword to functions\n  submodule: modernize ok_to_remove_submodule to use argv_array\n  submodule: add flags to ok_to_remove_submodule\n  rm: add absorb a submodules git dir before deletion\n\n builtin/rm.c  | 78 +++++++++++++++--------------------------------------------\n cache.h       |  2 ++\n entry.c       |  8 ++++++\n submodule.c   | 31 +++++++++++++++---------\n submodule.h   | 58 +++++++++++++++++++++++++-------------------\n t/t3600-rm.sh | 39 ++++++++++++------------------\n 6 files changed, 97 insertions(+), 119 deletions(-)\n\n-- \n2.11.0.rc2.35.g26e18c9\n\n"},{"id":"307819","messageId":"20161214224101.6211-3-sbeller@google.com","threadId":"44707","inReplyTo":"20161214224101.6211-1-sbeller@google.com","subject":"[PATCHv3 2/4] submodule: modernize ok_to_remove_submodule to use argv_array","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-14T22:40:59Z","receivedAt":"2016-12-14T22:41:37Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"Instead of constructing the NULL terminated array ourselves, we\nshould make use of the argv_array infrastructure.\n\nWhile at it, adapt the error messages to reflect the actual invocation.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c | 14 ++++----------\n 1 file changed, 4 insertions(+), 10 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 45ccfb7ab4..9f0b544ebe 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1023,13 +1023,6 @@ int ok_to_remove_submodule(const char *path)\n {\n \tssize_t len;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n-\tconst char *argv[] = {\n-\t\t\"status\",\n-\t\t\"--porcelain\",\n-\t\t\"-u\",\n-\t\t\"--ignore-submodules=none\",\n-\t\tNULL,\n-\t};\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ok_to_remove = 1;\n \n@@ -1039,14 +1032,15 @@ int ok_to_remove_submodule(const char *path)\n \tif (!submodule_uses_gitfile(path))\n \t\treturn 0;\n \n-\tcp.argv = argv;\n+\targv_array_pushl(&cp.args, \"status\", \"--porcelain\", \"-u\",\n+\t\t\t\t   \"--ignore-submodules=none\", NULL);\n \tprepare_submodule_repo_env(&cp.env_array);\n \tcp.git_cmd = 1;\n \tcp.no_stdin = 1;\n \tcp.out = -1;\n \tcp.dir = path;\n \tif (start_command(&cp))\n-\t\tdie(\"Could not run 'git status --porcelain -uall --ignore-submodules=none' in submodule %s\", path);\n+\t\tdie(_(\"could not run 'git status --porcelain -u --ignore-submodules=none' in submodule %s\"), path);\n \n \tlen = strbuf_read(&buf, cp.out, 1024);\n \tif (len > 2)\n@@ -1054,7 +1048,7 @@ int ok_to_remove_submodule(const char *path)\n \tclose(cp.out);\n \n \tif (finish_command(&cp))\n-\t\tdie(\"'git status --porcelain -uall --ignore-submodules=none' failed in submodule %s\", path);\n+\t\tdie(_(\"'git status --porcelain -u --ignore-submodules=none' failed in submodule %s\"), path);\n \n \tstrbuf_release(&buf);\n \treturn ok_to_remove;\n-- \n2.11.0.rc2.35.g26e18c9\n\n"},{"id":"307820","messageId":"20161214224101.6211-2-sbeller@google.com","threadId":"44707","inReplyTo":"20161214224101.6211-1-sbeller@google.com","subject":"[PATCHv3 1/4] submodule.h: add extern keyword to functions","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-14T22:40:58Z","receivedAt":"2016-12-14T22:41:38Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"As the upcoming series will add a lot of functions to the submodule\nheader, let's first make the header consistent to the rest of the project\nby adding the extern keyword to functions.\n\nAs per the CodingGuidelines we try to stay below 80 characters per line,\nso adapt all those functions to stay below 80 characters that are already\nusing more than one line.  Those function using just one line are better\nkept in one line than breaking them up into multiple lines just for the\ngoal of staying below the character limit as it makes grepping\nfor functions easier if they are one liners.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.h | 55 ++++++++++++++++++++++++++++++-------------------------\n 1 file changed, 30 insertions(+), 25 deletions(-)\n\ndiff --git a/submodule.h b/submodule.h\nindex 6229054b99..61fb610749 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -29,50 +29,55 @@ struct submodule_update_strategy {\n };\n #define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}\n \n-int is_staging_gitmodules_ok(void);\n-int update_path_in_gitmodules(const char *oldpath, const char *newpath);\n-int remove_path_from_gitmodules(const char *path);\n-void stage_updated_gitmodules(void);\n-void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,\n+extern int is_staging_gitmodules_ok(void);\n+extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);\n+extern int remove_path_from_gitmodules(const char *path);\n+extern void stage_updated_gitmodules(void);\n+extern void set_diffopt_flags_from_submodule_config(struct diff_options *,\n \t\tconst char *path);\n-int submodule_config(const char *var, const char *value, void *cb);\n-void gitmodules_config(void);\n-int parse_submodule_update_strategy(const char *value,\n+extern int submodule_config(const char *var, const char *value, void *cb);\n+extern void gitmodules_config(void);\n+extern int parse_submodule_update_strategy(const char *value,\n \t\tstruct submodule_update_strategy *dst);\n-const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);\n-void handle_ignore_submodules_arg(struct diff_options *diffopt, const char *);\n-void show_submodule_summary(FILE *f, const char *path,\n+extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);\n+extern void handle_ignore_submodules_arg(struct diff_options *, const char *);\n+extern void show_submodule_summary(FILE *f, const char *path,\n \t\tconst char *line_prefix,\n \t\tstruct object_id *one, struct object_id *two,\n \t\tunsigned dirty_submodule, const char *meta,\n \t\tconst char *del, const char *add, const char *reset);\n-void show_submodule_inline_diff(FILE *f, const char *path,\n+extern void show_submodule_inline_diff(FILE *f, const char *path,\n \t\tconst char *line_prefix,\n \t\tstruct object_id *one, struct object_id *two,\n \t\tunsigned dirty_submodule, const char *meta,\n \t\tconst char *del, const char *add, const char *reset,\n \t\tconst struct diff_options *opt);\n-void set_config_fetch_recurse_submodules(int value);\n-void check_for_new_submodule_commits(unsigned char new_sha1[20]);\n-int fetch_populated_submodules(const struct argv_array *options,\n+extern void set_config_fetch_recurse_submodules(int value);\n+extern void check_for_new_submodule_commits(unsigned char new_sha1[20]);\n+extern int fetch_populated_submodules(const struct argv_array *options,\n \t\t\t       const char *prefix, int command_line_option,\n \t\t\t       int quiet, int max_parallel_jobs);\n-unsigned is_submodule_modified(const char *path, int ignore_untracked);\n-int submodule_uses_gitfile(const char *path);\n-int ok_to_remove_submodule(const char *path);\n-int merge_submodule(unsigned char result[20], const char *path, const unsigned char base[20],\n-\t\t    const unsigned char a[20], const unsigned char b[20], int search);\n-int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name,\n-\t\tstruct string_list *needs_pushing);\n-int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);\n-int parallel_submodules(void);\n+extern unsigned is_submodule_modified(const char *path, int ignore_untracked);\n+extern int submodule_uses_gitfile(const char *path);\n+extern int ok_to_remove_submodule(const char *path);\n+extern int merge_submodule(unsigned char result[20], const char *path,\n+\t\t\t   const unsigned char base[20],\n+\t\t\t   const unsigned char a[20],\n+\t\t\t   const unsigned char b[20], int search);\n+extern int find_unpushed_submodules(unsigned char new_sha1[20],\n+\t\t\t\t    const char *remotes_name,\n+\t\t\t\t    struct string_list *needs_pushing);\n+extern int push_unpushed_submodules(unsigned char new_sha1[20],\n+\t\t\t\t    const char *remotes_name);\n+extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);\n+extern int parallel_submodules(void);\n \n /*\n  * Prepare the \"env_array\" parameter of a \"struct child_process\" for executing\n  * a submodule by clearing any repo-specific envirionment variables, but\n  * retaining any config in the environment.\n  */\n-void prepare_submodule_repo_env(struct argv_array *out);\n+extern void prepare_submodule_repo_env(struct argv_array *out);\n \n #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0)\n extern void absorb_git_dir_into_superproject(const char *prefix,\n-- \n2.11.0.rc2.35.g26e18c9\n\n"},{"id":"307821","messageId":"20161214224101.6211-4-sbeller@google.com","threadId":"44707","inReplyTo":"20161214224101.6211-1-sbeller@google.com","subject":"[PATCHv3 3/4] submodule: add flags to ok_to_remove_submodule","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-14T22:41:00Z","receivedAt":"2016-12-14T22:41:40Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"In different contexts the question whether deleting a submodule is ok\nto remove may be answered differently.\n\nIn 293ab15eea (submodule: teach rm to remove submodules unless they\ncontain a git directory, 2012-09-26) a case was made that we can safely\nignore ignored untracked files for removal as we explicitely ask for the\nremoval of the submodule.\n\nIn a later patch we want to remove submodules even when the user doesn't\nexplicitly ask for it (e.g. checking out a tree-ish in which the submodule\ndoesn't exist).  In that case we want to be more careful when it comes\nto deletion of untracked files. As of this patch it is unclear how this\nwill be implemented exactly, so we'll offer flags in which the caller\ncan specify how the different untracked files ought to be handled.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/rm.c |  3 ++-\n submodule.c  | 23 +++++++++++++++++++----\n submodule.h  |  5 ++++-\n 3 files changed, 25 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 3f3e24eb36..fdd7183f61 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -187,7 +187,8 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t */\n \t\tif (ce_match_stat(ce, &st, 0) ||\n \t\t    (S_ISGITLINK(ce->ce_mode) &&\n-\t\t     !ok_to_remove_submodule(ce->name)))\n+\t\t     !ok_to_remove_submodule(ce->name,\n+\t\t\t\tSUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)))\n \t\t\tlocal_changes = 1;\n \n \t\t/*\ndiff --git a/submodule.c b/submodule.c\nindex 9f0b544ebe..2d13744b06 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1019,7 +1019,7 @@ int submodule_uses_gitfile(const char *path)\n \treturn 1;\n }\n \n-int ok_to_remove_submodule(const char *path)\n+int ok_to_remove_submodule(const char *path, unsigned flags)\n {\n \tssize_t len;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n@@ -1032,15 +1032,27 @@ int ok_to_remove_submodule(const char *path)\n \tif (!submodule_uses_gitfile(path))\n \t\treturn 0;\n \n-\targv_array_pushl(&cp.args, \"status\", \"--porcelain\", \"-u\",\n+\targv_array_pushl(&cp.args, \"status\", \"--porcelain\",\n \t\t\t\t   \"--ignore-submodules=none\", NULL);\n+\n+\tif (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED)\n+\t\targv_array_push(&cp.args, \"-uno\");\n+\telse\n+\t\targv_array_push(&cp.args, \"-uall\");\n+\n+\tif (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED))\n+\t\targv_array_push(&cp.args, \"--ignored\");\n+\n \tprepare_submodule_repo_env(&cp.env_array);\n \tcp.git_cmd = 1;\n \tcp.no_stdin = 1;\n \tcp.out = -1;\n \tcp.dir = path;\n \tif (start_command(&cp))\n-\t\tdie(_(\"could not run 'git status --porcelain -u --ignore-submodules=none' in submodule %s\"), path);\n+\t\tdie(_(\"could not run 'git status --porcelain --ignore-submodules=none %s %s' in submodule '%s'\"),\n+\t\t\t(flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) ? \"-uno\" : \"-uall\",\n+\t\t\t(!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) ? \"--ignored\" : \"\",\n+\t\t\tpath);\n \n \tlen = strbuf_read(&buf, cp.out, 1024);\n \tif (len > 2)\n@@ -1048,7 +1060,10 @@ int ok_to_remove_submodule(const char *path)\n \tclose(cp.out);\n \n \tif (finish_command(&cp))\n-\t\tdie(_(\"'git status --porcelain -u --ignore-submodules=none' failed in submodule %s\"), path);\n+\t\tdie(_(\"'git status --porcelain --ignore-submodules=none %s %s' failed in submodule '%s'\"),\n+\t\t\t(flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) ? \"-uno\" : \"-uall\",\n+\t\t\t(!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) ? \"--ignored\" : \"\",\n+\t\t\tpath);\n \n \tstrbuf_release(&buf);\n \treturn ok_to_remove;\ndiff --git a/submodule.h b/submodule.h\nindex 61fb610749..3ed3aa479a 100644\n--- a/submodule.h\n+++ b/submodule.h\n@@ -59,7 +59,10 @@ extern int fetch_populated_submodules(const struct argv_array *options,\n \t\t\t       int quiet, int max_parallel_jobs);\n extern unsigned is_submodule_modified(const char *path, int ignore_untracked);\n extern int submodule_uses_gitfile(const char *path);\n-extern int ok_to_remove_submodule(const char *path);\n+\n+#define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<0)\n+#define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<1)\n+extern int ok_to_remove_submodule(const char *path, unsigned flags);\n extern int merge_submodule(unsigned char result[20], const char *path,\n \t\t\t   const unsigned char base[20],\n \t\t\t   const unsigned char a[20],\n-- \n2.11.0.rc2.35.g26e18c9\n\n"},{"id":"307822","messageId":"20161214224101.6211-5-sbeller@google.com","threadId":"44707","inReplyTo":"20161214224101.6211-1-sbeller@google.com","subject":"[PATCHv3 4/4] rm: add absorb a submodules git dir before deletion","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2016-12-14T22:41:01Z","receivedAt":"2016-12-14T22:41:43Z","isPatch":false,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When deleting a submodule, we need to keep the actual git directory around,\nsuch that we do not lose local changes in there and at a later checkout\nof the submodule we don't need to clone it again.\n\nNow that the functionality is available to absorb the git directory of a\nsubmodule, rewrite the checking in git-rm to not complain, but rather\nrelocate the git directories inside the superproject.\n\nAn alternative solution was discussed to have a function\n`depopulate_submodule`, that couples the check for its git directory and\npossible relocation before the the removal, such that it is less likely to\nmiss the check in the future, but the indirection with such a function\nadded seemed also complex. The reason for that was that this possible\nmove of the git directory was also implemented in `ok_to_remove_submodule`,\nsuch that this function could truthfully answer whether it is ok to remove\nthe submodule.\n\nThe solution proposed here defers all these checks to the caller.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n builtin/rm.c  | 75 ++++++++++++++---------------------------------------------\n cache.h       |  2 ++\n entry.c       |  8 +++++++\n t/t3600-rm.sh | 39 ++++++++++++-------------------\n 4 files changed, 42 insertions(+), 82 deletions(-)\n\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex fdd7183f61..025ef4c735 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -59,27 +59,9 @@ static void print_error_files(struct string_list *files_list,\n \t}\n }\n \n-static void error_removing_concrete_submodules(struct string_list *files, int *errs)\n-{\n-\tprint_error_files(files,\n-\t\t\t  Q_(\"the following submodule (or one of its nested \"\n-\t\t\t     \"submodules)\\n\"\n-\t\t\t     \"uses a .git directory:\",\n-\t\t\t     \"the following submodules (or one of their nested \"\n-\t\t\t     \"submodules)\\n\"\n-\t\t\t     \"use a .git directory:\", files->nr),\n-\t\t\t  _(\"\\n(use 'rm -rf' if you really want to remove \"\n-\t\t\t    \"it including all of its history)\"),\n-\t\t\t  errs);\n-\tstring_list_clear(files, 0);\n-}\n-\n-static int check_submodules_use_gitfiles(void)\n+static void submodules_absorb_gitdir_if_needed(const char *prefix)\n {\n \tint i;\n-\tint errs = 0;\n-\tstruct string_list files = STRING_LIST_INIT_NODUP;\n-\n \tfor (i = 0; i < list.nr; i++) {\n \t\tconst char *name = list.entry[i].name;\n \t\tint pos;\n@@ -99,12 +81,9 @@ static int check_submodules_use_gitfiles(void)\n \t\t\tcontinue;\n \n \t\tif (!submodule_uses_gitfile(name))\n-\t\t\tstring_list_append(&files, name);\n+\t\t\tabsorb_git_dir_into_superproject(prefix, name,\n+\t\t\t\tABSORB_GITDIR_RECURSE_SUBMODULES);\n \t}\n-\n-\terror_removing_concrete_submodules(&files, &errs);\n-\n-\treturn errs;\n }\n \n static int check_local_mod(struct object_id *head, int index_only)\n@@ -120,7 +99,6 @@ static int check_local_mod(struct object_id *head, int index_only)\n \tint errs = 0;\n \tstruct string_list files_staged = STRING_LIST_INIT_NODUP;\n \tstruct string_list files_cached = STRING_LIST_INIT_NODUP;\n-\tstruct string_list files_submodule = STRING_LIST_INIT_NODUP;\n \tstruct string_list files_local = STRING_LIST_INIT_NODUP;\n \n \tno_head = is_null_oid(head);\n@@ -218,13 +196,8 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\telse if (!index_only) {\n \t\t\tif (staged_changes)\n \t\t\t\tstring_list_append(&files_cached, name);\n-\t\t\tif (local_changes) {\n-\t\t\t\tif (S_ISGITLINK(ce->ce_mode) &&\n-\t\t\t\t    !submodule_uses_gitfile(name))\n-\t\t\t\t\tstring_list_append(&files_submodule, name);\n-\t\t\t\telse\n-\t\t\t\t\tstring_list_append(&files_local, name);\n-\t\t\t}\n+\t\t\tif (local_changes)\n+\t\t\t\tstring_list_append(&files_local, name);\n \t\t}\n \t}\n \tprint_error_files(&files_staged,\n@@ -246,8 +219,6 @@ static int check_local_mod(struct object_id *head, int index_only)\n \t\t\t  &errs);\n \tstring_list_clear(&files_cached, 0);\n \n-\terror_removing_concrete_submodules(&files_submodule, &errs);\n-\n \tprint_error_files(&files_local,\n \t\t\t  Q_(\"the following file has local modifications:\",\n \t\t\t     \"the following files have local modifications:\",\n@@ -341,6 +312,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\texit(0);\n \t}\n \n+\tsubmodules_absorb_gitdir_if_needed(prefix);\n+\n \t/*\n \t * If not forced, the file, the index and the HEAD (if exists)\n \t * must match; but the file can already been removed, since\n@@ -357,9 +330,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\toidclr(&oid);\n \t\tif (check_local_mod(&oid, index_only))\n \t\t\texit(1);\n-\t} else if (!index_only) {\n-\t\tif (check_submodules_use_gitfiles())\n-\t\t\texit(1);\n \t}\n \n \t/*\n@@ -393,27 +363,16 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t\t\tconst char *path = list.entry[i].name;\n \t\t\tif (list.entry[i].is_submodule) {\n \t\t\t\tif (is_empty_dir(path)) {\n-\t\t\t\t\tif (!rmdir(path)) {\n-\t\t\t\t\t\tremoved = 1;\n-\t\t\t\t\t\tif (!remove_path_from_gitmodules(path))\n-\t\t\t\t\t\t\tgitmodules_modified = 1;\n-\t\t\t\t\t\tcontinue;\n-\t\t\t\t\t}\n-\t\t\t\t} else {\n-\t\t\t\t\tstrbuf_reset(&buf);\n-\t\t\t\t\tstrbuf_addstr(&buf, path);\n-\t\t\t\t\tif (!remove_dir_recursively(&buf, 0)) {\n-\t\t\t\t\t\tremoved = 1;\n-\t\t\t\t\t\tif (!remove_path_from_gitmodules(path))\n-\t\t\t\t\t\t\tgitmodules_modified = 1;\n-\t\t\t\t\t\tstrbuf_release(&buf);\n-\t\t\t\t\t\tcontinue;\n-\t\t\t\t\t} else if (!file_exists(path))\n-\t\t\t\t\t\t/* Submodule was removed by user */\n-\t\t\t\t\t\tif (!remove_path_from_gitmodules(path))\n-\t\t\t\t\t\t\tgitmodules_modified = 1;\n-\t\t\t\t\t/* Fallthrough and let remove_path() fail. */\n-\t\t\t\t}\n+\t\t\t\t\tif (rmdir(path))\n+\t\t\t\t\t\tdie_errno(\"git rm: '%s'\", path);\n+\t\t\t\t} else if (file_exists(path))\n+\t\t\t\t\t/* non empty directory: */\n+\t\t\t\t\tremove_directory_or_die(path);\n+\n+\t\t\t\tremoved = 1;\n+\t\t\t\tif (!remove_path_from_gitmodules(path))\n+\t\t\t\t\tgitmodules_modified = 1;\n+\t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!remove_path(path)) {\n \t\t\t\tremoved = 1;\ndiff --git a/cache.h b/cache.h\nindex a50a61a197..3a423af59b 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -2018,4 +2018,6 @@ void sleep_millisec(int millisec);\n  */\n void safe_create_dir(const char *dir, int share);\n \n+extern void remove_directory_or_die(const char *path);\n+\n #endif /* CACHE_H */\ndiff --git a/entry.c b/entry.c\nindex c6eea240b6..ddd4cfb2bf 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -73,6 +73,14 @@ static void remove_subtree(struct strbuf *path)\n \t\tdie_errno(\"cannot rmdir '%s'\", path->buf);\n }\n \n+void remove_directory_or_die(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tstrbuf_addstr(&sb, path);\n+\tremove_subtree(&sb);\n+\tstrbuf_release(&sb);\n+}\n+\n static int create_file(const char *path, unsigned int mode)\n {\n \tmode = (mode & 0100) ? 0777 : 0666;\ndiff --git a/t/t3600-rm.sh b/t/t3600-rm.sh\nindex bcbb680651..5aa6db584c 100755\n--- a/t/t3600-rm.sh\n+++ b/t/t3600-rm.sh\n@@ -569,26 +569,22 @@ test_expect_success 'rm of a conflicted unpopulated submodule succeeds' '\n \ttest_cmp expect actual\n '\n \n-test_expect_success 'rm of a populated submodule with a .git directory fails even when forced' '\n+test_expect_success 'rm of a populated submodule with a .git directory migrates git dir' '\n \tgit checkout -f master &&\n \tgit reset --hard &&\n \tgit submodule update &&\n \t(cd submod &&\n \t\trm .git &&\n \t\tcp -R ../.git/modules/sub .git &&\n-\t\tGIT_WORK_TREE=. git config --unset core.worktree\n+\t\tGIT_WORK_TREE=. git config --unset core.worktree &&\n+\t\trm -r ../.git/modules/sub\n \t) &&\n-\ttest_must_fail git rm submod &&\n-\ttest -d submod &&\n-\ttest -d submod/.git &&\n-\tgit status -s -uno --ignore-submodules=none >actual &&\n-\t! test -s actual &&\n-\ttest_must_fail git rm -f submod &&\n-\ttest -d submod &&\n-\ttest -d submod/.git &&\n+\tgit rm submod 2>output.err &&\n+\t! test -d submod &&\n+\t! test -d submod/.git &&\n \tgit status -s -uno --ignore-submodules=none >actual &&\n-\t! test -s actual &&\n-\trm -rf submod\n+\ttest -s actual &&\n+\ttest_i18ngrep Migrating output.err\n '\n \n cat >expect.deepmodified <<EOF\n@@ -667,24 +663,19 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc\n \tgit submodule update --recursive &&\n \t(cd submod/subsubmod &&\n \t\trm .git &&\n-\t\tcp -R ../../.git/modules/sub/modules/sub .git &&\n+\t\tmv ../../.git/modules/sub/modules/sub .git &&\n \t\tGIT_WORK_TREE=. git config --unset core.worktree\n \t) &&\n-\ttest_must_fail git rm submod &&\n-\ttest -d submod &&\n-\ttest -d submod/subsubmod/.git &&\n-\tgit status -s -uno --ignore-submodules=none >actual &&\n-\t! test -s actual &&\n-\ttest_must_fail git rm -f submod &&\n-\ttest -d submod &&\n-\ttest -d submod/subsubmod/.git &&\n+\tgit rm submod 2>output.err &&\n+\t! test -d submod &&\n+\t! test -d submod/subsubmod/.git &&\n \tgit status -s -uno --ignore-submodules=none >actual &&\n-\t! test -s actual &&\n-\trm -rf submod\n+\ttest -s actual &&\n+\ttest_i18ngrep Migrating output.err\n '\n \n test_expect_success 'checking out a commit after submodule removal needs manual updates' '\n-\tgit commit -m \"submodule removal\" submod &&\n+\tgit commit -m \"submodule removal\" submod .gitmodules &&\n \tgit checkout HEAD^ &&\n \tgit submodule update &&\n \tgit checkout -q HEAD^ &&\n-- \n2.11.0.rc2.35.g26e18c9\n\n"},{"id":"307824","messageId":"20161214231032.GA174925@google.com","threadId":"44707","inReplyTo":"20161214224101.6211-4-sbeller@google.com","subject":"Re: [PATCHv3 3/4] submodule: add flags to ok_to_remove_submodule","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2016-12-14T23:10:32Z","receivedAt":"2016-12-14T23:11:48Z","isPatch":false,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 12/14, Stefan Beller wrote:\n> In different contexts the question whether deleting a submodule is ok\n> to remove may be answered differently.\n\nThis sentence is oddly worded.  Maybe this:\n\n  In different context the question \"Is it ok to delete a submodule?\"\n  may be answered differently.\n\n-- \nBrandon Williams\n"},{"id":"307826","messageId":"xmqqpokuvzqf.fsf@gitster.mtv.corp.google.com","threadId":"44707","inReplyTo":"20161214224101.6211-4-sbeller@google.com","subject":"Re: [PATCHv3 3/4] submodule: add flags to ok_to_remove_submodule","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-12-14T23:48:40Z","receivedAt":"2016-12-14T23:48:48Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n> diff --git a/submodule.c b/submodule.c\n> index 9f0b544ebe..2d13744b06 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -1019,7 +1019,7 @@ int submodule_uses_gitfile(const char *path)\n>  \treturn 1;\n>  }\n>  \n> -int ok_to_remove_submodule(const char *path)\n> +int ok_to_remove_submodule(const char *path, unsigned flags)\n>  {\n>  \tssize_t len;\n>  \tstruct child_process cp = CHILD_PROCESS_INIT;\n> @@ -1032,15 +1032,27 @@ int ok_to_remove_submodule(const char *path)\n>  \tif (!submodule_uses_gitfile(path))\n>  \t\treturn 0;\n>  \n> -\targv_array_pushl(&cp.args, \"status\", \"--porcelain\", \"-u\",\n> +\targv_array_pushl(&cp.args, \"status\", \"--porcelain\",\n>  \t\t\t\t   \"--ignore-submodules=none\", NULL);\n> +\n> +\tif (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED)\n> +\t\targv_array_push(&cp.args, \"-uno\");\n> +\telse\n> +\t\targv_array_push(&cp.args, \"-uall\");\n> +\n> +\tif (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED))\n> +\t\targv_array_push(&cp.args, \"--ignored\");\n> +\n\nThese \"internal values to assemble command line\" operations we\ncannot avoid.  But things like this ...\n\n>  \tif (start_command(&cp))\n> -\t\tdie(_(\"could not run 'git status --porcelain -u --ignore-submodules=none' in submodule %s\"), path);\n> +\t\tdie(_(\"could not run 'git status --porcelain --ignore-submodules=none %s %s' in submodule '%s'\"),\n> +\t\t\t(flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) ? \"-uno\" : \"-uall\",\n> +\t\t\t(!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) ? \"--ignored\" : \"\",\n> +\t\t\tpath);\n\nand this ...\n\n>  \tif (finish_command(&cp))\n> -\t\tdie(_(\"'git status --porcelain -u --ignore-submodules=none' failed in submodule %s\"), path);\n> +\t\tdie(_(\"'git status --porcelain --ignore-submodules=none %s %s' failed in submodule '%s'\"),\n> +\t\t\t(flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) ? \"-uno\" : \"-uall\",\n> +\t\t\t(!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) ? \"--ignored\" : \"\",\n> +\t\t\tpath);\n\nmakes me wonder if we want a helper that builds the string out of an\nalready assembled cp.args[] array, so that we won't have to do the\nsame thing twice/thrice and more importantly we won't have to worry\nabout these three going out of sync.\n\n"},{"id":"307827","messageId":"xmqqlgvivze9.fsf@gitster.mtv.corp.google.com","threadId":"44707","inReplyTo":"20161214224101.6211-5-sbeller@google.com","subject":"Re: [PATCHv3 4/4] rm: add absorb a submodules git dir before deletion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-12-14T23:55:58Z","receivedAt":"2016-12-15T00:03:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Stefan Beller <sbeller@google.com> writes:\n\n>  \t\t\tif (list.entry[i].is_submodule) {\n>  \t\t\t\tif (is_empty_dir(path)) {\n> +\t\t\t\t\tif (rmdir(path))\n> +\t\t\t\t\t\tdie_errno(\"git rm: '%s'\", path);\n> +\t\t\t\t} else if (file_exists(path))\n> +\t\t\t\t\t/* non empty directory: */\n\nLose colon?\n\n> +\t\t\t\t\tremove_directory_or_die(path);\n\n... otherwise?  I.e.\n\n\t\t\t\telse\n\t\t\t\t\t???\n\nIf we are running \"git rm -f <path>\", then the path could be a\nsubmodule in the index and on the filesystem, it could be (1)\nalready missing, as the user removed an empty submodule directory\nshe is not interested in, (2) a non-directory, e.g. a file or a\nsymbolic link, perhaps because she was trying to reorganize the\nsuperproject working tree but decided against it, or (3) something\nelse?\n\n(1) is perfectly OK; we end up with a result without the path, which\nis what \"git rm -f\" wanted to do anyway.  I am not sure what should\nhappen in (2), and what other corner cases there are for (3), though.\n\nAnd use of file_exists(path) in the above patch may trigger a\nstrange error message in case (2), as remove_directory_or_die()\nwould say \"path is not a directory\", to which the user will say \"Yes\nI know, I wanted you to remove it with 'git rm -f'\".\n\n\n\n"}]}