git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] push: allow pushing new branches with --force-with-lease

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 25, 2016, 22:11 UTC
Message-ID
<xmqq37mx4bct.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<xmqq4m7d7hlq.fsf@gitster.mtv.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> I suspect that the if/else cascade in the loop in apply_cas() can
> also be taught that ':' followed by an empty string asks to check
> that the target ref does not exist, in order to make it a bit more
> useful for folks who do not rely on the "use the last observed
> status of the tracking branch".
>
> That would make the "explicit" test much less cumbersome to read.
In other words, something like this, perhaps?
 remote.c            |  2 ++
 t/t5533-push-cas.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+)
diff --git a/remote.c b/remote.c
index b35ffd9..55812d8 100644
--- a/remote.c
+++ b/remote.c
@@ -2303,6 +2303,8 @@ int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unse
 	entry = add_cas_entry(cas, arg, colon - arg);
 	if (!*colon)
 		entry->use_tracking = 1;
+	else if (!colon[1])
+		hashclr(entry->expect);
 	else if (get_sha1(colon + 1, entry->expect))
 		return error("cannot parse expected object name '%s'", colon + 1);
 	return 0;
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index 4276b1b..04f4636 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -215,6 +215,18 @@ test_expect_success 'new branch covered by force-with-lease (explicit)' '
 	test_cmp expect actual
 '
 
+test_expect_success 'new branch covered by force-with-lease (less cumbersome)' '
+	setup_srcdst_basic &&
+	(
+		cd dst &&
+		git branch another master &&
+		git push --force-with-lease=another: origin another
+	) &&
+	git ls-remote dst refs/heads/another >expect &&
+	git ls-remote src refs/heads/another >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'new branch already exists' '
 	setup_srcdst_basic &&
 	(
-- 
2.9.2-629-gdd92683
Previous: John Keeping
Message 19 of 19 in “push: allow pushing new branches with --force-with-lease”
  1. push: allow pushing new branches with --force-with-leaseJohn Keeping, Jul 23, 2016
  2. Junio C HamanoJul 25, 2016
  3. 0/3 push: allow pushing new branches with --force-with-leaseJohn Keeping, Jul 25, 2016
  4. 1/3 Documentation/git-push: fix placeholder formattingJohn Keeping, Jul 25, 2016
  5. 2/3 push: add shorthand for --force-with-lease branch creationJohn Keeping, Jul 25, 2016
  6. Junio C HamanoJul 25, 2016
  7. John KeepingJul 26, 2016
  8. Junio C HamanoJul 26, 2016
  9. John KeepingJul 26, 2016
  10. Junio C HamanoJul 26, 2016
  11. Jakub NarębskiJul 26, 2016
  12. John KeepingJul 26, 2016
  13. 3/3 push: allow pushing new branches with --force-with-leaseJohn Keeping, Jul 25, 2016
  14. Junio C HamanoJul 25, 2016
  15. 0/3 push: allow pushing new branches with --force-with-leaseJohn Keeping, Jul 26, 2016
  16. 1/3 Documentation/git-push: fix placeholder formattingJohn Keeping, Jul 26, 2016
  17. 2/3 push: add shorthand for --force-with-lease branch creationJohn Keeping, Jul 26, 2016
  18. 3/3 push: allow pushing new branches with --force-with-leaseJohn Keeping, Jul 26, 2016
  19. Junio C HamanoJul 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.