From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 4/4] merge: introduce merge.allowUnrelatedhistories configuration option
Date: Thu, 21 Apr 2016 12:25:00 -0700 [thread overview]
Message-ID: <20160421192500.23563-5-gitster@pobox.com> (raw)
In-Reply-To: <20160421192500.23563-1-gitster@pobox.com>
It was rumored that in an unspecified workflow it is common to
create what Kernel folks call "crazy" and "insane" merges of two
unrelated histories, and having to give --allow-unrelated-histories
option every time is cumbersome.
Just in case the rumor will substanticated with a proper rationale
in the future, prepare a change to allow disabling the safety by
default.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Documentation/git.txt | 4 ++++
Documentation/merge-config.txt | 7 +++++++
builtin/merge.c | 3 +++
t/t3033-merge-toplevel.sh | 29 +++++++++++++++++++++++++++++
t/t5521-pull-options.sh | 9 ++++++++-
5 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 5c9380d..f2edac1 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -1140,6 +1140,10 @@ of clones and fetches.
'GIT_MERGE_ALLOW_UNRELATED_HISTORIES'::
Allow "git merge" to merge unrelated histories by default.
+ It is recommended that a script that regularly wants to
+ create such a merge to set and export this environment
+ variable upfront, instead of forcing its users to set
+ merge.allowunrelatedhistories configuration variable.
Discussion[[Discussion]]
diff --git a/Documentation/merge-config.txt b/Documentation/merge-config.txt
index 002ca58..8b3d14b 100644
--- a/Documentation/merge-config.txt
+++ b/Documentation/merge-config.txt
@@ -47,6 +47,13 @@ merge.stat::
Whether to print the diffstat between ORIG_HEAD and the merge result
at the end of the merge. True by default.
+merge.allowUnrelatedhistories::
+ Setting this option to true (false) makes `git merge` and `git
+ pull` to pretend as if the `--allow-unrelated-histories`
+ (`--no-allow-unrelated-histories`) option was given from the
+ command line. The configuration is ignored when one of these
+ options is explicitly given from the command line.
+
merge.tool::
Controls which merge tool is used by linkgit:git-mergetool[1].
The list below shows the valid built-in values.
diff --git a/builtin/merge.c b/builtin/merge.c
index 4e8b1a1..e979c68 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -583,6 +583,9 @@ static int git_merge_config(const char *k, const char *v, void *cb)
} else if (!strcmp(k, "commit.gpgsign")) {
sign_commit = git_config_bool(k, v) ? "" : NULL;
return 0;
+ } else if (!strcmp(k, "merge.allowunrelatedhistories")) {
+ allow_unrelated_histories = git_config_bool(k, v);
+ return 0;
}
status = fmt_merge_msg_config(k, v, cb);
diff --git a/t/t3033-merge-toplevel.sh b/t/t3033-merge-toplevel.sh
index d314599..583b837 100755
--- a/t/t3033-merge-toplevel.sh
+++ b/t/t3033-merge-toplevel.sh
@@ -149,4 +149,33 @@ test_expect_success 'two-project merge with --allow-unrelated-histories' '
git diff --exit-code five
'
+test_expect_success 'two-project merge with merge.allowunrelatedhistories' '
+ t3033_reset &&
+
+ # make sure configuration parser works
+ git reset --hard four &&
+ test_config merge.allowunrelatedhistories notabool &&
+ test_must_fail git merge . HEAD &&
+
+ # disabled explicitly and redundantly by configuration
+ git reset --hard four &&
+ test_config merge.allowunrelatedhistories false &&
+ test_must_fail git merge five &&
+
+ # disabled explicitly by configuration, overridden by command line
+ git reset --hard four &&
+ test_config merge.allowunrelatedhistories false &&
+ git merge --allow-unrelated-histories five &&
+
+ # enabled by configuration but explicitly disabled
+ git reset --hard four &&
+ test_config merge.allowunrelatedhistories true &&
+ test_must_fail git merge --no-allow-unrelated-histories five &&
+
+ # enabled by configuration
+ git reset --hard four &&
+ test_config merge.allowunrelatedhistories true &&
+ git merge five
+'
+
test_done
diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh
index ded8f98..50f0887 100755
--- a/t/t5521-pull-options.sh
+++ b/t/t5521-pull-options.sh
@@ -161,7 +161,14 @@ test_expect_success 'git pull --allow-unrelated-histories' '
(
cd dst &&
test_must_fail git pull ../src side &&
- git pull --allow-unrelated-histories ../src side
+ git pull --allow-unrelated-histories ../src side &&
+
+ git reset --hard one &&
+ git config merge.allowunrelatedhistories no &&
+ test_must_fail git pull ../src side &&
+ git config merge.allowunrelatedhistories yes &&
+ test_must_fail git pull --no-allow-unrelated-histories ../src side &&
+ git pull ../src side
)
'
--
2.8.1-422-g6d9b748
next prev parent reply other threads:[~2016-04-21 19:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-21 19:24 [PATCH 0/4] Loosening "two project merge" safety Junio C Hamano
2016-04-21 19:24 ` [PATCH 1/4] t3033: avoid 'ambiguous refs' warning Junio C Hamano
2016-04-21 19:24 ` [PATCH 2/4] pull: pass --allow-unrelated-histories to "git merge" Junio C Hamano
2016-04-21 19:36 ` Stefan Beller
2016-04-21 21:32 ` Junio C Hamano
2016-04-21 19:24 ` [PATCH 3/4] merge: GIT_MERGE_ALLOW_UNRELATED_HISTORIES environment Junio C Hamano
2016-04-21 19:25 ` Junio C Hamano [this message]
2016-04-21 22:29 ` [PATCH 0/4] Loosening "two project merge" safety Junio C Hamano
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=20160421192500.23563-5-gitster@pobox.com \
--to=gitster@pobox.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).