Skip to content

Commit be98d91

Browse files
committed
Merge branch 'jk/trailing-slash-in-pathspec'
Code refactoring. * jk/trailing-slash-in-pathspec: reset: handle submodule with trailing slash rm: re-use parse_pathspec's trailing-slash removal
2 parents f52752d + 2c63d6e commit be98d91

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

builtin/reset.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ static int read_from_tree(const struct pathspec *pathspec,
143143
opt.output_format = DIFF_FORMAT_CALLBACK;
144144
opt.format_callback = update_index_from_diff;
145145

146-
read_cache();
147146
if (do_diff_cache(tree_sha1, &opt))
148147
return 1;
149148
diffcore_std(&opt);
@@ -169,7 +168,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
169168

170169
static void die_if_unmerged_cache(int reset_type)
171170
{
172-
if (is_merge() || read_cache() < 0 || unmerged_cache())
171+
if (is_merge() || unmerged_cache())
173172
die(_("Cannot do a %s reset in the middle of a merge."),
174173
_(reset_type_names[reset_type]));
175174

@@ -220,8 +219,13 @@ static void parse_args(struct pathspec *pathspec,
220219
}
221220
}
222221
*rev_ret = rev;
222+
223+
if (read_cache() < 0)
224+
die(_("index file corrupt"));
225+
223226
parse_pathspec(pathspec, 0,
224227
PATHSPEC_PREFER_FULL |
228+
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP |
225229
(patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
226230
prefix, argv);
227231
}

builtin/rm.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
298298
if (read_cache() < 0)
299299
die(_("index file corrupt"));
300300

301-
/*
302-
* Drop trailing directory separators from directories so we'll find
303-
* submodules in the index.
304-
*/
305-
for (i = 0; i < argc; i++) {
306-
size_t pathlen = strlen(argv[i]);
307-
if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
308-
is_directory(argv[i])) {
309-
do {
310-
pathlen--;
311-
} while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
312-
argv[i] = xmemdupz(argv[i], pathlen);
313-
}
314-
}
315-
316-
parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
301+
parse_pathspec(&pathspec, 0,
302+
PATHSPEC_PREFER_CWD |
303+
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
304+
prefix, argv);
317305
refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
318306

319307
seen = xcalloc(pathspec.nr, 1);

t/t7400-submodule-basic.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ test_expect_success 'do not add files from a submodule' '
481481
482482
'
483483

484-
test_expect_success 'gracefully add submodule with a trailing slash' '
484+
test_expect_success 'gracefully add/reset submodule with a trailing slash' '
485485
486486
git reset --hard &&
487487
git commit -m "commit subproject" init &&
@@ -495,7 +495,9 @@ test_expect_success 'gracefully add submodule with a trailing slash' '
495495
git add init/ &&
496496
test_must_fail git diff --exit-code --cached init &&
497497
test $commit = $(git ls-files --stage |
498-
sed -n "s/^160000 \([^ ]*\).*/\1/p")
498+
sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
499+
git reset init/ &&
500+
git diff --exit-code --cached init
499501
500502
'
501503

0 commit comments

Comments
 (0)