aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-04-01 17:57:16 -0700
committerJunio C Hamano <gitster@pobox.com>2011-04-01 17:57:16 -0700
commitffc5e3c958b66fb4babeba01483cc924bc2957a5 (patch)
tree4cea1fc19bb4b720d04ac102c2a30f6dec864679 /builtin
parentb966427b53b246e722df1e5502b9145eb9dd063a (diff)
parent93e535a5b78c9861eca3e9371d1c3e5173c0ab02 (diff)
downloadgit-ffc5e3c958b66fb4babeba01483cc924bc2957a5.tar.gz
git-ffc5e3c958b66fb4babeba01483cc924bc2957a5.tar.xz
Merge branch 'jc/merge-sans-branch'
* jc/merge-sans-branch: merge: merge with the default upstream branch without argument merge: match the help text with the documentation Conflicts: builtin/merge.c
Diffstat (limited to 'builtin')
-rw-r--r--builtin/merge.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index 1e0bcfd79..d54e7ddbb 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -25,6 +25,7 @@
#include "help.h"
#include "merge-recursive.h"
#include "resolve-undo.h"
+#include "remote.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
@@ -37,8 +38,9 @@ struct strategy {
};
static const char * const builtin_merge_usage[] = {
- "git merge [options] <remote>...",
- "git merge [options] <msg> HEAD <remote>",
+ "git merge [options] [<commit>...]",
+ "git merge [options] <msg> HEAD <commit>",
+ "git merge --abort",
NULL
};
@@ -59,6 +61,7 @@ static int verbosity;
static int allow_rerere_auto;
static int abort_current_merge;
static int show_progress = -1;
+static int default_to_upstream;
static struct strategy all_strategy[] = {
{ "recursive", DEFAULT_TWOHEAD | NO_TRIVIAL },
@@ -538,6 +541,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)
if (is_bool && shortlog_len)
shortlog_len = DEFAULT_MERGE_LOG_LEN;
return 0;
+ } else if (!strcmp(k, "merge.defaulttoupstream")) {
+ default_to_upstream = git_config_bool(k, v);
+ return 0;
}
return git_diff_ui_config(k, v, cb);
}
@@ -945,6 +951,35 @@ static int evaluate_result(void)
return cnt;
}
+/*
+ * Pretend as if the user told us to merge with the tracking
+ * branch we have for the upstream of the current branch
+ */
+static int setup_with_upstream(const char ***argv)
+{
+ struct branch *branch = branch_get(NULL);
+ int i;
+ const char **args;
+
+ if (!branch)
+ die("No current branch.");
+ if (!branch->remote)
+ die("No remote for the current branch.");
+ if (!branch->merge_nr)
+ die("No default upstream defined for the current branch.");
+
+ args = xcalloc(branch->merge_nr + 1, sizeof(char *));
+ for (i = 0; i < branch->merge_nr; i++) {
+ if (!branch->merge[i]->dst)
+ die("No remote tracking branch for %s from %s",
+ branch->merge[i]->src, branch->remote_name);
+ args[i] = branch->merge[i]->dst;
+ }
+ args[i] = NULL;
+ *argv = args;
+ return i;
+}
+
int cmd_merge(int argc, const char **argv, const char *prefix)
{
unsigned char result_tree[20];
@@ -1027,6 +1062,9 @@ 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 && !abort_current_merge && default_to_upstream)
+ argc = setup_with_upstream(&argv);
+
if (!argc)
usage_with_options(builtin_merge_usage,
builtin_merge_options);