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

[PATCH] push: add config option to --force-with-lease by default.

From
Francesco Mazzoli <f@mazzo.li>
Date
Jul 3, 2017, 22:08 UTC
Message-ID
<1499119698-6408-1-git-send-email-f@mazzo.li>
In-Reply-To
<871spxchvm.fsf@gmail.com>

The flag can be overridden with `--no-force-with-lease`, or by passing the config via the command line.

Signed-off-by: Francesco Mazzoli <f@mazzo.li>
---
 Documentation/config.txt   | 5 +++++
 Documentation/git-push.txt | 4 +++-
 builtin/push.c             | 3 +++
 cache.h                    | 1 +
 config.c                   | 4 ++++
 environment.c              | 1 +
 6 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 06898a7..835b34b 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2537,6 +2537,11 @@ push.default::
 	specific workflows; for instance, in a purely central workflow
 	(i.e. the fetch source is equal to the push destination),
 	`upstream` is probably what you want.  Possible values are:
+
+push.forceWithLease::
+	When true, `--force-with-lease` is the default behavior when
+	using `push --force`. Explicit invocations of `--force-with-lease`
+	or `--no-force-with-lease` take precedence.
 +
 --
 
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 0a63966..5182656 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -195,7 +195,9 @@ only if the "lease" is still valid.
 `--force-with-lease` alone, without specifying the details, will protect
 all remote refs that are going to be updated by requiring their
 current value to be the same as the remote-tracking branch we have
-for them.
+for them. This behavior can be made default using the `push.forceWithLease`
+configuration option. Consult linkgit:git-config[1]. For more
+information.
 +
 `--force-with-lease=<refname>`, without specifying the expected value, will
 protect the named ref (alone), if it is going to be updated, by
diff --git a/builtin/push.c b/builtin/push.c
index 03846e8..d8fa826 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -561,6 +561,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 
 	packet_trace_identity("push");
 	git_config(git_push_config, &flags);
+	if (push_force_with_lease) {
+		cas.use_tracking_for_rest = 1;
+	}
 	argc = parse_options(argc, argv, prefix, options, push_usage, 0);
 	set_push_cert_flags(&flags, push_cert);
 
diff --git a/cache.h b/cache.h
index 96055c2..5d29e8e 100644
--- a/cache.h
+++ b/cache.h
@@ -830,6 +830,7 @@ enum push_default_type {
 extern enum branch_track git_branch_track;
 extern enum rebase_setup_type autorebase;
 extern enum push_default_type push_default;
+extern int push_force_with_lease;
 
 enum object_creation_mode {
 	OBJECT_CREATION_USES_HARDLINKS = 0,
diff --git a/config.c b/config.c
index 1cd40a5..f1b1e28 100644
--- a/config.c
+++ b/config.c
@@ -1317,6 +1317,10 @@ static int git_default_push_config(const char *var, const char *value)
 		}
 		return 0;
 	}
+	if (!strcmp(var, "push.forcewithlease")) {
+		push_force_with_lease = git_config_bool(var, value);
+		return 0;
+	}
 
 	/* Add other config variables here and to Documentation/config.txt. */
 	return 0;
diff --git a/environment.c b/environment.c
index d40b21f..fb36c1b 100644
--- a/environment.c
+++ b/environment.c
@@ -53,6 +53,7 @@ unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
 enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
+int push_force_with_lease = 0;
 #ifndef OBJECT_CREATION_MODE
 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
 #endif
-- 
2.7.4
Previous: Francesco MazzoliNext: Ævar Arnfjörð Bjarmason
Message 4 of 17 in “push: add config option to --force-with-lease by default.”
  1. push: add config option to --force-with-lease by default.Francesco Mazzoli, Jul 3, 2017
  2. Ævar Arnfjörð BjarmasonJul 3, 2017
  3. Francesco MazzoliJul 3, 2017
  4. push: add config option to --force-with-lease by default.Francesco Mazzoli, Jul 3, 2017
  5. Ævar Arnfjörð BjarmasonJul 3, 2017
  6. Ævar Arnfjörð BjarmasonJul 3, 2017
  7. Junio C HamanoJul 4, 2017
  8. Francesco MazzoliJul 5, 2017
  9. Junio C HamanoJul 5, 2017
  10. Francesco MazzoliJul 5, 2017
  11. Junio C HamanoJul 5, 2017
  12. Francesco MazzoliJul 5, 2017
  13. Mike RappazzoJul 5, 2017
  14. Junio C HamanoJul 6, 2017
  15. Francesco MazzoliJul 7, 2017
  16. Ævar Arnfjörð BjarmasonJul 5, 2017
  17. Ævar Arnfjörð BjarmasonJul 5, 2017

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.