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

[PATCH] Add support for merging from upstream by default.

From
Jared Hance <jaredhance@gmail.com>
Date
Feb 5, 2011, 00:45 UTC
Message-ID
<1296866721-27818-1-git-send-email-jaredhance@gmail.com>

Adds the option merge.defaultupstream to add support for merging from the upstream branch by default. The upstream branch is found using branch.[name].upstream. ---

So it turns out that the old code _did_ work with options; I had thought it hadn't because I relied on !argc == 0, but since argc is decreased after parsing options anyway, it isn't a problem. This update fixes the usage as Junio suggested, since it does support options.

 builtin/merge.c |   41 +++++++++++++++++++++++++++++++++++------
 1 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 42fff38..a69b69f 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -37,6 +37,7 @@ struct strategy {
 };
 
 static const char * const builtin_merge_usage[] = {
+        "git merge",
 	"git merge [options] <remote>...",
 	"git merge [options] <msg> HEAD <remote>",
 	NULL
@@ -58,6 +59,8 @@ static int option_renormalize;
 static int verbosity;
 static int allow_rerere_auto;
 static int abort_current_merge;
+static int default_upstream;
+static const char *upstream_branch;
 
 static struct strategy all_strategy[] = {
 	{ "recursive",  DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -519,8 +522,15 @@ static int git_merge_config(const char *k, const char *v, void *cb)
 			      builtin_merge_usage, 0);
 		free(buf);
 	}
-
-	if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
+        else if(branch && !prefixcmp(k, "branch.") &&
+                !prefixcmp(k + 7, branch) &&
+                !strcmp(k + 7 + strlen(branch), ".upstream")) {
+                return git_config_string(&upstream_branch, k, v);
+        }
+
+        if (!strcmp(k, "merge.defaultupstream"))
+                default_upstream = git_config_bool(k, v);
+        else if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
 		show_diffstat = git_config_bool(k, v);
 	else if (!strcmp(k, "pull.twohead"))
 		return git_config_string(&pull_twohead, k, v);
@@ -983,9 +993,28 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (!allow_fast_forward && fast_forward_only)
 		die("You cannot combine --no-ff with --ff-only.");
 
-	if (!argc)
-		usage_with_options(builtin_merge_usage,
-			builtin_merge_options);
+	if (!argc) {
+                if(default_upstream && upstream_branch) {
+		        struct object *o;
+                        struct commit *commit;
+
+                        o = peel_to_type(upstream_branch, 0, NULL, OBJ_COMMIT);
+                        if (!o)
+                            die("%s - not something we can merge", argv[i]);
+                        commit = lookup_commit(o->sha1);
+                        commit->util = (void *)upstream_branch;
+                        remotes = &commit_list_insert(commit, remotes)->next;
+
+                        strbuf_addf(&buf, "GITHEAD_%s", sha1_to_hex(o->sha1));
+                        setenv(buf.buf, upstream_branch, 1);
+                        strbuf_reset(&buf);
+                }
+                else {
+		        usage_with_options(builtin_merge_usage,
+			        builtin_merge_options);
+
+                }
+        }
 
 	/*
 	 * This could be traditional "merge <msg> HEAD <commit>..."  and
@@ -1048,7 +1077,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		}
 	}
 
-	if (head_invalid || !argc)
+	if (head_invalid || (!argc && !(default_upstream && upstream_branch)))
 		usage_with_options(builtin_merge_usage,
 			builtin_merge_options);
 
-- 
1.7.4
Next: Andreas Schwab
Message 1 of 6 in “Add support for merging from upstream by default.”
  1. Add support for merging from upstream by default.Jared Hance, Feb 5, 2011
  2. Andreas SchwabFeb 5, 2011
  3. Add support for merging from upstream by default.Jared Hance, Feb 5, 2011
  4. Junio C HamanoFeb 7, 2011
  5. Bert WesargFeb 7, 2011
  6. Bert WesargFeb 7, 2011

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.