From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
Brandon Williams <bwilliams.eng@gmail.com>,
Jacob Keller <jacob.keller@gmail.com>,
Tomo Krajina <tkrajina@gmail.com>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v2] refspec: make @ a synonym of HEAD
Date: Tue, 24 Nov 2020 18:11:02 -0600 [thread overview]
Message-ID: <20201125001102.111025-1-felipe.contreras@gmail.com> (raw)
Since commit 9ba89f484e git learned how to push to a remote branch using
the source @, for example:
git push origin @:$dst
However, if the right-hand side is missing, the push fails:
git push origin @
It is obvious what is the desired behavior, and allowing the push makes
things more consistent.
Additionally, @:master now has the same semantics as HEAD:master.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
refspec.c | 5 ++++-
t/t5511-refspec.sh | 2 ++
t/t5516-fetch-push.sh | 18 ++++++++++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/refspec.c b/refspec.c
index c49347c2d7..adbfb3283a 100644
--- a/refspec.c
+++ b/refspec.c
@@ -71,7 +71,10 @@ static int parse_refspec(struct refspec_item *item, const char *refspec, int fet
}
item->pattern = is_glob;
- item->src = xstrndup(lhs, llen);
+ if (llen == 1 && *lhs == '@')
+ item->src = xstrdup("HEAD");
+ else
+ item->src = xstrndup(lhs, llen);
flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0);
if (item->negative) {
diff --git a/t/t5511-refspec.sh b/t/t5511-refspec.sh
index f541f30bc2..f808649de4 100755
--- a/t/t5511-refspec.sh
+++ b/t/t5511-refspec.sh
@@ -58,6 +58,8 @@ test_refspec fetch 'HEAD~4:refs/remotes/frotz/new' invalid
test_refspec push 'HEAD'
test_refspec fetch 'HEAD'
+test_refspec push '@'
+test_refspec fetch '@'
test_refspec push 'refs/heads/ nitfol' invalid
test_refspec fetch 'refs/heads/ nitfol' invalid
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index d11382f769..1ca6b9641d 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -483,6 +483,15 @@ test_expect_success 'push HEAD with non-existent, incomplete dest' '
'
+test_expect_success 'push @ with non-existent, incomplete dest' '
+
+ mk_test testrepo &&
+ git checkout master &&
+ git push testrepo @:branch &&
+ check_push_result testrepo $the_commit heads/branch
+
+'
+
test_expect_success 'push with config remote.*.push = HEAD' '
mk_test testrepo heads/local &&
@@ -501,6 +510,15 @@ test_expect_success 'push with config remote.*.push = HEAD' '
check_push_result testrepo $the_first_commit heads/local
'
+test_expect_success 'push with @' '
+
+ mk_test testrepo heads/master &&
+ git checkout master &&
+ git push testrepo @ &&
+ check_push_result testrepo $the_commit heads/master
+
+'
+
test_expect_success 'push with remote.pushdefault' '
mk_test up_repo heads/master &&
mk_test down_repo heads/master &&
--
2.29.2
next reply other threads:[~2020-11-25 0:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-25 0:11 Felipe Contreras [this message]
2020-11-25 0:36 ` [PATCH v2] refspec: make @ a synonym of HEAD Junio C Hamano
2020-11-25 0:43 ` Felipe Contreras
2020-11-25 1:53 ` Junio C Hamano
2020-11-25 23:48 ` Felipe Contreras
2020-11-26 0:01 ` 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=20201125001102.111025-1-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=bwilliams.eng@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jacob.keller@gmail.com \
--cc=peff@peff.net \
--cc=tkrajina@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).