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

[PATCH 1/5] fetch test: use more robust test for filtered objects

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 24, 2019, 00:59 UTC
Message-ID
<20191224005907.GD38316@google.com>
In-Reply-To
<20191224005816.GC38316@google.com>

"git cat-file -e" uses has_object_file, which can fetch from promisor remotes when an object is missing. These tests end up checking that that fetch fails instead of for the object being missing.

By luck, the tests pass anyway:
- in one of these tests ("filtering by size"), the fetch fails because
  (in protocol v0) the server does not support fetches by SHA-1
- in the second, the object is present but the test could pass even if
  it weren't if the fetch succeeds
- in the third, the test sets extensions.partialClone to "arbitrary
  string" so that when it tries to fetch, it looks up the "arbitrary
  string" remote which does not exist

Use "git rev-list --objects --missing=allow-any", so that the tests pass for the right reason.

Noticed while testing with protocol v2, which allows fetching by sha1 by default, causing the first fetch to succeed and the test to fail.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t5500-fetch-pack.sh | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 6b97923964..964930b2d2 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -917,7 +917,10 @@ test_expect_success 'filtering by size' '
 	git -C client fetch-pack --filter=blob:limit=0 ../server HEAD &&
 
 	# Ensure that object is not inadvertently fetched
-	test_must_fail git -C client cat-file -e $(git hash-object server/one.t)
+	commit=$(git -C server rev-parse HEAD) &&
+	blob=$(git hash-object server/one.t) &&
+	git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
+	! grep "$blob" oids
 '
 
 test_expect_success 'filtering by size has no effect if support for it is not advertised' '
@@ -929,7 +932,10 @@ test_expect_success 'filtering by size has no effect if support for it is not ad
 	git -C client fetch-pack --filter=blob:limit=0 ../server HEAD 2> err &&
 
 	# Ensure that object is fetched
-	git -C client cat-file -e $(git hash-object server/one.t) &&
+	commit=$(git -C server rev-parse HEAD) &&
+	blob=$(git hash-object server/one.t) &&
+	git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
+	grep "$blob" oids &&
 
 	test_i18ngrep "filtering not recognized by server" err
 '
@@ -951,9 +957,11 @@ fetch_filter_blob_limit_zero () {
 	git -C client fetch --filter=blob:limit=0 origin HEAD:somewhere &&
 
 	# Ensure that commit is fetched, but blob is not
-	test_config -C client extensions.partialclone "arbitrary string" &&
-	git -C client cat-file -e $(git -C "$SERVER" rev-parse two) &&
-	test_must_fail git -C client cat-file -e $(git hash-object "$SERVER/two.t")
+	commit=$(git -C "$SERVER" rev-parse two) &&
+	blob=$(git hash-object server/two.t) &&
+	git -C client rev-list --objects --missing=allow-any "$commit" >oids &&
+	grep "$commit" oids &&
+	! grep "$blob" oids
 }
 
 test_expect_success 'fetch with --filter=blob:limit=0' '
-- 
2.24.1.735.g03f4e72817
Previous: Jonathan NiederNext: Derrick Stolee
Message 2 of 17 in “Enable protocol v2 by default”
  1. 0/5 Enable protocol v2 by defaultJonathan Nieder, Dec 24, 2019
  2. 1/5 fetch test: use more robust test for filtered objectsJonathan Nieder, Dec 24, 2019
  3. Derrick StoleeDec 26, 2019
  4. 2/5 config doc: protocol.version is not experimentalJonathan Nieder, Dec 24, 2019
  5. 3/5 test: request GIT_TEST_PROTOCOL_VERSION=0 when appropriateJonathan Nieder, Dec 24, 2019
  6. Junio C HamanoDec 26, 2019
  7. 0/2 avoid use of "VAR= cmd" with a shell function (Re: [PATCH 3/5] test: request GIT_TEST_PROTOCOL_VERSION=0 when appropriate)Jonathan Nieder, Dec 26, 2019
  8. 1/2 fetch test: avoid use of "VAR= cmd" with a shell functionJonathan Nieder, Dec 26, 2019
  9. 2/2 t/check-non-portable-shell: detect "FOO= shell_func", tooJonathan Nieder, Dec 26, 2019
  10. Junio C HamanoDec 26, 2019
  11. Junio C HamanoDec 26, 2019
  12. Jonathan NiederDec 26, 2019
  13. fetch test: mark test of "skipping" haves as v0-onlyJonathan Nieder, Dec 26, 2019
  14. Eric SunshineDec 26, 2019
  15. 4/5 protocol test: let protocol.version override GIT_TEST_PROTOCOL_VERSIONJonathan Nieder, Dec 24, 2019
  16. 5/5 fetch: default to protocol version 2Jonathan Nieder, Dec 24, 2019
  17. Derrick StoleeDec 26, 2019

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.