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

[PATCH 12/14] pull: configure --rebase via branch.<name>.rebase or pull.rebase

From
Paul Tan <pyokagan@gmail.com>
Date
May 18, 2015, 15:06 UTC
Message-ID
<1431961571-20370-13-git-send-email-pyokagan@gmail.com>
In-Reply-To
<1431961571-20370-1-git-send-email-pyokagan@gmail.com>

Since cd67e4d (Teach 'git pull' about --rebase, 2007-11-28), fetch+rebase could be set by default by defining the config variable branch.<name>.rebase. This setting can be overriden on the command line by --rebase and --no-rebase.

Since 6b37dff (pull: introduce a pull.rebase option to enable --rebase, 2011-11-06), git-pull --rebase can also be configured via the pull.rebase configuration option.

Re-implement support for these two configuration settings by introducing config_get_rebase() which is called before parse_options() to set the default value of opt_rebase.

Signed-off-by: Paul Tan <pyokagan@gmail.com>
---
 builtin/pull.c  | 35 +++++++++++++++++++++++++++++++++++
 t/t5520-pull.sh | 12 ++++++------
 2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/builtin/pull.c b/builtin/pull.c
index f18a21c..a0958a7 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -294,6 +294,39 @@ static const char *config_get_ff(void)
 	die(_("Invalid value for pull.ff: %s"), value);
 }
 
