git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t1517: more coverage for commands that work without repository
@ 2024-05-30 16:58 Junio C Hamano
  2024-05-31  8:43 ` [PATCH v2] " Junio C Hamano
  2024-05-31 11:26 ` [PATCH] " Patrick Steinhardt
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-05-30 16:58 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt

While most of the commands in Git suite are designed to do useful
things in Git repositories, some commands are also usable outside
any repository.  Building on top of an earlier work abece6e9 (t1517:
test commands that are designed to be run outside repository,
2024-05-20) that adds tests for such commands, let's give coverage
to some more commands.

This patch covers commands whose code has hits for

    $ git grep setup_git_directory_gently

and passes a pointer to nongit_ok variable it uses to allow it to
run outside a Git repository, but mostly they are tested only to see
that they start up (as opposed to dying with "not in a git
repository" complaint).  We may want to update them to actually do
something useful later, but this would at least help us catch
regressions by mistake.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * Designed to apply on top of jc/undecided-is-not-necessarily-sha1-fix
   that introduces t1517.

 t/t1517-outside-repo.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git c/t/t1517-outside-repo.sh w/t/t1517-outside-repo.sh
index 557808ffa7..b77017ac5f 100755
--- c/t/t1517-outside-repo.sh
+++ w/t/t1517-outside-repo.sh
@@ -56,4 +56,52 @@ test_expect_success 'grep outside repository' '
 	test_cmp expect actual
 '
 
+test_expect_success 'imap-send outside repository' '
+	test_config_global imap.host imaps://localhost &&
+	test_config_global imap.folder Drafts &&
+
+	echo nothing to send >expect &&
+	test_must_fail git imap-send -v </dev/null 2>actual &&
+	test_cmp expect actual &&
+
+	(
+		cd non-repo &&
+		test_must_fail git imap-send -v </dev/null 2>../actual
+	) &&
+	test_cmp expect actual
+'
+
+test_expect_success 'check-ref-format outside repository' '
+	git check-ref-format --branch refs/heads/xyzzy >expect &&
+	nongit git check-ref-format --branch refs/heads/xyzzy >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'diff outside repository' '
+	echo one >one &&
+	echo two >two &&
+	test_must_fail git diff --no-index one two >expect &&
+	(
+		cd non-repo &&
+		cp ../one . &&
+		cp ../two . &&
+		test_must_fail git diff one two >../actual
+	) &&
+	test_cmp expect actual
+'
+
+test_expect_success 'stripspace outside repository' '
+	nongit git stripspace -s </dev/null
+'
+
+test_expect_success 'remote-http outside repository' '
+	test_must_fail git remote-http 2>actual &&
+	test_grep "^error: remote-curl" actual &&
+	(
+		cd non-repo &&
+		test_must_fail git remote-http 2>../actual
+	) &&
+	test_grep "^error: remote-curl" actual
+'
+
 test_done

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2] t1517: more coverage for commands that work without repository
  2024-05-30 16:58 [PATCH] t1517: more coverage for commands that work without repository Junio C Hamano
@ 2024-05-31  8:43 ` Junio C Hamano
  2024-05-31 11:26 ` [PATCH] " Patrick Steinhardt
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-05-31  8:43 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt

While most of the commands in Git suite are designed to do useful
things in Git repositories, some commands are also usable outside
any repository.  Building on top of an earlier work abece6e9 (t1517:
test commands that are designed to be run outside repository,
2024-05-20) that adds tests for such commands, let's give coverage
to some more commands.

This patch covers commands whose code has hits for

    $ git grep setup_git_directory_gently

