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

1  2 
builtin/reset.c
t/t7400-submodule-basic.sh
diff --combined builtin/reset.c
index 1a5344877212e675d685055a631aba2ac0a4c661,800117f4f3685d9c333892fcae7332d1dff3208a..f2f9d55392d2193432d5a572a70cd27afcf6b136
@@@ -143,7 -143,6 +143,6 @@@ static int read_from_tree(const struct 
        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 +168,7 @@@ static void set_reflog_message(struct s
  
  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,13 -219,18 +219,18 @@@ static void parse_args(struct 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);
  }
  
 -static int update_refs(const char *rev, const unsigned char *sha1)
 +static int reset_refs(const char *rev, const unsigned char *sha1)
  {
        int update_ref_status;
        struct strbuf msg = STRBUF_INIT;
@@@ -330,14 -334,11 +334,14 @@@ int cmd_reset(int argc, const char **ar
                die_if_unmerged_cache(reset_type);
  
        if (reset_type != SOFT) {
 -              struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
 +              struct lock_file *lock = xcalloc(1, sizeof(*lock));
                int newfd = hold_locked_index(lock, 1);
                if (reset_type == MIXED) {
 +                      int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
                        if (read_from_tree(&pathspec, sha1))
                                return 1;
 +                      refresh_index(&the_index, flags, NULL, NULL,
 +                                    _("Unstaged changes after reset:"));
                } else {
                        int err = reset_index(sha1, reset_type, quiet);
                        if (reset_type == KEEP && !err)
                                die(_("Could not reset index file to revision '%s'."), rev);
                }
  
 -              if (reset_type == MIXED) { /* Report what has not been updated. */
 -                      int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
 -                      refresh_index(&the_index, flags, NULL, NULL,
 -                                    _("Unstaged changes after reset:"));
 -              }
 -
                if (write_cache(newfd, active_cache, active_nr) ||
                    commit_locked_index(lock))
                        die(_("Could not write new index file."));
        if (!pathspec.nr && !unborn) {
                /* Any resets without paths update HEAD to the head being
                 * switched to, saving the previous head in ORIG_HEAD before. */
 -              update_ref_status = update_refs(rev, sha1);
 +              update_ref_status = reset_refs(rev, sha1);
  
                if (reset_type == HARD && !update_ref_status && !quiet)
                        print_new_head_line(lookup_commit_reference(sha1));
index 10f89bd0ce3656a1dee841d19582e5d1bfc9736a,c268d3c9a2838105703daeeb89c68b10d5c71b04..c28e8d8ada68f37bc0090e07f7baf21c17c2de0b
@@@ -481,7 -481,7 +481,7 @@@ test_expect_success 'do not add files f
  
  '
  
- 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 &&
        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
  
  '
  
@@@ -962,6 -964,7 +964,6 @@@ test_expect_success 'submodule with UTF
                git add sub &&
                git commit -m "init sub"
        ) &&
 -      test_config core.precomposeunicode true &&
        git submodule add ./"$svname" &&
        git submodule >&2 &&
        test -n "$(git submodule | grep "$svname")"