[PATCH v2 2/2] remote.c: remove BUG in show_push_unqualified_ref_name_error()
From: Denton Liu <hidden>
Date: 2025-08-05 06:24:43
Subsystem:
the rest · Maintainer:
Linus Torvalds
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. Helped-by: Junio C Hamano [off-list ref] Signed-off-by: Denton Liu <redacted> --- Thanks, I liked the way you phrased the commit message so I copied it wholesale over. remote.c | 3 +-- t/t5516-fetch-push.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/remote.c b/remote.c
index e965f022f1..4ad20110e9 100644
--- a/remote.c
+++ b/remote.c@@ -1218,8 +1218,7 @@ static void show_push_unqualified_ref_name_error(const char *dst_value, "'%s:refs/tags/%s'?"), matched_src_name, dst_value); } else { - BUG("'%s' should be commit/tag/tree/blob, is '%d'", - matched_src_name, type); + advise(_("The <src> part of the refspec is an oid that doesn't exist.\n")); } }
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index c2fcfeca92..e064ea7433 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh@@ -509,7 +509,7 @@ test_expect_success 'push ref expression with non-existent, incomplete dest' ' ' -test_expect_failure 'push ref expression with non-existent oid src' ' +test_expect_success 'push ref expression with non-existent oid src' ' mk_test testrepo && test_must_fail git push testrepo $(test_oid 001):branch
--
2.50.1