fetch: die on invalid --negotiation-tip hash
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>
Jonathan Tan committed
Jul 15, 2021 at 10:44 UTC
82823118b9cd397d6b626cc86a0e555069ea8253
2 files changed
+16
-1
builtin/fetch.c
+3
-1
@@ -1428,7 +1428,9 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
1428
if (!has_glob_specials(s)) {
1429
struct object_id oid;
1430
if (get_oid(s, &oid))
1431
- die("%s is not a valid object", s);
1431
+ die(_("%s is not a valid object"), s);
1432
+ if (!has_object(the_repository, &oid, 0))
1433
+ die(_("the object %s does not exist"), s);
1434
oid_array_append(oids, &oid);
1435
continue;
1436
}
t/t5510-fetch.sh
+13
@@ -1214,6 +1214,19 @@ test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
1214
check_negotiation_tip
1215
'
1216
1217
+test_expect_success '--negotiation-tip rejects missing OIDs' '
1218
+ setup_negotiation_tip server server 0 &&
1219
+ test_must_fail git -C client fetch \
1220
+ --negotiation-tip=alpha_1 \
1221
+ --negotiation-tip=$(test_oid zero) \
1222
+ origin alpha_s beta_s 2>err &&
1223
+ cat >fatal-expect <<-EOF &&
1224
+ fatal: the object $(test_oid zero) does not exist
1225
+EOF
1226
+ grep fatal: err >fatal-actual &&
1227
+ test_cmp fatal-expect fatal-actual
1228
+'
1229
+
1230
. "$TEST_DIRECTORY"/lib-httpd.sh
1231
start_httpd
1232