+/**
+ * Returns the default configured value for --rebase. It first looks for the
+ * value of "branch.$curr_branch.rebase", where $curr_branch is the current
+ * branch, and if HEAD is detached or the configuration key does not exist,
+ * looks for the value of "pull.rebase". If both configuration keys do not
+ * exist, returns REBASE_FALSE.
+ */
+static int config_get_rebase(void)
+{
+	struct strbuf sb = STRBUF_INIT;
+	struct branch *curr_branch = branch_get("HEAD");
+	const char *key, *str;
+	int ret = -1, value;
+
+	if (curr_branch) {
+		strbuf_addf(&sb, "branch.%s.rebase", curr_branch->name);
+		key = sb.buf;
+		ret = git_config_get_value(sb.buf, &str);
+	}
+	if (ret) {
+		key = "pull.rebase";
+		ret = git_config_get_value(key, &str);
+	}
+	if (ret) {
+		strbuf_release(&sb);
+		return REBASE_FALSE;
+	}
+	if ((value = parse_config_rebase(str)) < 0)
+		die(_("Invalid value for %s: %s"), key, str);
+	strbuf_release(&sb);
+	return value;
+}
+
 struct known_remote {
 	struct known_remote *next;
 	struct remote *remote;
@@ -730,6 +763,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
 	if (!getenv("GIT_REFLOG_ACTION"))
 		set_reflog_message(argc, argv);
 
+	opt_rebase = config_get_rebase();
+
 	argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
 	parse_repo_refspecs(argc, argv, &repo, &refspecs);
 
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index 3798b96..17254ee 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -234,7 +234,7 @@ test_expect_success '--rebase fails with multiple branches' '
 	test modified = "$(git show HEAD:file)"
 '
 
-test_expect_failure 'pull.rebase' '
+test_expect_success 'pull.rebase' '
 	git reset --hard before-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
@@ -242,7 +242,7 @@ test_expect_failure 'pull.rebase' '
 	test new = "$(git show HEAD:file2)"
 '
 
-test_expect_failure 'branch.to-rebase.rebase' '
+test_expect_success 'branch.to-rebase.rebase' '
 	git reset --hard before-rebase &&
 	test_config branch.to-rebase.rebase true &&
 	git pull . copy &&
@@ -280,7 +280,7 @@ test_expect_success 'pull.rebase=false create a new merge commit' '
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
-test_expect_failure 'pull.rebase=true flattens keep-merge' '
+test_expect_success 'pull.rebase=true flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase true &&
 	git pull . copy &&
@@ -288,7 +288,7 @@ test_expect_failure 'pull.rebase=true flattens keep-merge' '
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
-test_expect_failure 'pull.rebase=1 is treated as true and flattens keep-merge' '
+test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase 1 &&
 	git pull . copy &&
@@ -296,7 +296,7 @@ test_expect_failure 'pull.rebase=1 is treated as true and flattens keep-merge' '
 	test file3 = "$(git show HEAD:file3.t)"
 '
 
-test_expect_failure 'pull.rebase=preserve rebases and merges keep-merge' '
+test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase preserve &&
 	git pull . copy &&
@@ -304,7 +304,7 @@ test_expect_failure 'pull.rebase=preserve rebases and merges keep-merge' '
 	test "$(git rev-parse HEAD^2)" = "$(git rev-parse keep-merge)"
 '
 
-test_expect_failure 'pull.rebase=invalid fails' '
+test_expect_success 'pull.rebase=invalid fails' '
 	git reset --hard before-preserve-rebase &&
 	test_config pull.rebase invalid &&
 	! git pull . copy
-- 
2.1.4
Previous: Paul TanNext: Stefan Beller
Message 30 of 43 in “Make git-pull a builtin”
  1. 00/14 Make git-pull a builtinPaul Tan, May 18, 2015
  2. 01/14 pull: implement fetch + mergePaul Tan, May 18, 2015
  3. Johannes SchindelinMay 18, 2015
  4. 02/14 pull: pass verbosity, --progress flags to fetch and mergePaul Tan, May 18, 2015
  5. Johannes SchindelinMay 18, 2015
  6. Paul TanMay 21, 2015
  7. Johannes SchindelinMay 21, 2015
  8. Paul TanMay 22, 2015
  9. 03/14 pull: pass git-merge's options to git-mergePaul Tan, May 18, 2015
  10. 04/14 pull: pass git-fetch's options to git-fetchPaul Tan, May 18, 2015
  11. 05/14 pull: error on no merge candidatesPaul Tan, May 18, 2015
  12. Johannes SchindelinMay 18, 2015
  13. 06/14 pull: support pull.ff configPaul Tan, May 18, 2015
  14. Johannes SchindelinMay 18, 2015
  15. Paul TanMay 21, 2015
  16. 07/14 pull: check if in unresolved merge statePaul Tan, May 18, 2015
  17. Johannes SchindelinMay 18, 2015
  18. 08/14 pull: fast-forward working tree if head is updatedPaul Tan, May 18, 2015
  19. Johannes SchindelinMay 18, 2015
  20. 09/14 pull: implement pulling into an unborn branchPaul Tan, May 18, 2015
  21. 10/14 pull: set reflog messagePaul Tan, May 18, 2015
  22. Johannes SchindelinMay 18, 2015
  23. Junio C HamanoMay 18, 2015
  24. Paul TanMay 21, 2015
  25. 11/14 pull: teach git pull about --rebasePaul Tan, May 18, 2015
  26. Stefan BellerMay 18, 2015
  27. Johannes SchindelinMay 19, 2015
  28. Paul TanMay 31, 2015
  29. Paul TanJun 2, 2015
  30. 12/14 pull: configure --rebase via branch.<name>.rebase or pull.rebasePaul Tan, May 18, 2015
  31. Stefan BellerMay 18, 2015
  32. 13/14 pull --rebase: exit early when the working directory is dirtyPaul Tan, May 18, 2015
  33. 14/14 pull --rebase: error on no merge candidate casesPaul Tan, May 18, 2015
  34. Stefan BellerMay 19, 2015
  35. Johannes SchindelinMay 19, 2015
  36. Junio C HamanoMay 19, 2015
  37. Paul TanMay 22, 2015
  38. Johannes SchindelinMay 22, 2015
  39. Stefan BellerMay 22, 2015
  40. Junio C HamanoMay 18, 2015
  41. Paul TanMay 30, 2015
  42. Paul TanMay 30, 2015
  43. Johannes SchindelinMay 18, 2015

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.