git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Michael McClimon <michael@mcclimon.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/1] Git.pm: add semicolon after catch statement
Date: Sun, 16 Oct 2022 19:18:34 -0400	[thread overview]
Message-ID: <Y0yRStZ6gM+H8/Bf@coredump.intra.peff.net> (raw)
In-Reply-To: <20221016212236.12453-2-michael@mcclimon.org>

On Sun, Oct 16, 2022 at 05:22:36PM -0400, Michael McClimon wrote:

> When attempting to initialize a repository object in an unsafe
> directory, a syntax error is reported (Can't use string as a HASH ref
> while strict refs in use). Fix this runtime error by adding the required
> semicolon after the catch statement.
> 
> Without the semicolon, the result of the following line (i.e., the
> result of Cwd::abs_path) is passed as the third argument to Error.pm's
> catch function. That function expects that its third argument,
> $clauses, is a hash reference, and trying to access a string as a hash
> reference is a fatal error.

Curiously this works as expected for me, both before and after your
patch. I wonder if it depends on perl version. Mine is 5.34.

I've never used Error.pm's try/catch before, so I don't know what's
normal. Regular if/unless doesn't need it, but certainly an earlier
catch uses a semicolon. So it seems like a reasonable fix.

> diff --git a/perl/Git.pm b/perl/Git.pm
> index 080cdc2a..cf15ead6 100644
> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -217,7 +217,7 @@ sub repository {
>  			} catch Git::Error::Command with {
>  				# Mimic git-rev-parse --git-dir error message:
>  				throw Error::Simple("fatal: Not a git repository: $dir");
> -			}
> +			};

I'd assume t9700 passes for you, since I don't think we cover this case.
Maybe it's worth squashing this in:

diff --git a/t/t9700/test.pl b/t/t9700/test.pl
index e046f7db76..5bd3687f37 100755
--- a/t/t9700/test.pl
+++ b/t/t9700/test.pl
@@ -30,6 +30,12 @@ sub adjust_dirsep {
 # set up
 our $abs_repo_dir = cwd();
 ok(our $r = Git->repository(Directory => "."), "open repository");
+{
+	local $ENV{GIT_TEST_ASSUME_DIFFERENT_OWNER} = 1;
+	my $failed = eval { Git->repository(Directory => ".") };
+	ok(!$failed, "reject unsafe repository");
+	like($@, qr/not a git repository/i, "unsafe error message");
+}
 
 # config
 is($r->config("test.string"), "value", "config scalar: string");

  reply	other threads:[~2022-10-16 23:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16 21:22 [PATCH 0/1] Git.pm: add semicolon after catch statement Michael McClimon
2022-10-16 21:22 ` [PATCH 1/1] " Michael McClimon
2022-10-16 23:18   ` Jeff King [this message]
2022-10-17  2:17     ` Michael McClimon
2022-10-17 17:34       ` Jeff King
2022-10-18  1:39         ` Michael McClimon
2022-11-10 15:10         ` Johannes Schindelin
2022-11-10 21:41           ` Jeff King
2022-10-22  1:19 ` [PATCH v2 0/2] Fix behavior of Git.pm in unsafe bare repositories Michael McClimon
2022-10-22  1:19   ` [PATCH v2 1/2] Git.pm: add semicolon after catch statement Michael McClimon
2022-10-22  1:19   ` [PATCH v2 2/2] setup: allow Git.pm to do unsafe repo checking Michael McClimon
2022-10-22  5:29     ` Junio C Hamano
2022-10-22 21:18       ` Jeff King
2022-10-22 23:17         ` Junio C Hamano
2022-10-22 19:45     ` Ævar Arnfjörð Bjarmason
2022-10-22 20:55       ` Jeff King
2022-10-24 10:57         ` Ævar Arnfjörð Bjarmason
2022-10-24 23:38           ` Jeff King
2022-10-22 21:16     ` Jeff King
2022-10-22 22:08       ` Jeff King
2022-10-22 23:19         ` Michael McClimon
2022-10-24 23:33           ` Jeff King
2022-10-22 23:14       ` 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=Y0yRStZ6gM+H8/Bf@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=michael@mcclimon.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).