From: Jared Hance <jaredhance@gmail.com>
To: git@vger.kernel.org
Cc: Jared Hance <jaredhance@gmail.com>
Subject: [PATCH] Add support for merging from upstream by default.
Date: Fri, 4 Feb 2011 19:45:21 -0500 [thread overview]
Message-ID: <1296866721-27818-1-git-send-email-jaredhance@gmail.com> (raw)
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 reply other threads:[~2011-02-05 0:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-05 0:45 Jared Hance [this message]
2011-02-05 10:03 ` [PATCH] Add support for merging from upstream by default Andreas Schwab
2011-02-05 13:31 ` Jared Hance
2011-02-07 1:59 ` Junio C Hamano
2011-02-07 9:36 ` Bert Wesarg
2011-02-07 9:43 ` Bert Wesarg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1296866721-27818-1-git-send-email-jaredhance@gmail.com \
--to=jaredhance@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).