# [PATCH v4 4/4] mergetool: honor -O<orderfile>

5 messages from 2016-10-08 to 2016-10-11. Participants: David Aguilar, Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/44249

## David Aguilar, 2016-10-08 00:01

Subject: [PATCH v4 4/4] mergetool: honor -O<orderfile>
Message-ID: <20161008000130.22858-1-davvid@gmail.com>
URL: https://gitlist.dev/e/20161008000130.22858-1-davvid%40gmail.com

```
Teach mergetool to pass "-O<orderfile>" down to `git diff` when
specified on the command-line.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Since v3:

I missed one last piped invocation of "git mergetool" in the tests,
which has been fixed.

 Documentation/git-mergetool.txt | 10 ++++++----
 git-mergetool.sh                |  9 +++++++--
 t/t7610-mergetool.sh            | 27 +++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt
index c4c1a9b..3622d66 100644
--- a/Documentation/git-mergetool.txt
+++ b/Documentation/git-mergetool.txt
@@ -79,10 +79,12 @@ success of the resolution after the custom tool has exited.
 	Prompt before each invocation of the merge resolution program
 	to give the user a chance to skip the path.
 
-DIFF ORDER FILES
-----------------
-`git mergetool` honors the `diff.orderFile` configuration variable
-used by `git diff`.  See linkgit:git-config[1] for more details.
+-O<orderfile>::
+	Process files in the order specified in the
+	<orderfile>, which has one shell glob pattern per line.
+	This overrides the `diff.orderFile` configuration variable
+	(see linkgit:git-config[1]).  To cancel `diff.orderFile`,
+	use `-O/dev/null`.
 
 TEMPORARY FILES
 ---------------
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 65696d8..e52b4e4 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -9,7 +9,7 @@
 # at the discretion of Junio C Hamano.
 #
 
-USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...'
+USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<orderfile>] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
 NONGIT_OK=Yes
 OPTIONS_SPEC=
@@ -390,6 +390,7 @@ print_noop_and_exit () {
 main () {
 	prompt=$(git config --bool mergetool.prompt)
 	guessed_merge_tool=false
+	orderfile=
 
 	while test $# != 0
 	do
@@ -419,6 +420,9 @@ main () {
 		--prompt)
 			prompt=true
 			;;
+		-O*)
+			orderfile="$1"
+			;;
 		--)
 			shift
 			break
@@ -460,7 +464,8 @@ main () {
 	fi
 
 	files=$(git -c core.quotePath=false \
-		diff --name-only --diff-filter=U -- "$@")
+		diff --name-only --diff-filter=U \
+		${orderfile:+"$orderfile"} -- "$@")
 
 	cd_to_toplevel
 
diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index 38c1e4d..6d9f215 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -638,5 +638,32 @@ test_expect_success 'diff.orderFile configuration is honored' '
 	test_cmp expect actual &&
 	git reset --hard >/dev/null
 '
+test_expect_success 'mergetool -Oorder-file is honored' '
+	test_config diff.orderFile order-file &&
+	test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" &&
+	test_config mergetool.myecho.trustExitCode true &&
+	test_must_fail git merge order-file-side1 &&
+	cat >expect <<-\EOF &&
+		Merging:
+		a
+		b
+	EOF
+	git mergetool -O/dev/null --no-prompt --tool myecho >output &&
+	git grep --no-index -h -A2 Merging: output >actual &&
+	test_cmp expect actual &&
+	git reset --hard >/dev/null 2>&1 &&
+
+	git config --unset diff.orderFile &&
+	test_must_fail git merge order-file-side1 &&
+	cat >expect <<-\EOF &&
+		Merging:
+		b
+		a
+	EOF
+	git mergetool -Oorder-file --no-prompt --tool myecho >output &&
+	git grep --no-index -h -A2 Merging: output >actual &&
+	test_cmp expect actual &&
+	git reset --hard >/dev/null 2>&1
+'
 
 test_done
-- 
2.10.1.386.g8ee99a0


```

## Johannes Sixt, 2016-10-08 07:46

Subject: Re: [PATCH v4 4/4] mergetool: honor -O<orderfile>
Message-ID: <a0725074-b82e-06dd-13b8-7730cbebe50c@kdbg.org>
URL: https://gitlist.dev/e/a0725074-b82e-06dd-13b8-7730cbebe50c%40kdbg.org
In-Reply-To: <20161008000130.22858-1-davvid@gmail.com>

```
With this final fixup, the series looks good to me, and I have no 
further comments.

Reviewed-by: Johannes Sixt <j6t@kdbg.org>

-- Hannes


```

## Junio C Hamano, 2016-10-10 18:28

Subject: Re: [PATCH v4 4/4] mergetool: honor -O<orderfile>
Message-ID: <xmqqa8ecf48c.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqa8ecf48c.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20161008000130.22858-1-davvid@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

> Teach mergetool to pass "-O<orderfile>" down to `git diff` when
> specified on the command-line.
>
> Helped-by: Johannes Sixt <j6t@kdbg.org>
> Signed-off-by: David Aguilar <davvid@gmail.com>
> ---
> Since v3:
>
> I missed one last piped invocation of "git mergetool" in the tests,
> which has been fixed.

I only see 4/4 in v4; am I correct to assume that 1-3/4 of v4 are
the same as their counterparts in v3?

```

## David Aguilar, 2016-10-11 05:06

Subject: Re: [PATCH v4 4/4] mergetool: honor -O<orderfile>
Message-ID: <20161011050623.GA14278@gmail.com>
URL: https://gitlist.dev/e/20161011050623.GA14278%40gmail.com
In-Reply-To: <xmqqa8ecf48c.fsf@gitster.mtv.corp.google.com>

```
On Mon, Oct 10, 2016 at 11:28:35AM -0700, Junio C Hamano wrote:
> David Aguilar <davvid@gmail.com> writes:
> 
> > Teach mergetool to pass "-O<orderfile>" down to `git diff` when
> > specified on the command-line.
> >
> > Helped-by: Johannes Sixt <j6t@kdbg.org>
> > Signed-off-by: David Aguilar <davvid@gmail.com>
> > ---
> > Since v3:
> >
> > I missed one last piped invocation of "git mergetool" in the tests,
> > which has been fixed.
> 
> I only see 4/4 in v4; am I correct to assume that 1-3/4 of v4 are
> the same as their counterparts in v3?

Yes, 1-3 are unchanged since v3.
Thanks for checking,
-- 
David

```

## Junio C Hamano, 2016-10-11 17:05

Subject: Re: [PATCH v4 4/4] mergetool: honor -O<orderfile>
Message-ID: <xmqqr37makak.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqr37makak.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <20161011050623.GA14278@gmail.com>

```
David Aguilar <davvid@gmail.com> writes:

>> I only see 4/4 in v4; am I correct to assume that 1-3/4 of v4 are
>> the same as their counterparts in v3?
>
> Yes, 1-3 are unchanged since v3.
> Thanks for checking,

I'll queue these four with Reviewed-by's from j6t.

Thanks, both.

```
