Re: [PATCH] submodule: prevent overwriting .gitmodules entry on path reuse
- From
JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com>
- Date
- May 10, 2025, 05:57 UTC
- Message-ID
- <CA+rGoLc=S44mHwc-ZpagwfAo=V-BjcX58HCaQDn1fBJcknQ4Vw@mail.gmail.com>
- In-Reply-To
- <20250510054542.556401-1-jayatheerthkulkarni2005@gmail.com>
Show 32 quoted lines
> +++ b/builtin/submodule--helper.c
> @@ -32,6 +32,8 @@
> #include "advice.h"
> #include "branch.h"
> #include "list-objects-filter-options.h"
> +#include "wildmatch.h"
> +
>
> #define OPT_QUIET (1 << 0)
> #define OPT_CACHED (1 << 1)
> @@ -3323,6 +3325,23 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con
> return ret;
> }
>
> +static int submodule_active_matches_path(const char *path)
> +{
> + const struct string_list *values;
> + size_t i;
> +
> + if (git_config_get_string_multi("submodule.active", &values))
> + return 0;
> +
> + for (i = 0; i < values->nr; i++) {
> + const char *pat = values->items[i].string;
> + if (!wildmatch(pat, path, 0))
> + return 1;
> + }
> +
> + return 0;
> +}
> +
>I added this change in the same patch because t7413 was throwing errors at these specific lines of code I don't really have full understanding of these files yet but after this t7413 perfectly passed all the tests
I tried these changed because there was a comment about this in the file
/* * NEEDSWORK: In a multi-working-tree world this needs to be * set in the per-worktree config. */ /* * NEEDSWORK: In the longer run, we need to get rid of this * pattern of querying "submodule.active" before calling * is_submodule_active(), since that function needs to find * out the value of "submodule.active" again anyway. */
I can separate it into different patches if there is a requirement. Or change based on the feedback.
-Jayatheerth