git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH 11/18] merge: Add a new --index-only option, not yet implemented

From
Elijah Newren <newren@gmail.com>
Date
Apr 8, 2016, 06:58 UTC
Message-ID
<1460098726-5958-12-git-send-email-newren@gmail.com>
In-Reply-To
<1460098726-5958-1-git-send-email-newren@gmail.com>
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
Previous: Elijah NewrenNext: Junio C Hamano
Message 16 of 30 in “Add --index-only option to git merge”
  1. 00/18 Add --index-only option to git mergeElijah Newren, Apr 8, 2016
  2. 01/18 Remove duplicate codeElijah Newren, Apr 8, 2016
  3. Junio C HamanoApr 8, 2016
  4. 02/18 Avoid checking working copy when creating a virtual merge baseElijah Newren, Apr 8, 2016
  5. 03/18 Document weird bug in octopus merges via testcasesElijah Newren, Apr 8, 2016
  6. 04/18 merge-octopus: Abort if index not cleanElijah Newren, Apr 8, 2016
  7. Junio C HamanoApr 8, 2016
  8. 05/18 Add testcase for --index-only merges needing the recursive strategyElijah Newren, Apr 8, 2016
  9. Junio C HamanoApr 8, 2016
  10. Junio C HamanoApr 8, 2016
  11. 06/18 Add testcase for --index-only merges needing an ff updateElijah Newren, Apr 8, 2016
  12. 07/18 Add testcase for --index-only merges with the resolve strategyElijah Newren, Apr 8, 2016
  13. 08/18 Add testcase for --index-only merges with the octopus strategyElijah Newren, Apr 8, 2016
  14. 09/18 Add testcase for --index-only merges with the ours strategyElijah Newren, Apr 8, 2016
  15. 10/18 Add testcase for --index-only merges with the subtree strategyElijah Newren, Apr 8, 2016
  16. 11/18 merge: Add a new --index-only option, not yet implementedElijah Newren, Apr 8, 2016
  17. Junio C HamanoApr 8, 2016
  18. 12/18 Add --index-only support for recursive mergesElijah Newren, Apr 8, 2016
  19. 13/18 Add --index-only support with read_tree_trivial merges, kind ofElijah Newren, Apr 8, 2016
  20. 14/18 Add --index-only support for ff_only mergesElijah Newren, Apr 8, 2016
  21. 15/18 merge: Pass --index-only along to external merge strategy programsElijah Newren, Apr 8, 2016
  22. 16/18 git-merge-one-file.sh: support --index-only optionElijah Newren, Apr 8, 2016
  23. 17/18 git-merge-resolve.sh: support --index-only optionElijah Newren, Apr 8, 2016
  24. 18/18 git-merge-octopus.sh: support --index-only optionElijah Newren, Apr 8, 2016
  25. Michael J GruberApr 8, 2016
  26. Elijah NewrenApr 9, 2016
  27. Junio C HamanoApr 8, 2016
  28. Elijah NewrenApr 9, 2016
  29. Junio C HamanoApr 9, 2016
  30. Elijah NewrenApr 10, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.