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

[PATCH 3/3] push: add remote.*.pushHeadOnly configuration

From
Paolo Bonzini <bonzini@gnu.org>
Date
Jul 20, 2009, 06:37 UTC
Message-ID
<1248071820-18289-4-git-send-email-bonzini@gnu.org>
In-Reply-To
<1248071820-18289-1-git-send-email-bonzini@gnu.org>

This patch adds a remote.*.pushHeadOnly configuration that automatically enables (when possible) the --current option to git push.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
 Documentation/config.txt |    6 ++++++
 builtin-push.c           |    2 ++
 remote.c                 |    2 ++
 remote.h                 |    1 +
 t/t5516-fetch-push.sh    |   16 +++++++++++++++-
 5 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index cb6832b..4ab5593 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1359,6 +1359,12 @@ remote.<name>.uploadpack::
 	The default program to execute on the remote side when fetching.  See
 	option \--upload-pack of linkgit:git-fetch-pack[1].
 
+remote.<name>.pushHeadOnly::
+	If true, whenever `git push` is invoked without a refspec and
+	it will try pushing to this remote, `git push` will automatically
+	behave as if the `\--current` option was given on the command line.
+	In other words, only the current branch is pushed to the remote.
+
 remote.<name>.tagopt::
 	Setting this value to \--no-tags disables automatic tag following when
 	fetching from remote <name>
diff --git a/builtin-push.c b/builtin-push.c
index 71d94a5..8d5b054 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -109,6 +109,8 @@ static int do_push(const char *repo, int flags)
 
 	if (remote->mirror)
 		flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
+	if (remote->push_head_only && !refspec_nr)
+		flags |= TRANSPORT_PUSH_CURRENT;
 
 	if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
 		if (!strcmp(*refspec, "refs/tags/*"))
diff --git a/remote.c b/remote.c
index b5bf9a6..d46dc0d 100644
--- a/remote.c
+++ b/remote.c
@@ -379,6 +379,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 		remote->mirror = git_config_bool(key, value);
 	else if (!strcmp(subkey, ".skipdefaultupdate"))
 		remote->skip_default_update = git_config_bool(key, value);
+	else if (!strcmp(subkey, ".pushheadonly"))
+		remote->push_head_only = git_config_bool(key, value);
 
 	else if (!strcmp(subkey, ".url")) {
 		const char *v;
diff --git a/remote.h b/remote.h
index 8e5d5b4..b1e3e99 100644
--- a/remote.h
+++ b/remote.h
@@ -36,6 +36,7 @@ struct remote {
 	 * 2 to always fetch tags
 	 */
 	int fetch_tags;
+	int push_head_only;
 	int skip_default_update;
 	int mirror;
 
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index a480cb2..9d61ba0 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -631,9 +631,23 @@ test_expect_success 'push --current respects configuration' '
 	git config remote.bremote.push refs/heads/master:refs/heads/master2 &&
 	git push --current bremote &&
 	test $(git rev-parse master) = $(cd b.git && git rev-parse master2)
+'
+
+test_expect_success 'remote.*.pushHeadOnly respects configuration' '
+	echo xx > b &&
+	git commit -mmaster3 b &&
+	git config remote.bremote.pushHeadOnly true &&
 	git checkout branch &&
-	git push --current bremote 2>&1 | grep "Everything up-to-date" &&
+	git push bremote &&
+	test $(git rev-parse master^) = $(cd b.git && git rev-parse master) &&
 	test $(git rev-parse branch^) = $(cd b.git && git rev-parse branch)
 '
 
+test_expect_success 'remote.*.pushHeadOnly works' '
+	git config --unset remote.bremote.push &&
+	git push bremote &&
+	test $(git rev-parse master^) = $(cd b.git && git rev-parse master) &&
+	test $(git rev-parse branch) = $(cd b.git && git rev-parse branch)
+'
+
 test_done
-- 
1.6.2.5
Previous: demerphq
Message 9 of 9 in “add push --current and remote.*.pushHeadOnly”
  1. 0/3 add push --current and remote.*.pushHeadOnlyPaolo Bonzini, Jul 20, 2009
  2. 1/3 reintroduce PUSH_DEFAULT_UNSPECIFIEDPaolo Bonzini, Jul 20, 2009
  3. 2/3 push: add --currentPaolo Bonzini, Jul 20, 2009
  4. Björn SteinbrinkJul 20, 2009
  5. Paolo BonziniJul 20, 2009
  6. Tay Ray ChuanJul 20, 2009
  7. Paolo BonziniJul 20, 2009
  8. demerphqJul 20, 2009
  9. 3/3 push: add remote.*.pushHeadOnly configurationPaolo Bonzini, Jul 20, 2009

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.