Merge branch 'jc/merge-refuse-new-root'
"git pull" has been taught to pass --allow-unrelated-histories option to underlying "git merge". * jc/merge-refuse-new-root: pull: pass --allow-unrelated-histories to "git merge" t3033: avoid 'ambiguous refs' warningmaint
commit
175008d454
|
@ -11,6 +11,7 @@ SYNOPSIS
|
||||||
[verse]
|
[verse]
|
||||||
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
|
'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
|
||||||
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
|
[-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
|
||||||
|
[--[no-]allow-unrelated-histories]
|
||||||
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
|
[--[no-]rerere-autoupdate] [-m <msg>] [<commit>...]
|
||||||
'git merge' <msg> HEAD <commit>...
|
'git merge' <msg> HEAD <commit>...
|
||||||
'git merge' --abort
|
'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
|
'git merge --abort' is equivalent to 'git reset --merge' when
|
||||||
`MERGE_HEAD` is present.
|
`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>...::
|
<commit>...::
|
||||||
Commits, usually other branch heads, to merge into our branch.
|
Commits, usually other branch heads, to merge into our branch.
|
||||||
Specifying more than one commit will create a merge with
|
Specifying more than one commit will create a merge with
|
||||||
|
|
|
@ -114,3 +114,11 @@ ifndef::git-pull[]
|
||||||
reporting.
|
reporting.
|
||||||
|
|
||||||
endif::git-pull[]
|
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.
|
||||||
|
|
|
@ -91,6 +91,7 @@ static int config_autostash;
|
||||||
static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
|
static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
|
||||||
static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
|
static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
|
||||||
static char *opt_gpg_sign;
|
static char *opt_gpg_sign;
|
||||||
|
static int opt_allow_unrelated_histories;
|
||||||
|
|
||||||
/* Options passed to git-fetch */
|
/* Options passed to git-fetch */
|
||||||
static char *opt_all;
|
static char *opt_all;
|
||||||
|
@ -163,6 +164,9 @@ static struct option pull_options[] = {
|
||||||
OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"),
|
OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"),
|
||||||
N_("GPG sign commit"),
|
N_("GPG sign commit"),
|
||||||
PARSE_OPT_OPTARG),
|
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 */
|
/* Options passed to git-fetch */
|
||||||
OPT_GROUP(N_("Options related to fetching")),
|
OPT_GROUP(N_("Options related to fetching")),
|
||||||
|
@ -628,6 +632,8 @@ static int run_merge(void)
|
||||||
argv_array_pushv(&args, opt_strategy_opts.argv);
|
argv_array_pushv(&args, opt_strategy_opts.argv);
|
||||||
if (opt_gpg_sign)
|
if (opt_gpg_sign)
|
||||||
argv_array_push(&args, 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");
|
argv_array_push(&args, "FETCH_HEAD");
|
||||||
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
|
ret = run_command_v_opt(args.argv, RUN_GIT_CMD);
|
||||||
|
|
|
@ -19,7 +19,7 @@ test_expect_success setup '
|
||||||
test_commit three &&
|
test_commit three &&
|
||||||
git checkout right &&
|
git checkout right &&
|
||||||
test_commit four &&
|
test_commit four &&
|
||||||
git checkout --orphan five &&
|
git checkout --orphan newroot &&
|
||||||
test_commit five &&
|
test_commit five &&
|
||||||
git checkout master
|
git checkout master
|
||||||
'
|
'
|
||||||
|
|
|
@ -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
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue