diff options
author | Junio C Hamano <gitster@pobox.com> | 2009-02-10 21:31:08 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-02-10 21:31:08 -0800 |
commit | 8c5514906a532f154aa0db1199f46bbdeeffb0ad (patch) | |
tree | 1485160c77cf35751367c5966023ddcecd116154 | |
parent | 6e5d7ddc490fc7fdf46a5d0af35aa6fd64ae4a96 (diff) | |
parent | 496917b721adae11e596cd44b13cb8a49c388de7 (diff) | |
download | git-8c5514906a532f154aa0db1199f46bbdeeffb0ad.tar.gz git-8c5514906a532f154aa0db1199f46bbdeeffb0ad.tar.xz |
Merge branch 'js/git-submodule-trailing-slash'
* js/git-submodule-trailing-slash:
submodule: warn about non-submodules
Let ls-files strip trailing slashes in submodules' paths
-rw-r--r-- | builtin-ls-files.c | 21 | ||||
-rwxr-xr-x | git-submodule.sh | 2 | ||||
-rwxr-xr-x | t/t7400-submodule-basic.sh | 13 |
3 files changed, 34 insertions, 2 deletions
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) { diff --git a/git-submodule.sh b/git-submodule.sh index 2f47e065f..6cc2d334c 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -59,7 +59,7 @@ resolve_relative_url () # module_list() { - git ls-files --stage -- "$@" | grep '^160000 ' + git ls-files --error-unmatch --stage -- "$@" | grep '^160000 ' } # diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ec7ac6a5..b8cb2df66 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -234,4 +234,17 @@ 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_expect_success 'submodule <invalid-path> warns' ' + + git submodule no-such-submodule 2> output.err && + grep "^error: .*no-such-submodule" output.err + +' + test_done |