Merge branch 'jl/submodule-rm'
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:52:30 +0000 (12:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Nov 2012 20:52:30 +0000 (12:52 -0800)
Finishing touches to "git rm $submodule" that removes the working
tree of a submodule.

* jl/submodule-rm:
Teach rm to remove submodules when given with a trailing '/'

1  2 
builtin/rm.c
diff --combined builtin/rm.c
index 2aea3b565318e11bdcc63f175631388f4f20ba44,4e5e8abeb6a36a13cf272061fb4ee9e129d31740..dabfcf689068804f2b352d200b35770b467a27e8
@@@ -12,7 -12,7 +12,7 @@@
  #include "submodule.h"
  
  static const char * const builtin_rm_usage[] = {
 -      "git rm [options] [--] <file>...",
 +      N_("git rm [options] [--] <file>..."),
        NULL
  };
  
@@@ -203,13 -203,13 +203,13 @@@ static int show_only = 0, force = 0, in
  static int ignore_unmatch = 0;
  
  static struct option builtin_rm_options[] = {
 -      OPT__DRY_RUN(&show_only, "dry run"),
 -      OPT__QUIET(&quiet, "do not list removed files"),
 -      OPT_BOOLEAN( 0 , "cached",         &index_only, "only remove from the index"),
 -      OPT__FORCE(&force, "override the up-to-date check"),
 -      OPT_BOOLEAN('r', NULL,             &recursive,  "allow recursive removal"),
 +      OPT__DRY_RUN(&show_only, N_("dry run")),
 +      OPT__QUIET(&quiet, N_("do not list removed files")),
 +      OPT_BOOLEAN( 0 , "cached",         &index_only, N_("only remove from the index")),
 +      OPT__FORCE(&force, N_("override the up-to-date check")),
 +      OPT_BOOLEAN('r', NULL,             &recursive,  N_("allow recursive removal")),
        OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
 -                              "exit with a zero status even if nothing matched"),
 +                              N_("exit with a zero status even if nothing matched")),
        OPT_END(),
  };
  
@@@ -234,6 -234,21 +234,21 @@@ int cmd_rm(int argc, const char **argv
        if (read_cache() < 0)
                die(_("index file corrupt"));
  
+       /*
+        * Drop trailing directory separators from directories so we'll find
+        * submodules in the index.
+        */
+       for (i = 0; i < argc; i++) {
+               size_t pathlen = strlen(argv[i]);
+               if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
+                   is_directory(argv[i])) {
+                       do {
+                               pathlen--;
+                       } while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
+                       argv[i] = xmemdupz(argv[i], pathlen);
+               }
+       }
        pathspec = get_pathspec(prefix, argv);
        refresh_index(&the_index, REFRESH_QUIET, pathspec, NULL, NULL);