From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>,
jean-luc malet <jeanluc.malet@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 3/3] builtin-merge: add support for default merge options
Date: Fri, 6 Mar 2009 19:44:35 -0500 [thread overview]
Message-ID: <1236386675-23308-1-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <76718490903061516l62869424q4bd4cfa64fe2195e@mail.gmail.com>
This patch teaches merge a new setting, merge.options, which is
processed before any of the other merge configuration settings. It may
be used to establish a default which can then be overridden by more
specific branch.<name>.mergeoptions (or, obviously, command-line
switches).
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
On Fri, Mar 6, 2009 at 5:46 PM, Junio C Hamano <gitster@pobox.com> wrote:
> If for some reason you would want to have cumulative options across
> branch.*.merge, merge.options and the command line, then you would instead
> keep two separate strings, and call git_config_option_string() for both of
> them, before processing the real command line options.
Which is what this version does. I also made the explanation of this behavior
in the man page more explicit.
Documentation/git-merge.txt | 12 +++++--
builtin-merge.c | 22 +++++++++++--
t/t7600-merge.sh | 69 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index f7be584..5d80a78 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -47,10 +47,16 @@ CONFIGURATION
-------------
include::merge-config.txt[]
+merge.options::
+ Sets default options for merging. The syntax and supported options are
+ equal to that of 'git-merge'. Arguments are split by spaces, and may be
+ quoted in the same way as alias.* config options.
+
branch.<name>.mergeoptions::
- Sets default options for merging into branch <name>. The syntax and
- supported options are equal to that of 'git-merge', but option values
- containing whitespace characters are currently not supported.
+ Sets default options for merging into branch <name>. This setting is
+ handled after and is cumulative to `merge.options`. So it may override,
+ but does replace, any settings appearing there. The syntax is identical
+ to `merge.options`.
HOW MERGE WORKS
---------------
diff --git a/builtin-merge.c b/builtin-merge.c
index 504f2be..d4dc4fe 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -50,6 +50,8 @@ static unsigned char head[20], stash[20];
static struct strategy **use_strategies;
static size_t use_strategies_nr, use_strategies_alloc;
static const char *branch;
+static const char *branch_option_string = NULL;
+static const char *default_option_string = NULL;
static int verbosity;
static struct strategy all_strategy[] = {
@@ -451,10 +453,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
{
if (branch && !prefixcmp(k, "branch.") &&
!prefixcmp(k + 7, branch) &&
- !strcmp(k + 7 + strlen(branch), ".mergeoptions")) {
- if (git_config_option_string(builtin_merge_options, 0, k, v))
- die("Bad branch.%s.mergeoptions string", branch);
- }
+ !strcmp(k + 7 + strlen(branch), ".mergeoptions"))
+ return git_config_string(&branch_option_string, k, v);
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat"))
show_diffstat = git_config_bool(k, v);
@@ -462,6 +462,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)
return git_config_string(&pull_twohead, k, v);
else if (!strcmp(k, "pull.octopus"))
return git_config_string(&pull_octopus, k, v);
+ else if (!strcmp(k, "merge.options"))
+ return git_config_string(&default_option_string, k, v);
else if (!strcmp(k, "merge.log") || !strcmp(k, "merge.summary"))
option_log = git_config_bool(k, v);
return git_diff_ui_config(k, v, cb);
@@ -839,6 +841,18 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
head_invalid = 1;
git_config(git_merge_config, NULL);
+ if (default_option_string) {
+ if (git_config_option_string(builtin_merge_options, 0,
+ "merge.options", default_option_string))
+ die("Bad merge.options string");
+ }
+ if (branch_option_string) {
+ strbuf_addf(&buf, "branch.%s.mergeoptions", branch);
+ if (git_config_option_string(builtin_merge_options, 0,
+ buf.buf, branch_option_string))
+ die("Bad %s string", buf.buf);
+ strbuf_reset(&buf);
+ }
/* for color.ui */
if (diff_use_color_default == -1)
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 9db8bb4..aaecdab 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -367,6 +367,16 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
test_debug 'gitk --all'
+test_expect_success 'merge c1 with c2 (no-commit in merge.options)' '
+ git reset --hard c1 &&
+ with_config merge.options --no-commit -- merge c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_mergeheads $c2
+'
+
+test_debug 'gitk --all'
+
test_expect_success 'merge c1 with c2 (squash in config)' '
git reset --hard c1 &&
with_config branch.master.mergeoptions --squash -- \
@@ -379,6 +389,17 @@ test_expect_success 'merge c1 with c2 (squash in config)' '
test_debug 'gitk --all'
+test_expect_success 'merge c1 with c2 (squash in merge.options)' '
+ git reset --hard c1 &&
+ with_config merge.options --squash -- merge c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_no_mergehead &&
+ verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
test_expect_success 'override config option -n with --summary' '
git reset --hard c1 &&
test_tick &&
@@ -425,6 +446,54 @@ test_expect_success 'override config option --stat' '
test_debug 'gitk --all'
+test_expect_success 'override merge.options -n with branch mergeoptions --summary' '
+ git reset --hard c1 &&
+ test_tick &&
+ with_config merge.options -n branch.master.mergeoptions --summary -- \
+ merge c2 >diffstat.txt &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2 &&
+ if ! grep "^ file | *2 +-$" diffstat.txt
+ then
+ echo "[OOPS] diffstat was not generated with --summary"
+ false
+ fi
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override merge.options -n with branch mergeoptions --stat' '
+ git reset --hard c1 &&
+ test_tick &&
+ with_config merge.options -n branch.master.mergeoptions --stat -- \
+ merge c2 >diffstat.txt &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2 &&
+ if ! grep "^ file | *2 +-$" diffstat.txt
+ then
+ echo "[OOPS] diffstat was not generated with --stat"
+ false
+ fi
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override merge.options --stat' '
+ git reset --hard c1 &&
+ test_tick &&
+ with_config merge.options --stat branch.master.mergeoptions -n -- \
+ merge c2 >diffstat.txt &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2 &&
+ if grep "^ file | *2 +-$" diffstat.txt
+ then
+ echo "[OOPS] diffstat was generated"
+ false
+ fi
+'
+
+test_debug 'gitk --all'
+
test_expect_success 'merge c1 with c2 (override --no-commit)' '
git reset --hard c1 &&
test_tick &&
--
1.6.2.rc2.332.g5d21b
next prev parent reply other threads:[~2009-03-07 0:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-06 22:15 [PATCH 0/3] Re: how to have --no-ff be the default for all branch Jay Soffian
2009-03-06 22:15 ` [PATCH 1/3] config: add git_config_option_string() Jay Soffian
2009-03-06 22:15 ` [PATCH 2/3] builtin-merge: refactor to use git_config_option_string Jay Soffian
2009-03-06 22:15 ` [PATCH 3/3] builtin-merge: add support for default merge options Jay Soffian
2009-03-06 22:46 ` Junio C Hamano
2009-03-06 23:16 ` Jay Soffian
2009-03-07 0:44 ` Jay Soffian [this message]
2009-03-07 0:58 ` Junio C Hamano
2009-03-07 1:56 ` Jay Soffian
2009-03-07 7:18 ` Junio C Hamano
2009-03-07 13:48 ` Jay Soffian
2009-03-07 19:31 ` jean-luc malet
2010-03-19 14:19 ` jean-luc malet
2010-03-19 14:54 ` Jay Soffian
2010-04-02 17:19 ` jean-luc malet
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=1236386675-23308-1-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jeanluc.malet@gmail.com \
/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).