Skip to content

Commit 3d84072

Browse files
committed
remote.c: remove BUG in show_push_unqualified_ref_name_error()
When "git push <remote> <src>:<dst>" does not spell out the destination side of the ref fully, and when <src> is not given as a reference but an object name, the code tries to give advice messages based on the type of that object. The type is determined by calling odb_read_object_info() and signalled by its return value. The code however reported a programming error with BUG() when this function said that there is no such object, which happens when the object name is given as a full hexadecimal (if the object name is given as a partial hexadecimal or an non-existing ref, the function would have died without returning, so this BUG() wouldn't have triggered). This is wrong. It is an ordinary end-user mistake to give an object name that does not exist and treated as such. An example of the error message produced is as follows: error: The destination you provided is not a full refname (i.e., starting with "refs/"). We tried to guess what you meant by: - Looking for a ref that matches 'branch' on the remote side. - Checking if the <src> being pushed ('0000000000000000000000000000000000000001') is a ref in "refs/{heads,tags}/". If so we add a corresponding refs/{heads,tags}/ prefix on the remote side. Neither worked, so we gave up. You must fully qualify the ref. BUG: remote.c:1221: '0000000000000000000000000000000000000001' should be commit/tag/tree/blob, is '-1' fatal: the remote end hung up unexpectedly Aborted (core dumped) Helped-by: Junio C Hamano <gitster@pobox.com>
1 parent ee6d69b commit 3d84072

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

remote.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,10 @@ static void show_push_unqualified_ref_name_error(const char *dst_value,
12221222
matched_src_name, dst_value);
12231223
break;
12241224
default:
1225-
BUG("'%s' should be commit/tag/tree/blob, is '%d'",
1226-
matched_src_name, type);
1225+
advise(_("The <src> part of the refspec ('%s') "
1226+
"is an object ID that doesn't exist.\n"),
1227+
matched_src_name);
1228+
break;
12271229
}
12281230
}
12291231

t/t5516-fetch-push.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,11 @@ test_expect_success 'push ref expression with non-existent, incomplete dest' '
471471
test_must_fail git push testrepo main^:branch
472472
'
473473

474+
test_expect_success 'push ref expression with non-existent oid src' '
475+
mk_test testrepo &&
476+
test_must_fail git push testrepo $(test_oid 001):branch
477+
'
478+
474479
for head in HEAD @
475480
do
476481

0 commit comments

Comments
 (0)