Skip to content

Commit c83cca3

Browse files
avargitster
authored andcommitted
push: improve the error shown on unqualified <dst> push
Improve the error message added in f8aae12 ("push: allow unqualified dest refspecs to DWIM", 2008-04-23), which before this change looks like this: $ git push avar v2.19.0^{commit}:newbranch -n error: unable to push to unqualified destination: newbranch The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to '[email protected]:avar/git.git' This message needed to be read very carefully to spot how to fix the error, i.e. to push to refs/heads/newbranch. Now the message will look like this instead: $ ./git-push avar v2.19.0^{commit}:newbranch -n 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 'newbranch' on the remote side. - Checking if the <src> being pushed ('v2.19.0^{commit}') 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. error: failed to push some refs to '[email protected]:avar/git.git' This improvement is the result of on-list discussion in [1] and [2], as well as my own fixes / reformatting / phrasing on top. The suggestion by Jeff on-list was to make that second bullet point "Looking at the refname of the local source.". The version being added here is more verbose, but also more accurate. saying "local source" could refer to any ref in the local refstore, including something in refs/remotes/*. A later change will teach guess_ref() to infer a ref type from remote-tracking refs, so let's not confuse the two. While I'm at it, add a "TRANSLATORS" comment since the message has gotten more complex and it's not as clear what the two %s's refer to. 1. https://public-inbox.org/git/[email protected]/ 2. https://public-inbox.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b0e542 commit c83cca3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

remote.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,22 @@ static int match_explicit(struct ref *src, struct ref *dst,
10491049
matched_dst = make_linked_ref(dst_guess, dst_tail);
10501050
free(dst_guess);
10511051
} else {
1052-
error(_("unable to push to unqualified destination: %s\n"
1053-
"The destination refspec neither matches an "
1054-
"existing ref on the remote nor\n"
1055-
"begins with refs/, and we are unable to "
1056-
"guess a prefix based on the source ref."),
1057-
dst_value);
1052+
/*
1053+
* TRANSLATORS: "matches '%s'%" is the <dst>
1054+
* part of "git push <remote> <src>:<dst>"
1055+
* push, and "being pushed ('%s')" is the
1056+
* <src>.
1057+
*/
1058+
error(_("The destination you provided is not a full refname (i.e.,\n"
1059+
"starting with \"refs/\"). We tried to guess what you meant by:\n"
1060+
"\n"
1061+
"- Looking for a ref that matches '%s' on the remote side.\n"
1062+
"- Checking if the <src> being pushed ('%s')\n"
1063+
" is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n"
1064+
" refs/{heads,tags}/ prefix on the remote side.\n"
1065+
"\n"
1066+
"Neither worked, so we gave up. You must fully qualify the ref."),
1067+
dst_value, matched_src->name);
10581068
}
10591069
break;
10601070
default:

0 commit comments

Comments
 (0)