X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-ls-files.c;h=9dec282fba6ba22e37d13bdc5e35fa4a031433b5;hb=1d4e4cd4a108dc105f6c8e739c69b9261d4e92a5;hp=34340312953867fdcb4ae62d530bdae3162744a5;hpb=ed096c4a23476810831e12d2e9227403c21bd774;p=git.git diff --git a/builtin-ls-files.c b/builtin-ls-files.c index 343403129..9dec282fb 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -262,6 +262,21 @@ static const char *verify_pathspec(const char *prefix) 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 * (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); + /* 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 */ if (pathspec) 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_cached = 1; - read_cache(); if (prefix) prune_cache(prefix); if (with_tree) {