git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] refspec: make @ a valid refspec
@ 2020-11-22 16:46 Felipe Contreras
  2020-11-24  7:42 ` Jeff King
  0 siblings, 1 reply; 13+ messages in thread
From: Felipe Contreras @ 2020-11-22 16:46 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Jeff King, Brandon Williams, Jacob Keller,
	Felipe Contreras

Since commit 9ba89f484e git learned how to push to a remote branch using
the source @, for example:

  git push origin @:master

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.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 refspec.c             | 5 ++++-
 t/t5511-refspec.sh    | 2 ++
 t/t5516-fetch-push.sh | 9 +++++++++
 3 files changed, 15 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..12c0c7c06b 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -501,6 +501,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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-04 22:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-22 16:46 [PATCH] refspec: make @ a valid refspec Felipe Contreras
2020-11-24  7:42 ` Jeff King
2020-11-24 20:01   ` Junio C Hamano
2020-11-24 22:01     ` Felipe Contreras
2020-11-24 22:45       ` Junio C Hamano
2020-11-24 22:52         ` Jacob Keller
2020-11-24 23:14           ` Junio C Hamano
2020-11-24 23:47             ` Jacob Keller
2020-11-25  0:28               ` Felipe Contreras
2020-11-25  0:30               ` Junio C Hamano
2020-11-25  0:14             ` Felipe Contreras
2020-11-25  0:09         ` Felipe Contreras
2020-12-04 22:20           ` Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).