[RFC/PATCH 11/18] merge: Add a new --index-only option, not yet implemented
Subsequent commits will add implementation for each relevant merge strategy
Signed-off-by: Elijah Newren <newren@gmail.com>
---
Documentation/git-merge.txt | 14 ++++++++++++++
builtin/merge.c | 7 +++++++
git.c | 2 +-
merge-recursive.c | 1 +
merge-recursive.h | 1 +
t/t6043-merge-index-only.sh | 4 ++--
6 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 07f7295..82a6d43 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -86,6 +86,20 @@ invocations. The automated message can include the branch description.
Allow the rerere mechanism to update the index with the
result of auto-conflict resolution if possible.
+--index-only::
+ Perform merge on index only, leaving working tree alone. Most
+ users do NOT want to use this flag, as it will leave the
+ working tree and the index completely out of sync, which is
+ very likely to confuse users and prevent a subsequent 'git
+ merge --abort' from working. It is intended for script
+ writers to have a way to easily check whether a merge would
+ succeed and which files would conflict, typically from bare
+ clones.
++
+Note that files other than the index in the git-dir may also be
+modified when using this flag (e.g. MERGE_HEAD, MERGE_MSG, MERGE_RR,
+HEAD, whatever HEAD points at, and new objects under objects/).
+
--abort::
Abort the current conflict resolution process, and
try to reconstruct the pre-merge state.
diff --git a/builtin/merge.c b/builtin/merge.c
index 101ffef..ce5be0a 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -63,6 +63,7 @@ static char *branch_mergeoptions;
static int option_renormalize;
static int verbosity;
static int allow_rerere_auto;
+static int index_only = 0;
static int abort_current_merge;
static int show_progress = -1;
static int default_to_upstream = 1;
@@ -221,6 +222,8 @@ static struct option builtin_merge_options[] = {
OPT__VERBOSITY(&verbosity),
OPT_BOOL(0, "abort", &abort_current_merge,
N_("abort the current in-progress merge")),
+ OPT_BOOL(0, "index-only", &index_only,
+ N_("perform merge on index only, leaving working tree alone")),
OPT_SET_INT(0, "progress", &show_progress, N_("force progress reporting"), 1),
{ OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"),
N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
@@ -663,6 +666,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
o.subtree_shift = "";
o.renormalize = option_renormalize;
+ o.index_only = index_only;
o.show_rename_progress =
show_progress == -1 ? isatty(2) : show_progress;
@@ -1193,6 +1197,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
parse_branch_merge_options(branch_mergeoptions);
argc = parse_options(argc, argv, prefix, builtin_merge_options,
builtin_merge_usage, 0);
+ if (!index_only)
+ setup_work_tree();
+
if (shortlog_len < 0)
shortlog_len = (merge_log_config > 0) ? merge_log_config : 0;
diff --git a/git.c b/git.c
index 6cc0c07..b07485a 100644
--- a/git.c
+++ b/git.c
@@ -427,7 +427,7 @@ static struct cmd_struct commands[] = {
{ "ls-tree", cmd_ls_tree, RUN_SETUP },
{ "mailinfo", cmd_mailinfo },
{ "mailsplit", cmd_mailsplit },
- { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
+ { "merge", cmd_merge, RUN_SETUP },
{ "merge-base", cmd_merge_base, RUN_SETUP },
{ "merge-file", cmd_merge_file, RUN_SETUP_GENTLY },
{ "merge-index", cmd_merge_index, RUN_SETUP },
diff --git a/merge-recursive.c b/merge-recursive.c
index 06d31ed..b346ed6 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -2041,6 +2041,7 @@ void init_merge_options(struct merge_options *o)
o->merge_rename_limit = -1;
o->renormalize = 0;
o->detect_rename = 1;
+ o->index_only = 0;
merge_recursive_config(o);
if (getenv("GIT_MERGE_VERBOSITY"))
o->verbosity =
diff --git a/merge-recursive.h b/merge-recursive.h
index 52f0201..7e9955f 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -15,6 +15,7 @@ struct merge_options {
const char *subtree_shift;
unsigned buffer_output : 1;
unsigned renormalize : 1;
+ unsigned index_only : 1;
long xdl_opts;
int verbosity;
int detect_rename;
diff --git a/t/t6043-merge-index-only.sh b/t/t6043-merge-index-only.sh
index 5eda6b3..9bb64d8 100755
--- a/t/t6043-merge-index-only.sh
+++ b/t/t6043-merge-index-only.sh
@@ -374,7 +374,7 @@ test_expect_failure '--index-only octopus, bare' '
)
'
-test_expect_failure '--index-only ours, non-bare' '
+test_expect_success '--index-only ours, non-bare' '
git reset --hard &&
git checkout B^0 &&
@@ -387,7 +387,7 @@ test_expect_failure '--index-only ours, non-bare' '
test ! -f c
'
-test_expect_failure '--index-only ours, bare' '
+test_expect_success '--index-only ours, bare' '
rm -rf bare.clone &&
git clone --bare . bare.clone &&
(cd bare.clone &&
--
2.8.0.18.gc685494