From: Jeff King <peff@peff.net>
To: "jonsmirl@gmail.com" <jonsmirl@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: [PATCH] push: don't guess at qualifying remote refs on deletion
Date: Tue, 3 Jul 2012 14:04:39 -0400 [thread overview]
Message-ID: <20120703180439.GC3294@sigill.intra.peff.net> (raw)
In-Reply-To: <CAKON4OxBo7XiF5c60oyEUMR1xCh16n5BZCz-mmcUc0V9X7D32A@mail.gmail.com>
When we try to push a ref and the right-hand side of the
refspec does not find a match, we try to create it. If it is
not fully qualified, we try to guess where it would go in
the refs hierarchy based on the left-hand source side. If
the source side is not a ref, then we give up and give a
long explanatory message.
For deletions, however, this doesn't make any sense. We
would never want to create on the remote side, and if an
unqualified ref can't be matched, it is simply an error. The
current code handles this already because the left-hand side
is empty, and therefore does not give us a hint as to where
the right-hand side should go, and we properly error out.
Unfortunately, the error message is the long "we tried to
qualify this, but the source side didn't let us guess"
message, which is quite confusing.
Instead, we can just be more succinct and say "we can't
delete this because we couldn't find it". So before:
$ git push origin :bogus
error: unable to push to unqualified destination: bogus
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 '$URL'
and now:
$ git push origin :bogus
error: unable to delete 'bogus': remote ref does not exist
error: failed to push some refs to '$URL'
It is tempting to also catch a fully-qualified ref like
"refs/heads/bogus" and generate the same error message.
However, that currently does not error out at all, and
instead gets sent to the remote side, which typically
generates a warning:
$ git push origin:refs/heads/bogus
remote: warning: Deleting a non-existent ref.
To $URL
- [deleted] bogus
While it would be nice to catch this error early, a
client-side error would mean aborting the push entirely and
changing push's exit code. For example, right now you can
do:
$ git push origin refs/heads/foo refs/heads/bar
and end up in a state where "foo" and "bar" are deleted,
whether both of them currently exist or not (and see an
error only if we actually failed to contact the server).
Generating an error would cause a regression for this use
case.
Signed-off-by: Jeff King <peff@peff.net>
---
On Tue, Jul 03, 2012 at 07:42:07AM -0400, jonsmirl@gmail.com wrote:
> I have the branch name wrong. It is fl.stgit not fl.stg.
> But the error message sent me off in the wrong direction looking for an answer.
I think this would help. I used "remote ref does not exist"
because that is the simplest explanation for the user.
However, given that we will try to push a fully qualified
ref that does not exist, a more accurate message might
"destination refspec did not match" or something similar. I
prefer the former, though, as it less arcane.
remote.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/remote.c b/remote.c
index 6833538..04fd9ea 100644
--- a/remote.c
+++ b/remote.c
@@ -1100,6 +1100,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
case 0:
if (!memcmp(dst_value, "refs/", 5))
matched_dst = make_linked_ref(dst_value, dst_tail);
+ else if (is_null_sha1(matched_src->new_sha1))
+ error("unable to delete '%s': remote ref does not exist",
+ dst_value);
else if ((dst_guess = guess_ref(dst_value, matched_src)))
matched_dst = make_linked_ref(dst_guess, dst_tail);
else
--
1.7.11.rc1.21.g3c8d91e
next prev parent reply other threads:[~2012-07-03 18:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-03 3:09 How do I delete a remote branch with a period in the name? jonsmirl
2012-07-03 4:14 ` Junio C Hamano
2012-07-03 11:42 ` jonsmirl
2012-07-03 18:04 ` Jeff King [this message]
2012-07-03 18:34 ` [PATCH] push: don't guess at qualifying remote refs on deletion jonsmirl
2012-07-03 18:40 ` Jeff King
2012-07-03 18:43 ` jonsmirl
2012-07-03 19:35 ` Jeff King
2012-07-04 7:21 ` Carlos Martín Nieto
[not found] ` <CABURp0rVPAvxP1sp_nmoNYd+F+OsvWeHgUAeo7-VTnQhdebFeg@mail.gmail.com>
2012-07-05 7:22 ` Carlos Martín Nieto
2012-07-05 15:32 ` Phil Hord
2012-07-05 17:24 ` Carlos Martín Nieto
2012-07-05 17:26 ` Junio C Hamano
2012-07-03 19:38 ` Junio C Hamano
2012-07-04 7:37 ` Jeff King
2012-07-03 7:56 ` How do I delete a remote branch with a period in the name? Andreas Schwab
2012-07-03 19:39 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120703180439.GC3294@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jonsmirl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).