From: "Martin Ågren" <martin.agren@gmail.com>
To: ks1322 ks1322 <ks1322@gmail.com>
Cc: git@vger.kernel.org, Victoria Dye <vdye@github.com>
Subject: [PATCH] diagnose: require repository
Date: Sat, 14 Oct 2023 15:53:01 +0200 [thread overview]
Message-ID: <20231014135302.13095-1-martin.agren@gmail.com> (raw)
In-Reply-To: <CAKFQ_Q9WjF9i-Rx2jdCw-adPVQrWNfNKrDY-em8Rpa5RNLXz4A@mail.gmail.com>
When `git diagnose` is run from outside a repo, it begins collecting
various information before eventually hitting a segmentation fault,
leaving an incomplete zip file behind.
Switch from the gentle setup to requiring a git directory. Without a git
repo, there isn't really much to diagnose.
We could possibly do a best-effort collection of information about the
machine and then give up. That would roughly be today's behavior but
with a controlled exit rather than a segfault. However, the purpose of
this tool is largely to create a zip archive. Rather than creating an
empty zip file or no zip file at all, and having to explain that
behavior, it seems more helpful to bail out clearly and early with a
succinct error message.
Reported-by: ks1322 ks1322 <ks1322@gmail.com>
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
Thanks for the report. This could be one way of fixing this.
I haven't found anything in the original submission [1] discussing this
"_GENTLY". I didn't see anything in the implementation or the tests
suggesting that it was intentional to run outside a git repo.
[1] https://lore.kernel.org/git/xmqqzgg1nz6v.fsf@gitster.g/t/#mc66904caab6bc79e57eaf5063df268b2725b6fcc
t/t0092-diagnose.sh | 5 +++++
git.c | 2 +-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/t/t0092-diagnose.sh b/t/t0092-diagnose.sh
index 133e5747d6..49671d35a2 100755
--- a/t/t0092-diagnose.sh
+++ b/t/t0092-diagnose.sh
@@ -5,6 +5,11 @@ test_description='git diagnose'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
+test_expect_success 'nothing to diagnose without repo' '
+ nongit test_must_fail git diagnose 2>err &&
+ grep "not a git repository" err
+'
+
test_expect_success UNZIP 'creates diagnostics zip archive' '
test_when_finished rm -rf report &&
diff --git a/git.c b/git.c
index c67e44dd82..ff04a74bbd 100644
--- a/git.c
+++ b/git.c
@@ -525,7 +525,7 @@ static struct cmd_struct commands[] = {
{ "credential-cache--daemon", cmd_credential_cache_daemon },
{ "credential-store", cmd_credential_store },
{ "describe", cmd_describe, RUN_SETUP },
- { "diagnose", cmd_diagnose, RUN_SETUP_GENTLY },
+ { "diagnose", cmd_diagnose, RUN_SETUP },
{ "diff", cmd_diff, NO_PARSEOPT },
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
{ "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
--
2.42.0.399.g85a82e71e0
next prev parent reply other threads:[~2023-10-14 13:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-14 11:59 Bug: git diagnose crashes with Segmentation fault outside of git repository ks1322 ks1322
2023-10-14 13:53 ` Martin Ågren [this message]
2023-10-14 14:56 ` [PATCH] diagnose: require repository Kristoffer Haugsbakk
2023-10-14 17:15 ` Junio C Hamano
2023-10-19 13:18 ` Martin Ågren
2023-10-19 18:09 ` Junio C Hamano
2023-10-19 18:16 ` Victoria Dye
2023-10-14 17:22 ` Bug: git diagnose crashes with Segmentation fault outside of git repository Christian Couder
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231014135302.13095-1-martin.agren@gmail.com \
--to=martin.agren@gmail.com \
--cc=git@vger.kernel.org \
--cc=ks1322@gmail.com \
--cc=vdye@github.com \
/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.
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 NNTP newsgroup(s).