Skip to content

Commit

Permalink
Merge branch 'js/git-submodule-trailing-slash'
Browse files Browse the repository at this point in the history
* js/git-submodule-trailing-slash:
  submodule: warn about non-submodules
  Let ls-files strip trailing slashes in submodules' paths
  • Loading branch information
Junio C Hamano committed Feb 11, 2009
2 parents 6e5d7dd + 496917b commit 8c55149
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
21 changes: 20 additions & 1 deletion builtin-ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resolve_relative_url ()
#
module_list()
{
git ls-files --stage -- "$@" | grep '^160000 '
git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
}

#
Expand Down
13 changes: 13 additions & 0 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8c55149

Please sign in to comment.