Message ID | 20181026230741.23321-4-avarab@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | None | expand |
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > Improve the error message added in f8aae12034 ("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 'git@github.com: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. If so, we would have added ..., but we couldn't, because <src> was not such a local ref. But is that a useful/actionable piece of information? The user said v2.19.0^{commit} because there was no such local ref the user could have used instead to allow the DWIM to work on the destination side. Perhaps it may be a good thing to remember for the next time, but it does not help the user at all while redoing this failed push. > Neither worked, so we gave up. You must fully-qualify the ref. > error: failed to push some refs to 'git@github.com:avar/git.git' I am not sure if this is an improvement, quite honestly. The only part that directly matters to the end user and is is more understandable than the original is "You must fully qualify the ref" (by the way, that dash is probably not what you want). As I already said, "if this were local ref we can guess the location, it would have worked better" is not relevant to the end user, so it is a better use of the extra bytes to explain what it is to "fully" qualify the ref, than telling what would have helped us make a better guess. Perhaps something along the lines of... 'newbranch' does not match any existing ref on the remote side. Please fully specify the destination refname starting from "refs/" (e.g. "v2.19.0^{commit}:refs/heads/newbranch" for creating a "newbranch" branch).
diff --git a/remote.c b/remote.c index 5cb3d00bfb..f4b438ff74 100644 --- a/remote.c +++ b/remote.c @@ -1049,12 +1049,22 @@ static int match_explicit(struct ref *src, struct ref *dst, matched_dst = make_linked_ref(dst_guess, dst_tail); free(dst_guess); } else { - error(_("unable to push to unqualified destination: %s\n" - "The destination refspec neither matches an " - "existing ref on the remote nor\n" - "begins with refs/, and we are unable to " - "guess a prefix based on the source ref."), - dst_value); + /* + * TRANSLATORS: "matches '%s'%" is the <dst> + * part of "git push <remote> <src>:<dst>" + * push, and "being pushed ('%s')" is the + * <src>. + */ + error(_("The destination you provided is not a full refname (i.e.,\n" + "starting with \"refs/\"). We tried to guess what you meant by:\n" + "\n" + "- Looking for a ref that matches '%s' on the remote side.\n" + "- Checking if the <src> being pushed ('%s')\n" + " is a ref in \"refs/{heads,tags}/\". If so we add a corresponding\n" + " refs/{heads,tags}/ prefix on the remote side.\n" + "\n" + "Neither worked, so we gave up. You must fully-qualify the ref."), + dst_value, matched_src->name); } break; default:
Improve the error message added in f8aae12034 ("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 'git@github.com: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 'git@github.com: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/20181010205505.GB12949@sigill.intra.peff.net/ 2. https://public-inbox.org/git/xmqqbm81lb7c.fsf@gitster-ct.c.googlers.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- remote.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)