pull: pass --allow-unrelated-histories to "git merge"
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Mar 2016 20:21:09 +0000 (13:21 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Apr 2016 18:58:51 +0000 (11:58 -0700)
The previous commit said:

We could add the same option to "git pull" and have it passed
through to underlying "git merge". I do not have a fundamental
opposition against such a feature, but this commit does not do
so and instead leaves it as low-hanging fruit for others,
because such a "two project merge" would be done after fetching
the other project into some location in the working tree of an
existing project and making sure how well they fit together, it
is sufficient to allow a local merge without such an option
pass-through from "git pull" to "git merge".

Prepare a patch to make it a reality, just in case it is needed.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-merge.txt
Documentation/merge-options.txt
builtin/pull.c
t/t5521-pull-options.sh
index 689aa4c57cca66c7cd92235248eee2b32ff20451..b758d5556caaeeb0a439d67c46100e5fa0d34cd4 100644 (file)
@@ -11,6 +11,7 @@ SYNOPSIS
 [verse]
 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
        [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
+       [--[no-]allow-unrelated-histories]
        [--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
 'git merge' <msg> HEAD <commit>...
 'git merge' --abort
@@ -98,19 +99,6 @@ commit or stash your changes before running 'git merge'.
 'git merge --abort' is equivalent to 'git reset --merge' when
 `MERGE_HEAD` is present.
 
---allow-unrelated-histories::
-       By default, `git merge` command refuses to merge histories
-       that do not share a common ancestor.  This option can be
-       used to override this safety when merging histories of two
-       projects that started their lives independently.  As that is
-       a very rare occasion, no configuration variable to enable
-       this by default exists and will not be added, and the list
-       of options at the top of this documentation does not mention
-       this option.  Also `git pull` does not pass this option down
-       to `git merge` (instead, you `git fetch` first, examine what
-       you will be merging and then `git merge` locally with this
-       option).
-
 <commit>...::
        Commits, usually other branch heads, to merge into our branch.
        Specifying more than one commit will create a merge with
index f08e9b80c562faa1de2408cd4cfdb7253d3be1f2..dfb43d000fa8f539a99bae771fca87abfd46e507 100644 (file)
@@ -114,3 +114,11 @@ ifndef::git-pull[]
        reporting.
 
 endif::git-pull[]
+
+--allow-unrelated-histories::
+       By default, `git merge` command refuses to merge histories
+       that do not share a common ancestor.  This option can be
+       used to override this safety when merging histories of two
+       projects that started their lives independently. As that is
+       a very rare occasion, no configuration variable to enable
+       this by default exists and will not be added.
index 5145fc60a0377a7fb799555892909f979aca9076..797932d0b029ca8156822ec8f1b487b1199b648a 100644 (file)
@@ -86,6 +86,7 @@ static char *opt_verify_signatures;
 static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
 static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
 static char *opt_gpg_sign;
+static int opt_allow_unrelated_histories;
 
 /* Options passed to git-fetch */
 static char *opt_all;
@@ -155,6 +156,9 @@ static struct option pull_options[] = {
        OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"),
                N_("GPG sign commit"),
                PARSE_OPT_OPTARG),
+       OPT_SET_INT(0, "allow-unrelated-histories",
+                   &opt_allow_unrelated_histories,
+                   N_("allow merging unrelated histories"), 1),
 
        /* Options passed to git-fetch */
        OPT_GROUP(N_("Options related to fetching")),
@@ -603,6 +607,8 @@ static int run_merge(void)
        argv_array_pushv(&args, opt_strategy_opts.argv);
        if (opt_gpg_sign)
                argv_array_push(&args, opt_gpg_sign);
+       if (opt_allow_unrelated_histories > 0)
+               argv_array_push(&args, "--allow-unrelated-histories");
 
        argv_array_push(&args, "FETCH_HEAD");
        ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
index 18372caa151a30ac0ec1f247e793164fe667358a..ded8f98dbed9764744799f7b4bed0c51fc57a158 100755 (executable)
@@ -144,4 +144,25 @@ test_expect_success 'git pull --all --dry-run' '
        )
 '
 
+test_expect_success 'git pull --allow-unrelated-histories' '
+       test_when_finished "rm -fr src dst" &&
+       git init src &&
+       (
+               cd src &&
+               test_commit one &&
+               test_commit two
+       ) &&
+       git clone src dst &&
+       (
+               cd src &&
+               git checkout --orphan side HEAD^ &&
+               test_commit three
+       ) &&
+       (
+               cd dst &&
+               test_must_fail git pull ../src side &&
+               git pull --allow-unrelated-histories ../src side
+       )
+'
+
 test_done