@@ -38,6 +38,11 @@ See `OUTPUT` below for details.
OPTIONS
-------
+--exclude-oids-and-modes::
+ Instead of writing a list of (mode, oid, stage, path) tuples
+ to output for conflicted files, just provide a list of
+ filenames with conflicts.
+
--[no-]messages::
Write any informational messages such as "Auto-merging <path>"
or CONFLICT notices to the end of stdout. If unspecified, the
@@ -55,7 +60,7 @@ simply one line:
Whereas for a conflicted merge, the output is by default of the form:
<OID of toplevel tree>
- <Conflicted file list>
+ <Conflicted file info>
<Informational messages>
These are discussed individually below.
@@ -67,18 +72,23 @@ This is a tree object that represents what would be checked out in the
working tree at the end of `git merge`. If there were conflicts, then
files within this tree may have embedded conflict markers.
-Conflicted file list
+Conflicted file info
~~~~~~~~~~~~~~~~~~~~
-This is a sequence of lines containing a filename on each line, quoted
-as explained for the configuration variable `core.quotePath` (see
-linkgit:git-config[1]).
+This is a sequence of lines with the format
+
+ <mode> <object> <stage> <filename>
+
+The filename will be quoted as explained for the configuration
+variable `core.quotePath` (see linkgit:git-config[1]). However, if
+the `--exclude-oids-and-modes` option is passed, the mode, object, and
+stage will be omitted.
Informational messages
~~~~~~~~~~~~~~~~~~~~~~
This always starts with a blank line to separate it from the previous
-section, and then has free-form messages about the merge, such as:
+sections, and then has free-form messages about the merge, such as:
* "Auto-merging <file>"
* "CONFLICT (rename/delete): <oldfile> renamed...but deleted in..."
@@ -110,6 +120,14 @@ plumbing commands since the possibility of merge conflicts give it a
much higher chance of the command not succeeding (and NEWTREE containing
a bunch of stuff other than just a toplevel tree).
+git-merge-tree was written to provide users with the same information
+that they'd have access to if using `git merge`:
+ * what would be written to the working tree (the <OID of toplevel tree>)
+ * the higher order stages that would be written to the index (the
+ <Conflicted file info>)
+ * any messages that would have been printed to stdout (the <Informational
+ messages>)
+
GIT
---
Part of the linkgit:git[1] suite
@@ -394,6 +394,7 @@ static int trivial_merge(const char *base,
struct merge_tree_options {
int mode;
int show_messages;
+ int exclude_modes_oids_stages;
};
static int real_merge(struct merge_tree_options *o,
@@ -450,7 +451,11 @@ static int real_merge(struct merge_tree_options *o,
merge_get_conflicted_files(&result, &conflicted_files);
for (i = 0; i < conflicted_files.nr; i++) {
const char *name = conflicted_files.items[i].string;
- if (last && !strcmp(last, name))
+ struct stage_info *c = conflicted_files.items[i].util;
+ if (!o->exclude_modes_oids_stages)
+ printf("%06o %s %d\t",
+ c->mode, oid_to_hex(&c->oid), c->stage);
+ else if (last && !strcmp(last, name))
continue;
write_name_quoted_relative(
name, prefix, stdout, line_termination);
@@ -485,6 +490,10 @@ int cmd_merge_tree(int argc, const char **argv, const char *prefix)
N_("do a trivial merge only"), 't'),
OPT_BOOL(0, "messages", &o.show_messages,
N_("also show informational/conflict messages")),
+ OPT_BOOL_F('l', "exclude-modes-oids-stages",
+ &o.exclude_modes_oids_stages,
+ N_("list conflicted files without modes/oids/stages"),
+ PARSE_OPT_NONEG),
OPT_END()
};
@@ -47,6 +47,7 @@ test_expect_success 'Content merge and a few conflicts' '
expected_tree=$(cat .git/AUTO_MERGE) &&
# We will redo the merge, while we are still in a conflicted state!
+ git ls-files -u >conflicted-file-info &&
test_when_finished "git reset --hard" &&
test_expect_code 1 git merge-tree --write-tree side1 side2 >RESULT &&
@@ -86,7 +87,7 @@ test_expect_success 'Barf on too many arguments' '
'
test_expect_success 'test conflict notices and such' '
- test_expect_code 1 git merge-tree --write-tree side1 side2 >out &&
+ test_expect_code 1 git merge-tree --write-tree --exclude-modes-oids-stages side1 side2 >out &&
sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual &&
# Expected results:
@@ -109,7 +110,7 @@ test_expect_success 'test conflict notices and such' '
'
test_expect_success 'Just the conflicted files without the messages' '
- test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out &&
+ test_expect_code 1 git merge-tree --write-tree --no-messages --exclude-modes-oids-stages side1 side2 >out &&
sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual &&
test_write_lines HASH greeting whatever~side1 >expect &&
@@ -117,4 +118,25 @@ test_expect_success 'Just the conflicted files without the messages' '
test_cmp expect actual
'
+test_expect_success 'Check conflicted oids and modes without messages' '
+ test_expect_code 1 git merge-tree --write-tree --no-messages side1 side2 >out &&
+ sed -e "s/[0-9a-f]\{40,\}/HASH/g" out >actual &&
+
+ # Compare the basic output format
+ q_to_tab >expect <<-\EOF &&
+ HASH
+ 100644 HASH 1Qgreeting
+ 100644 HASH 2Qgreeting
+ 100644 HASH 3Qgreeting
+ 100644 HASH 1Qwhatever~side1
+ 100644 HASH 2Qwhatever~side1
+ EOF
+
+ test_cmp expect actual &&
+
+ # Check the actual hashes against the `ls-files -u` output too
+ tail -n +2 out | sed -e s/side1/HEAD/ >actual &&
+ test_cmp conflicted-file-info actual
+'
+
test_done