[RFC PATCH 27/35] pull: add per-branch mode configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Many people have argued that `git pull` should have a per-branch
configuration for its mode of operation (e.g. Linus Torvalds [1] and
Theodore Ts'o [2]).

branch.<name>.pullMode achieves that.

[1] https://lore.kernel.org/git/CA+55aFz2Uvq4vmyjJPao5tS-uuVvKm6mbP7Uz8sdq1VMxMGJCw@xxxxxxxxxxxxxx/
[2] https://lore.kernel.org/git/20130312212027.GE14792@xxxxxxxxx/

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 Documentation/config/branch.txt |  5 +++++
 Documentation/config/pull.txt   |  3 ++-
 builtin/pull.c                  | 13 +++++++++++++
 t/t5520-pull.sh                 | 11 +++++++++++
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/Documentation/config/branch.txt b/Documentation/config/branch.txt
index ba355f23e0..5f412caf62 100644
--- a/Documentation/config/branch.txt
+++ b/Documentation/config/branch.txt
@@ -101,6 +101,11 @@ branch.<name>.updateMode::
 	possible values are 'fast-forward', 'merge', and 'rebase'.
 	See `update.mode` for doing this in a non branch-specific manner.
 
+branch.<name>.pullMode::
+	When `git pull` is run, this determines the mode of operation,
+	possible values are 'merge' and 'rebase'. See `pull.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/pull.txt b/Documentation/config/pull.txt
index 646431a02d..3fb9bfdfea 100644
--- a/Documentation/config/pull.txt
+++ b/Documentation/config/pull.txt
@@ -32,7 +32,8 @@ for details).
 pull.mode::
 	When "git pull" is run, this determines if it would either merge or
 	rebase the fetched branch. The possible values are 'merge',
-	and 'rebase'.
+	and 'rebase'. See "branch.<name>.pullMode" for setting this on a
+	per-branch basis.
 
 pull.octopus::
 	The default merge strategy to use when pulling multiple branches
diff --git a/builtin/pull.c b/builtin/pull.c
index 124575c32c..bb3c0b55f9 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -374,8 +374,21 @@ static enum rebase_type config_get_rebase(void)
 
 static enum pull_mode_type config_get_pull_mode(const char *repo)
 {
+	struct branch *curr_branch = branch_get("HEAD");
 	const char *value;
 
+	if (curr_branch) {
+		char *key = xstrfmt("branch.%s.pullmode", curr_branch->name);
+
+		if (!git_config_get_value(key, &value)) {
+			enum pull_mode_type ret = parse_config_pull_mode(key, value);
+			free(key);
+			return ret;
+		}
+
+		free(key);
+	}
+
 	if (!git_config_get_value("pull.mode", &value))
 		return parse_config_pull_mode("pull.mode", value);
 
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 663c15fcd7..59894dd15a 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -493,6 +493,17 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' '
 	test_cmp expect actual
 '
 
+test_expect_success 'branch..pullmode overrides pull.mode' '
+	git reset --hard before-rebase &&
+	test_config pull.mode rebase &&
+	test_config branch.to-rebase.pullmode merge &&
+	git pull . copy &&
+	test_cmp_rev ! HEAD^ copy &&
+	echo new >expect &&
+	git show HEAD:file2 >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'pull --rebase warns on --verify-signatures' '
 	git reset --hard before-rebase &&
 	git pull --rebase --verify-signatures . copy 2>err &&
-- 
2.32.0.36.g70aac2b1aa




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux