Merge branch 'jk/trailing-slash-in-pathspec'
authorJunio C Hamano <gitster@pobox.com>
Thu, 17 Oct 2013 22:55:13 +0000 (15:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Oct 2013 22:55:14 +0000 (15:55 -0700)
Code refactoring.

* jk/trailing-slash-in-pathspec:
reset: handle submodule with trailing slash
rm: re-use parse_pathspec's trailing-slash removal

builtin/reset.c
builtin/rm.c
t/t7400-submodule-basic.sh
index 1a5344877212e675d685055a631aba2ac0a4c661..f2f9d55392d2193432d5a572a70cd27afcf6b136 100644 (file)
@@ -143,7 +143,6 @@ static int read_from_tree(const struct pathspec *pathspec,
        opt.output_format = DIFF_FORMAT_CALLBACK;
        opt.format_callback = update_index_from_diff;
 
-       read_cache();
        if (do_diff_cache(tree_sha1, &opt))
                return 1;
        diffcore_std(&opt);
@@ -169,7 +168,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
 
 static void die_if_unmerged_cache(int reset_type)
 {
-       if (is_merge() || read_cache() < 0 || unmerged_cache())
+       if (is_merge() || unmerged_cache())
                die(_("Cannot do a %s reset in the middle of a merge."),
                    _(reset_type_names[reset_type]));
 
@@ -220,8 +219,13 @@ static void parse_args(struct pathspec *pathspec,
                }
        }
        *rev_ret = rev;
+
+       if (read_cache() < 0)
+               die(_("index file corrupt"));
+
        parse_pathspec(pathspec, 0,
                       PATHSPEC_PREFER_FULL |
+                      PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP |
                       (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
                       prefix, argv);
 }
index 9b59ab3a64e00cfe3a6a73d6493001085c31d683..3a0e0eaab7d1fd8a298bb2519776abede5c685e2 100644 (file)
@@ -298,22 +298,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
        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);
-               }
-       }
-
-       parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
+       parse_pathspec(&pathspec, 0,
+                      PATHSPEC_PREFER_CWD |
+                      PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
+                      prefix, argv);
        refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
 
        seen = xcalloc(pathspec.nr, 1);
index 10f89bd0ce3656a1dee841d19582e5d1bfc9736a..c28e8d8ada68f37bc0090e07f7baf21c17c2de0b 100755 (executable)
@@ -481,7 +481,7 @@ test_expect_success 'do not add files from a submodule' '
 
 '
 
-test_expect_success 'gracefully add submodule with a trailing slash' '
+test_expect_success 'gracefully add/reset submodule with a trailing slash' '
 
        git reset --hard &&
        git commit -m "commit subproject" init &&
@@ -495,7 +495,9 @@ test_expect_success 'gracefully add submodule with a trailing slash' '
        git add init/ &&
        test_must_fail git diff --exit-code --cached init &&
        test $commit = $(git ls-files --stage |
-               sed -n "s/^160000 \([^ ]*\).*/\1/p")
+               sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
+       git reset init/ &&
+       git diff --exit-code --cached init
 
 '