and passes a pointer to nongit_ok variable it uses to allow it to
run outside a Git repository, but mostly they are tested only to see
that they start up (as opposed to dying with "not in a git
repository" complaint).  We may want to update them to actually do
something useful later, but this would at least help us catch
regressions by mistake.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * The previous iteration was buggy when the repository was using
   sha256, as the nongit invocation of "git diff" will use sha1.

 t/t1517-outside-repo.sh | 52 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh
index 557808ffa7..990a036582 100755
--- a/t/t1517-outside-repo.sh
+++ b/t/t1517-outside-repo.sh
@@ -56,4 +56,56 @@ test_expect_success 'grep outside repository' '
 	test_cmp expect actual
 '
 
+test_expect_success 'imap-send outside repository' '
+	test_config_global imap.host imaps://localhost &&
+	test_config_global imap.folder Drafts &&
+
+	echo nothing to send >expect &&
+	test_must_fail git imap-send -v </dev/null 2>actual &&
+	test_cmp expect actual &&
+
+	(
+		cd non-repo &&
+		test_must_fail git imap-send -v </dev/null 2>../actual
+	) &&
+	test_cmp expect actual
+'
+
+test_expect_success 'check-ref-format outside repository' '
+	git check-ref-format --branch refs/heads/xyzzy >expect &&
+	nongit git check-ref-format --branch refs/heads/xyzzy >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'diff outside repository' '
+	echo one >one &&
+	echo two >two &&
+	test_must_fail git diff --no-index one two >expect.raw &&
+	(
+		cd non-repo &&
+		cp ../one . &&
+		cp ../two . &&
+		test_must_fail git diff one two >../actual.raw
+	) &&
+	# outside repository diff falls back to SHA-1 but
+	# GIT_DEFAULT_HASH may be set to sha256 on the in-repo side.
+	sed -e "/^index /d" expect.raw >expect &&
+	sed -e "/^index /d" actual.raw >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'stripspace outside repository' '
+	nongit git stripspace -s </dev/null
+'
+
+test_expect_success 'remote-http outside repository' '
+	test_must_fail git remote-http 2>actual &&
+	test_grep "^error: remote-curl" actual &&
+	(
+		cd non-repo &&
+		test_must_fail git remote-http 2>../actual
+	) &&
+	test_grep "^error: remote-curl" actual
+'
+
 test_done

Interdiff against v1:
  diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh
  index b77017ac5f..990a036582 100755
  --- a/t/t1517-outside-repo.sh
  +++ b/t/t1517-outside-repo.sh
  @@ -80,13 +80,17 @@ test_expect_success 'check-ref-format outside repository' '
   test_expect_success 'diff outside repository' '
   	echo one >one &&
   	echo two >two &&
  -	test_must_fail git diff --no-index one two >expect &&
  +	test_must_fail git diff --no-index one two >expect.raw &&
   	(
   		cd non-repo &&
   		cp ../one . &&
   		cp ../two . &&
  -		test_must_fail git diff one two >../actual
  +		test_must_fail git diff one two >../actual.raw
   	) &&
  +	# outside repository diff falls back to SHA-1 but
  +	# GIT_DEFAULT_HASH may be set to sha256 on the in-repo side.
  +	sed -e "/^index /d" expect.raw >expect &&
  +	sed -e "/^index /d" actual.raw >actual &&
   	test_cmp expect actual
   '
   
-- 
2.45.2-584-g20241e85ff


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t1517: more coverage for commands that work without repository
  2024-05-30 16:58 [PATCH] t1517: more coverage for commands that work without repository Junio C Hamano
  2024-05-31  8:43 ` [PATCH v2] " Junio C Hamano
@ 2024-05-31 11:26 ` Patrick Steinhardt
  2024-05-31 14:57   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Patrick Steinhardt @ 2024-05-31 11:26 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On Thu, May 30, 2024 at 09:58:46AM -0700, Junio C Hamano wrote:
[snip]
> +test_expect_success 'stripspace outside repository' '
> +	nongit git stripspace -s </dev/null
> +'

I was wondering whether we also want to verify that it does the correct
thing here as it's comparatively easy:

	test_expect_success 'stripspace outside repository' '
		cat >input <<-EOF &&
		# foo
		bar
		EOF
		cat >expect <<-EOF &&
		bar
		EOF

		git stripspace -s <input >actual &&
		test_cmp expect actual &&
		nongit git stripspace -s <input >actual &&
		test_cmp expect actual
	'

For the other tests it's a bit more involved. And given that these are
all designed as smoke tests, I think it's fine overall.

Thanks!

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t1517: more coverage for commands that work without repository
  2024-05-31 11:26 ` [PATCH] " Patrick Steinhardt
@ 2024-05-31 14:57   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-05-31 14:57 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git

Patrick Steinhardt <ps@pks.im> writes:

> On Thu, May 30, 2024 at 09:58:46AM -0700, Junio C Hamano wrote:
> [snip]
>> +test_expect_success 'stripspace outside repository' '
>> +	nongit git stripspace -s </dev/null
>> +'
>
> I was wondering whether we also want to verify that it does the correct
> thing here as it's comparatively easy:
> ...
> For the other tests it's a bit more involved. And given that these are
> all designed as smoke tests, I think it's fine overall.

Yup, as I said in the proposed log message, we may want to update
them to actually do something useful later, but this would at least
help us catch regressions by mistake.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-31 14:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-30 16:58 [PATCH] t1517: more coverage for commands that work without repository Junio C Hamano
2024-05-31  8:43 ` [PATCH v2] " Junio C Hamano
2024-05-31 11:26 ` [PATCH] " Patrick Steinhardt
2024-05-31 14:57   ` Junio C Hamano

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).