| 3907 | } |
| 3908 | |
| 3909 | static int skip_submodule(const char *path, |
| 3910 | struct repository *repo, |
| 3911 | struct pathspec *pathspec, |
| 3912 | int ignored_too) |
| 3913 | { |
| 3914 | struct stat st; |
| 3915 | const struct submodule *sub; |
| 3916 | int pathspec_matches = 0; |
| 3917 | int ps_i; |
| 3918 | char *norm_pathspec = NULL; |
| 3919 | |
| 3920 | /* Only consider if path is a directory */ |
| 3921 | if (lstat(path, &st) || !S_ISDIR(st.st_mode)) |
| 3922 | return 0; |
| 3923 | |
| 3924 | /* Check if it's a submodule with ignore=all */ |
| 3925 | sub = submodule_from_path(repo, null_oid(the_hash_algo), path); |
| 3926 | if (!sub || !sub->name || !sub->ignore || strcmp(sub->ignore, "all")) |
| 3927 | return 0; |
| 3928 | |
| 3929 | trace_printf("ignore=all: %s\n", path); |
| 3930 | trace_printf("pathspec %s\n", (pathspec && pathspec->nr) |
| 3931 | ? "has pathspec" |
| 3932 | : "no pathspec"); |
| 3933 | |
| 3934 | /* Check if submodule path is explicitly mentioned in pathspec */ |
| 3935 | if (pathspec) { |
| 3936 | for (ps_i = 0; ps_i < pathspec->nr; ps_i++) { |
| 3937 | const char *m = pathspec->items[ps_i].match; |
| 3938 | if (!m) |
| 3939 | continue; |
| 3940 | norm_pathspec = xstrdup(m); |
| 3941 | strip_dir_trailing_slashes(norm_pathspec); |
| 3942 | if (!strcmp(path, norm_pathspec)) { |
| 3943 | pathspec_matches = 1; |
| 3944 | FREE_AND_NULL(norm_pathspec); |
| 3945 | break; |
| 3946 | } |
| 3947 | FREE_AND_NULL(norm_pathspec); |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | /* If explicitly matched and forced, allow adding */ |
| 3952 | if (pathspec_matches) { |
| 3953 | if (ignored_too && ignored_too > 0) { |
| 3954 | trace_printf("Add submodule due to --force: %s\n", path); |
| 3955 | return 0; |
| 3956 | } else { |
| 3957 | advise_if_enabled(ADVICE_ADD_IGNORED_FILE, |
| 3958 | _("Skipping submodule due to ignore=all: %s\n" |
| 3959 | "Use --force if you really want to add the submodule."), path); |
| 3960 | return 1; |
| 3961 | } |
| 3962 | } |
| 3963 | |
| 3964 | /* No explicit pathspec match -> skip silently */ |
| 3965 | trace_printf("Pathspec to submodule does not match explicitly: %s\n", path); |
| 3966 | return 1; |
no test coverage detected