]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: die on invalid --negotiation-tip hash
authorJonathan Tan <jonathantanmy@google.com>
Thu, 15 Jul 2021 17:44:32 +0000 (10:44 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jul 2021 18:58:52 +0000 (11:58 -0700)
If a full hexadecimal hash is given as a --negotiation-tip to "git
fetch", and that hash does not correspond to an object, "git fetch" will
segfault if --negotiate-only is given and will silently ignore that hash
otherwise. Make these cases fatal errors, just like the case when an
invalid ref name or abbreviated hash is given.

While at it, mark the error messages as translatable.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c
t/t5510-fetch.sh

index dfde96a4354c145dd23da41d3e6819ea3d3bb9b6..0aeb0438404f3f33aeef459e9108d987024fd181 100644 (file)
@@ -1428,7 +1428,9 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
                if (!has_glob_specials(s)) {
                        struct object_id oid;
                        if (get_oid(s, &oid))
-                               die("%s is not a valid object", s);
+                               die(_("%s is not a valid object"), s);
+                       if (!has_object(the_repository, &oid, 0))
+                               die(_("the object %s does not exist"), s);
                        oid_array_append(oids, &oid);
                        continue;
                }
index e83b2a65069f6a1ddf78da5a38efd3f5f85c65e8..a0faf0dd94909392d7fa3b263b30b2bb41d7ca35 100755 (executable)
@@ -1214,6 +1214,19 @@ test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
        check_negotiation_tip
 '
 
+test_expect_success '--negotiation-tip rejects missing OIDs' '
+       setup_negotiation_tip server server 0 &&
+       test_must_fail git -C client fetch \
+               --negotiation-tip=alpha_1 \
+               --negotiation-tip=$(test_oid zero) \
+               origin alpha_s beta_s 2>err &&
+       cat >fatal-expect <<-EOF &&
+       fatal: the object $(test_oid zero) does not exist
+EOF
+       grep fatal: err >fatal-actual &&
+       test_cmp fatal-expect fatal-actual
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd