Let ls-files strip trailing slashes in submodules' paths
Tab completion makes it easy to add a trailing slash to a submodule path. As it is completely clear what the user actually wanted to say, be nice and strip that slash at the end. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
621f1b4bcf
commit
f3670a5749
|
@ -262,6 +262,21 @@ static const char *verify_pathspec(const char *prefix)
|
||||||
return max ? xmemdupz(prev, max) : NULL;
|
return max ? xmemdupz(prev, max) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void strip_trailing_slash_from_submodules(void)
|
||||||
|
{
|
||||||
|
const char **p;
|
||||||
|
|
||||||
|
for (p = pathspec; *p != NULL; p++) {
|
||||||
|
int len = strlen(*p), pos;
|
||||||
|
|
||||||
|
if (len < 1 || (*p)[len - 1] != '/')
|
||||||
|
continue;
|
||||||
|
pos = cache_name_pos(*p, len - 1);
|
||||||
|
if (pos >= 0 && S_ISGITLINK(active_cache[pos]->ce_mode))
|
||||||
|
*p = xstrndup(*p, len - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the tree specified with --with-tree option
|
* Read the tree specified with --with-tree option
|
||||||
* (typically, HEAD) into stage #1 and then
|
* (typically, HEAD) into stage #1 and then
|
||||||
|
@ -510,6 +525,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
pathspec = get_pathspec(prefix, argv + i);
|
pathspec = get_pathspec(prefix, argv + i);
|
||||||
|
|
||||||
|
/* be nice with submodule patsh ending in a slash */
|
||||||
|
read_cache();
|
||||||
|
if (pathspec)
|
||||||
|
strip_trailing_slash_from_submodules();
|
||||||
|
|
||||||
/* Verify that the pathspec matches the prefix */
|
/* Verify that the pathspec matches the prefix */
|
||||||
if (pathspec)
|
if (pathspec)
|
||||||
prefix = verify_pathspec(prefix);
|
prefix = verify_pathspec(prefix);
|
||||||
|
@ -533,7 +553,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
|
||||||
show_killed | show_modified))
|
show_killed | show_modified))
|
||||||
show_cached = 1;
|
show_cached = 1;
|
||||||
|
|
||||||
read_cache();
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
prune_cache(prefix);
|
prune_cache(prefix);
|
||||||
if (with_tree) {
|
if (with_tree) {
|
||||||
|
|
|
@ -234,4 +234,10 @@ test_expect_success 'gracefully add submodule with a trailing slash' '
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-files gracefully handles trailing slash' '
|
||||||
|
|
||||||
|
test "init" = "$(git ls-files init/)"
|
||||||
|
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue