Skip to content

Commit 8282311

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 54a03bc commit 8282311

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

builtin/fetch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,9 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
14281428
if (!has_glob_specials(s)) {
14291429
struct object_id oid;
14301430
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);
14321434
oid_array_append(oids, &oid);
14331435
continue;
14341436
}

t/t5510-fetch.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,19 @@ test_expect_success '--negotiation-tip understands abbreviated SHA-1' '
12141214
check_negotiation_tip
12151215
'
12161216

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+
12171230
. "$TEST_DIRECTORY"/lib-httpd.sh
12181231
start_httpd
12191232

0 commit comments

Comments
 (0)