|
48 | 48 | #include "csum-file.h" |
49 | 49 | #include "promisor-remote.h" |
50 | 50 | #include "hook.h" |
| 51 | +#include "submodule.h" |
| 52 | +#include "submodule-config.h" |
51 | 53 |
|
52 | 54 | /* Mask for the name length in ce_flags in the on-disk index */ |
53 | 55 |
|
@@ -3928,6 +3930,47 @@ static void update_callback(struct diff_queue_struct *q, |
3928 | 3930 | die(_("unexpected diff status %c"), p->status); |
3929 | 3931 | case DIFF_STATUS_MODIFIED: |
3930 | 3932 | case DIFF_STATUS_TYPE_CHANGED: |
| 3933 | + struct stat st; |
| 3934 | + if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory |
| 3935 | + const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path); |
| 3936 | + if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) { |
| 3937 | + int pathspec_matches = 0; |
| 3938 | + char *norm_pathspec = NULL; |
| 3939 | + int ps_i; |
| 3940 | + trace_printf("ignore=all %s\n", path); |
| 3941 | + trace_printf("pathspec %s\n", |
| 3942 | + (data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec"); |
| 3943 | + /* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */ |
| 3944 | + if (data->pathspec) { |
| 3945 | + for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) { |
| 3946 | + const char *m = data->pathspec->items[ps_i].match; |
| 3947 | + if (!m) |
| 3948 | + continue; |
| 3949 | + norm_pathspec = xstrdup(m); |
| 3950 | + strip_dir_trailing_slashes(norm_pathspec); |
| 3951 | + if (!strcmp(path, norm_pathspec)) { |
| 3952 | + pathspec_matches = 1; |
| 3953 | + FREE_AND_NULL(norm_pathspec); |
| 3954 | + break; |
| 3955 | + } |
| 3956 | + FREE_AND_NULL(norm_pathspec); |
| 3957 | + } |
| 3958 | + } |
| 3959 | + if (pathspec_matches) { |
| 3960 | + if (data->ignored_too && data->ignored_too > 0) { |
| 3961 | + trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path); |
| 3962 | + } else { |
| 3963 | + printf(_("Skipping submodule due to ignore=all: %s"), path); |
| 3964 | + printf(_("Use -f if you really want to add them.") ); |
| 3965 | + continue; |
| 3966 | + } |
| 3967 | + } else { |
| 3968 | + /* No explicit pathspec match -> skip silently (or with trace). */ |
| 3969 | + trace_printf("pathspec does not match %s\n", path); |
| 3970 | + continue; |
| 3971 | + } |
| 3972 | + } |
| 3973 | + } |
3931 | 3974 | if (add_file_to_index(data->index, path, data->flags)) { |
3932 | 3975 | if (!(data->flags & ADD_CACHE_IGNORE_ERRORS)) |
3933 | 3976 | die(_("updating files failed")); |
|
0 commit comments