From: Junio C Hamano <gitster@pobox.com>
To: David Turner <dturner@twosigma.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] diff --submodule=diff: do not fail on ever-initialied deleted submodules
Date: Mon, 26 Jul 2021 15:57:27 -0700 [thread overview]
Message-ID: <xmqqv94wfzu0.fsf@gitster.g> (raw)
In-Reply-To: <20210726183358.3255233-2-dturner@twosigma.com> (David Turner's message of "Mon, 26 Jul 2021 14:33:57 -0400")
David Turner <dturner@twosigma.com> writes:
> 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 crash as
> it attempted to chdir into the now-deleted working tree directory.
Hmph. So what does the failure look like? The child process inside
start_command() attempts chdir() and reports CHILD_ERR_CHDIR back,
and we catch it as an error by reading from notify_pipe[0] and report
failure from start_command()? Or are we talking about a more severe
"crash" of an uncontrolled kind?
Bypassing the execution of diff in the submodule like this patch
does may avoid such a failure, but is that all we need to "fix" this
issue? What does the user expect after removing a submodule that
way and runs "diff" with the "--submodule=diff" option? Shouldn't
we be giving "all lines from all files have been removed" patch?
Thanks.
> Signed-off-by: David Turner <dturner@twosigma.com>
> ---
> submodule.c | 3 ++
> t/t4060-diff-submodule-option-diff-format.sh | 45 ++++++++++++++++++++++++----
> 2 files changed, 43 insertions(+), 5 deletions(-)
>
> diff --git a/submodule.c b/submodule.c
> index 0b1d9c1dde..9031527a16 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -673,6 +673,9 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
> !(right || is_null_oid(two)))
> goto done;
>
> + if (!is_directory(path))
> + goto done;
> +
> if (left)
> old_oid = one;
> if (right)
> diff --git a/t/t4060-diff-submodule-option-diff-format.sh b/t/t4060-diff-submodule-option-diff-format.sh
> index 69b9946931..10e330c08a 100755
> --- a/t/t4060-diff-submodule-option-diff-format.sh
> +++ b/t/t4060-diff-submodule-option-diff-format.sh
> @@ -703,10 +703,26 @@ test_expect_success 'path filter' '
> diff_cmp expected actual
> '
>
> -commit_file sm2
> +cat >.gitmodules <<-EOF
> +[submodule "sm2"]
> + path = sm2
> + url = bogus_url
> +EOF
> +git add .gitmodules
> +commit_file sm2 .gitmodules
> +
> test_expect_success 'given commit' '
> git diff-index -p --submodule=diff HEAD^ >actual &&
> cat >expected <<-EOF &&
> + diff --git a/.gitmodules b/.gitmodules
> + new file mode 100644
> + index 1234567..89abcde
> + --- /dev/null
> + +++ b/.gitmodules
> + @@ -0,0 +1,3 @@
> + +[submodule "sm2"]
> + +path = sm2
> + +url = bogus_url
> Submodule sm1 $head7...0000000 (submodule deleted)
> Submodule sm2 0000000...$head9 (new submodule)
> diff --git a/sm2/foo8 b/sm2/foo8
> @@ -728,15 +744,21 @@ test_expect_success 'given commit' '
> '
>
> test_expect_success 'setup .git file for sm2' '
> - (cd sm2 &&
> - REAL="$(pwd)/../.real" &&
> - mv .git "$REAL" &&
> - echo "gitdir: $REAL" >.git)
> + git submodule absorbgitdirs sm2
> '
>
> test_expect_success 'diff --submodule=diff with .git file' '
> git diff --submodule=diff HEAD^ >actual &&
> cat >expected <<-EOF &&
> + diff --git a/.gitmodules b/.gitmodules
> + new file mode 100644
> + index 1234567..89abcde
> + --- /dev/null
> + +++ b/.gitmodules
> + @@ -0,0 +1,3 @@
> + +[submodule "sm2"]
> + +path = sm2
> + +url = bogus_url
> Submodule sm1 $head7...0000000 (submodule deleted)
> Submodule sm2 0000000...$head9 (new submodule)
> diff --git a/sm2/foo8 b/sm2/foo8
> @@ -757,6 +779,19 @@ test_expect_success 'diff --submodule=diff with .git file' '
> diff_cmp expected actual
> '
>
> +mv sm2 sm2-bak
> +
> +test_expect_success 'deleted submodule with .git file' '
> + git diff-index -p --submodule=diff HEAD >actual &&
> + cat >expected <<-EOF &&
> + Submodule sm1 $head7...0000000 (submodule deleted)
> + Submodule sm2 $head9...0000000 (submodule deleted)
> + EOF
> + diff_cmp expected actual
> +'
> +
> +mv sm2-bak sm2
> +
> test_expect_success 'setup nested submodule' '
> git submodule add -f ./sm2 &&
> git commit -a -m "add sm2" &&
next prev parent reply other threads:[~2021-07-26 22:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-26 18:33 [PATCH 1/3] Remove unused var David Turner
2021-07-26 18:33 ` [PATCH 2/3] diff --submodule=diff: do not fail on ever-initialied deleted submodules David Turner
2021-07-26 22:57 ` Junio C Hamano [this message]
2021-07-27 17:35 ` David Turner
2021-08-31 6:17 ` Junio C Hamano
2021-08-31 13:12 ` [PATCH v4 1/3] Remove unused var David Turner
2021-08-31 13:12 ` [PATCH v4 2/3] diff --submodule=diff: do not fail on ever-initialied deleted submodules David Turner
2021-08-31 13:12 ` [PATCH v4 3/3] diff --submodule=diff: Don't print failure message twice David Turner
2021-08-31 17:16 ` [PATCH v4 1/3] Remove unused var Junio C Hamano
2021-07-26 18:33 ` [PATCH 3/3] diff --submodule=diff: Don't print failure message twice David Turner
2021-07-26 22:47 ` Junio C Hamano
2021-07-26 22:47 ` [PATCH 1/3] Remove unused var Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqv94wfzu0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=dturner@twosigma.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).