From bdab972153a73815e04e9699406433e409ed28ab Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 9 May 2017 12:17:59 -0700 Subject: submodule: add die_in_unpopulated_submodule function Currently 'git add' is the only command which dies when launched from an unpopulated submodule (the place-holder directory for a submodule which hasn't been checked out). This is triggered implicitly by passing the PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag to 'parse_pathspec()'. Instead make this desire more explicit by creating a function 'die_in_unpopulated_submodule()' which dies if the provided 'prefix' has a leading path component which matches a submodule in the the index. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin/add.c') diff --git a/builtin/add.c b/builtin/add.c index 9f53f020d0..ec58e36796 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -17,6 +17,7 @@ #include "revision.h" #include "bulk-checkin.h" #include "argv-array.h" +#include "submodule.h" static const char * const builtin_add_usage[] = { N_("git add [] [--] ..."), @@ -379,6 +380,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (read_cache() < 0) die(_("index file corrupt")); + die_in_unpopulated_submodule(&the_index, prefix); + /* * Check the "pathspec '%s' did not match any files" block * below before enabling new magic. -- cgit v1.2.1 From c08397e3aa46fd0f0da29dfe5b257839b9c5d1c8 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:24 -0700 Subject: pathspec: remove PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag Since (ae8d08242 pathspec: pass directory indicator to match_pathspec_item()) the path matching logic has been able to cope with submodules without needing to strip off a trailing slash if a path refers to a submodule. Since the stripping the trailing slash is no longer necessary, remove the PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE flag. In addition, factor out the logic which dies if a path decends into a submodule so that it can still be used as a check after a pathspec struct has been initialized. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'builtin/add.c') diff --git a/builtin/add.c b/builtin/add.c index ec58e36796..86770d6af4 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -388,10 +388,11 @@ int cmd_add(int argc, const char **argv, const char *prefix) */ parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_FULL | - PATHSPEC_SYMLINK_LEADING_PATH | - PATHSPEC_STRIP_SUBMODULE_SLASH_EXPENSIVE, + PATHSPEC_SYMLINK_LEADING_PATH, prefix, argv); + die_path_inside_submodule(&the_index, &pathspec); + if (add_new_files) { int baselen; -- cgit v1.2.1 From 08de9151a8a67f29a3a5a36931298237d78ca736 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 11 May 2017 15:04:27 -0700 Subject: pathspec: convert find_pathspecs_matching_against_index to take an index Convert find_pathspecs_matching_against_index to take an index parameter. In addition mark pathspec.c with NO_THE_INDEX_COMPATIBILITY_MACROS now that it doesn't use any cache macros or reference 'the_index'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/add.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin/add.c') diff --git a/builtin/add.c b/builtin/add.c index 86770d6af4..0365a52098 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -136,7 +136,7 @@ static char *prune_directory(struct dir_struct *dir, struct pathspec *pathspec, *dst++ = entry; } dir->nr = dst - dir->entries; - add_pathspec_matches_against_index(pathspec, seen); + add_pathspec_matches_against_index(pathspec, &the_index, seen); return seen; } @@ -418,7 +418,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int i; if (!seen) - seen = find_pathspecs_matching_against_index(&pathspec); + seen = find_pathspecs_matching_against_index(&pathspec, &the_index); /* * file_exists() assumes exact match -- cgit v1.2.1