[RFC PATCH 18/35] update: add per-branch mode configuration
From: Felipe Contreras <hidden>
Date: 2021-07-05 12:32:44
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
Signed-off-by: Felipe Contreras <redacted> --- Documentation/config/branch.txt | 5 +++++ Documentation/config/update.txt | 3 ++- builtin/update.c | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt
index cc5f3249fc..ba355f23e0 100644
--- a/Documentation/config/branch.txt
+++ b/Documentation/config/branch.txt@@ -96,6 +96,11 @@ mode. it unless you understand the implications (see linkgit:git-rebase[1] for details). +branch.<name>.updateMode:: + When `git update` is run, this determines the mode of operation, + possible values are 'fast-forward', 'merge', and 'rebase'. + See `update.mode` for doing this in a non branch-specific manner. + branch.<name>.description:: Branch description, can be edited with `git branch --edit-description`. Branch description is
diff --git a/Documentation/config/update.txt b/Documentation/config/update.txt
index 42a7fe1614..e6db45b6c3 100644
--- a/Documentation/config/update.txt
+++ b/Documentation/config/update.txt@@ -1,4 +1,5 @@ update.mode:: When `git update` is run, this determines the mode of operation, possible values are 'fast-forward', 'merge', and 'rebase'. The default - is 'fast-forward'. + is 'fast-forward'. See "branch.<name>.updateMode" for setting this on a + per-branch basis.
diff --git a/builtin/update.c b/builtin/update.c
index 4a1b82a41d..50905f5806 100644
--- a/builtin/update.c
+++ b/builtin/update.c@@ -7,6 +7,7 @@ #include "run-command.h" #include "config.h" #include "dir.h" +#include "remote.h" enum update_mode_type { UPDATE_MODE_INVALID = -1,
@@ -58,6 +59,22 @@ static int git_update_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } +static void get_branch_config(void) +{ + struct branch *cur_branch = branch_get("HEAD"); + char *key; + const char *value; + + if (!cur_branch) + return; + + key = xstrfmt("branch.%s.updatemode", cur_branch->name); + if (!git_config_get_value(key, &value)) + mode = update_mode_parse_value(value); + + free(key); +} + static int run_fetch(void) { struct strvec args = STRVEC_INIT;
@@ -112,6 +129,7 @@ int cmd_update(int argc, const char **argv, const char *prefix) setenv("GIT_REFLOG_ACTION", "update", 0); git_config(git_update_config, NULL); + get_branch_config(); argc = parse_options(argc, argv, prefix, update_options, update_usage, 0);
--
2.32.0.36.g70aac2b1aa