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

Re: [PATCH v2 2/3] diff --submodule=diff: do not fail on ever-initialied deleted submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 31, 2021, 06:19 UTC
Message-ID
<xmqqsfyqxhk0.fsf@gitster.g>
In-Reply-To
<20210802170004.4103535-2-dturner@twosigma.com>
David Turner <dturner@twosigma.com> writes:
Show 25 quoted lines
> If you have ever initialized a submodule, open_submodule will open it.
> If you then delete the submodule's worktree directory (but don't
> remove it from .gitmodules), git diff --submodule=diff would error out
> as it attempted to chdir into the now-deleted working tree directory.
>
> Instead, we chdir into the submodule's git directory and run the diff
> from there.
>
> Signed-off-by: David Turner <dturner@twosigma.com>
> ---
>  submodule.c                                  |  10 ++
>  t/t4060-diff-submodule-option-diff-format.sh | 157 +++++++++++++++++++++++++--
>  2 files changed, 160 insertions(+), 7 deletions(-)
>
> diff --git a/submodule.c b/submodule.c
> index 0b1d9c1dde..d13d103975 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -710,6 +710,16 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
>  		strvec_push(&cp.args, oid_to_hex(new_oid));
>  
>  	prepare_submodule_repo_env(&cp.env_array);
> +
> +	if (!is_directory(path)) {
> +		// fall back to absorbed git dir, if any

I'll locally amend this comment style. If there is no other comments, that would be sufficient.

Show 9 quoted lines
> +		if (!sub)
> +			goto done;
> +		cp.dir = sub->gitdir;
> +		strvec_push(&cp.env_array, GIT_DIR_ENVIRONMENT "=.");
> +		strvec_push(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT "=.");
> +	}
> +
>  	if (start_command(&cp))
>  		diff_emit_submodule_error(o, "(diff failed)\n");
Previous: David TurnerNext: David Turner
Message 3 of 5 in “Remove unused var”
  1. 1/3 Remove unused varDavid Turner, Aug 2, 2021
  2. 2/3 diff --submodule=diff: do not fail on ever-initialied deleted submodulesDavid Turner, Aug 2, 2021
  3. Junio C HamanoAug 31, 2021
  4. 3/3 diff --submodule=diff: Don't print failure message twiceDavid Turner, Aug 2, 2021
  5. Junio C HamanoAug 31, 2021

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.