git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/1][RFC][GSoC] submodule: using 'is_writing_gitmodules_ok()' for a stricter check

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 13, 2020, 13:42 UTC
Message-ID
<nycvar.QRO.7.76.6.2002131435301.46@tvgsbejvaqbjf.bet>
In-Reply-To
<20200211170359.31835-2-shouryashukla.oo@gmail.com>
Hi Shourya,
On Tue, 11 Feb 2020, Shourya Shukla wrote:
Show 9 quoted lines
> The if conditions of the functions 'update_path_in_gitmodules()'
> and 'remove_path_from_gitmodules()' are not catering to every
> condition encountered by the function. On detailed observation,
> one can notice that .gitmodules cannot be changed (i.e. removal
> of a path or updation of a path) until these conditions are satisfied:
>
>     1. The file exists
>     2. The file, if it does not exist, should be absent from
>        the index and other branches as well.
I don't think that other branches matter in this context.
Show 7 quoted lines
>     3. There should not be any unmerged changes in the file.
>     4. The submodules do not exist or if the submodule name
>        does not match.
>
> Only the conditions 1, 3 and 4 were being satisfied earlier. Now
> on changing the if statement in one of the places, the condition
> 2 is satisfied as well.
Let's see how this is done...
Show 20 quoted lines
> Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
> ---
>  submodule.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/submodule.c b/submodule.c
> index 3a184b66ab..f7836a6851 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -107,7 +107,13 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
>  	const struct submodule *submodule;
>  	int ret;
>
> -	if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
> +	/* If .gitmodules file is not safe to write(update a path) i.e.
> +	 * if it does not exist or if it is not present in the working tree
> +	 * but lies in the index or in the current branch.
> +	 * The function 'is_writing_gitmodules_ok()' checks for the same.
> +	 * and exits with failure if above conditions are not satisfied
> +	*/
Style: we always begin and end multi-line comments with `/*` and `*/` on
their own line.
> +	if (is_writing_gitmodules_ok())
Hmm. This function is defined thusly:
int is_writing_gitmodules_ok(void)
{
	struct object_id oid;
	return file_exists(GITMODULES_FILE) ||
		(get_oid(GITMODULES_INDEX, &oid) < 0 && get_oid(GITMODULES_HEAD, &oid) < 0);
}

Aha! So this tries to ensure that the `.gitmodules` file exists on disk, or if it does not, then it should not exist in the index nor in the _current_ branch.

But we're in the function called `update_path_in_gitmodules()` which suggests that we're working on an existing, valid `.gitmodules`.

So I do not think that we can proceed if `.gitmodules` is absent from disk, even if in case that it is _also_ absent from the index and from the current branch.

Show 15 quoted lines
>  		return -1;
>
>  	if (is_gitmodules_unmerged(the_repository->index))
> @@ -136,7 +142,13 @@ int remove_path_from_gitmodules(const char *path)
>  	struct strbuf sect = STRBUF_INIT;
>  	const struct submodule *submodule;
>
> -	if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
> +	/* If .gitmodules file is not safe to write(remove a path) i.e.
> +	 * if it does not exist or if it is not present in the working tree
> +	 * but lies in the index or in the current branch.
> +	 * The function 'is_writing_gitmodules_ok()' checks for the same.
> +	 * and exits with failure if above conditions are not satisfied
> +	*/
> +	if (is_writing_gitmodules_ok())

Here, we want to remove a path from `.gitmodules`, so I think that the same analysis applies as above.

In other words, I think that the existing code is correct and does not need to be patched.

Ciao, Johannes

Show 7 quoted lines
>  		return -1;
>
>  	if (is_gitmodules_unmerged(the_repository->index))
> --
> 2.20.1
>
>
Previous: Shourya ShuklaNext: Shourya Shukla
Message 3 of 5 in “[RFC][GSoC] submodule: enforcing stricter checks”
  1. 0/1 [RFC][GSoC] submodule: enforcing stricter checksShourya Shukla, Feb 11, 2020
  2. 1/1 [RFC][GSoC] submodule: using 'is_writing_gitmodules_ok()' for a stricter checkShourya Shukla, Feb 11, 2020
  3. Johannes SchindelinFeb 13, 2020
  4. Shourya ShuklaFeb 13, 2020
  5. Johannes SchindelinFeb 14, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.