threads / rfc / 39493

RFC v2, 2 partst4150-am: refactor am -3 tests

Subject: [PATCH/RFC v2 1/2] t4150-am: refactor am -3 tests

## tl;dr

8 messages between Jun 2, 2015 and Jun 2, 2015. Diffs are folded; open one to read it.

replies: 7people: 5as markdown or json

Remi Lespinet· Jun 2, 2015, 13:24 UTC · lore

Create a setup for git am -3 in a separate test instead of creating this setup each time.

This prepares for the next commit which will use this setup as well.
Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
I removed the function creating temporary branch for now, because this
would have cost too much time reviewing. I've just done a refactoring
to simplify changes introduced in the next commit.
 t/t4150-am.sh | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)
Show changes to t/t4150-am.sh +14 −18
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 306e6f3..6ced98c 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -274,15 +274,21 @@ test_expect_success 'am --keep-non-patch really keeps the non-patch part' '
 	grep "^\[foo\] third" actual
 '
 
+test_expect_success 'setup am -3' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout -b base3way master2 &&
+	sed -n -e "3,\$p" msg >file &&
+	head -n 9 msg >>file &&
+	git add file &&
+	test_tick &&
+	git commit -m "copied stuff"
+'
+
 test_expect_success 'am -3 falls back to 3-way merge' '
 	rm -fr .git/rebase-apply &&
 	git reset --hard &&
-	git checkout -b lorem2 master2 &&
-	sed -n -e "3,\$p" msg >file &&
-	head -n 9 msg >>file &&
-	git add file &&
-	test_tick &&
-	git commit -m "copied stuff" &&
+	git checkout -b lorem2 base3way &&
 	git am -3 lorem-move.patch &&
 	test_path_is_missing .git/rebase-apply &&
 	git diff --exit-code lorem
@@ -291,12 +297,7 @@ test_expect_success 'am -3 falls back to 3-way merge' '
 test_expect_success 'am -3 -p0 can read --no-prefix patch' '
 	rm -fr .git/rebase-apply &&
 	git reset --hard &&
-	git checkout -b lorem3 master2 &&
-	sed -n -e "3,\$p" msg >file &&
-	head -n 9 msg >>file &&
-	git add file &&
-	test_tick &&
-	git commit -m "copied stuff" &&
+	git checkout -b lorem3 base3way &&
 	git am -3 -p0 lorem-zero.patch &&
 	test_path_is_missing .git/rebase-apply &&
 	git diff --exit-code lorem
@@ -338,12 +339,7 @@ test_expect_success 'am -3 can rename a file after falling back to 3-way merge'
 test_expect_success 'am -3 -q is quiet' '
 	rm -fr .git/rebase-apply &&
 	git checkout -f lorem2 &&
-	git reset master2 --hard &&
-	sed -n -e "3,\$p" msg >file &&
-	head -n 9 msg >>file &&
-	git add file &&
-	test_tick &&
-	git commit -m "copied stuff" &&
+	git reset base3way --hard &&
 	git am -3 -q lorem-move.patch >output.out 2>&1 &&
 	! test -s output.out
 '
-- 
1.9.1
Remi Lespinet· Jun 2, 2015, 13:24 UTC · re: Remi Lespinet · lore

[PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

Add the am.threeWay configuration variable to use the -3 or --3way option of git am by default. When am.threeway is set and not desired for a specific git am command, the --no-3way option can be used to override it.

Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
---
 Documentation/config.txt |  7 +++++++
 Documentation/git-am.txt |  6 ++++--
 git-am.sh                |  7 +++++++
 t/t4150-am.sh            | 19 +++++++++++++++++++
 4 files changed, 37 insertions(+), 2 deletions(-)
Show changes to 4 files +37 −1

Documentation/config.txt, Documentation/git-am.txt, git-am.sh, t/t4150-am.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index d44bc85..8e42752 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -769,6 +769,13 @@ am.keepcr::
 	by giving '--no-keep-cr' from the command line.
 	See linkgit:git-am[1], linkgit:git-mailsplit[1].
 
+am.threeWay::
+	If true, git-am will fall back on 3-way merge when the patch
+	cannot be applied cleanly, in the same way as the '-3' or
+	'--3-way' option. Can be overridden by giving '--no-3-way'
+	from the command line.
+	See linkgit:git-am[1].
+
 apply.ignoreWhitespace::
 	When set to 'change', tells 'git apply' to ignore changes in
 	whitespace, in the same way as the '--ignore-space-change'
diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt
index 0d8ba48..3190c05 100644
--- a/Documentation/git-am.txt
+++ b/Documentation/git-am.txt
@@ -89,11 +89,13 @@ default.   You can use `--no-utf8` to override this.
 	linkgit:git-mailinfo[1]).
 
 -3::
---3way::
+--[no-]3way::
 	When the patch does not apply cleanly, fall back on
 	3-way merge if the patch records the identity of blobs
 	it is supposed to apply to and we have those blobs
-	available locally.
+	available locally.  `am.threeWay` configuration variable
+	can be used to specify the default behaviour.  `--no-3way`
+	is useful to override `am.threeWay`.
 
 --ignore-space-change::
 --ignore-whitespace::
diff --git a/git-am.sh b/git-am.sh
index 761befb..781507c 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -389,6 +389,11 @@ then
     keepcr=t
 fi
 
+if test "$(git config --bool --get am.threeWay)" = true
+then
+    threeway=t
+fi
+
 while test $# != 0
 do
 	case "$1" in
@@ -400,6 +405,8 @@ it will be removed. Please do not use it anymore."
 		;;
 	-3|--3way)
 		threeway=t ;;
+	--no-3way)
+		threeway=f ;;
 	-s|--signoff)
 		sign=t ;;
 	-u|--utf8)
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 6ced98c..b822a39 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -303,6 +303,25 @@ test_expect_success 'am -3 -p0 can read --no-prefix patch' '
 	git diff --exit-code lorem
 '
 
+test_expect_success 'am with config am.threeWay falls back to 3-way merge' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout -b lorem4 base3way &&
+	test_config am.threeWay 1 &&
+	git am lorem-move.patch &&
+	test_path_is_missing .git/rebase-apply &&
+	git diff --exit-code lorem
+'
+
+test_expect_success 'am with config am.threeWay overridden by --no-3way' '
+	rm -fr .git/rebase-apply &&
+	git reset --hard &&
+	git checkout -b lorem5 base3way &&
+	test_config am.threeWay 1 &&
+	test_must_fail git am --no-3way lorem-move.patch &&
+	test_path_is_dir .git/rebase-apply
+'
+
 test_expect_success 'am can rename a file' '
 	grep "^rename from" rename.patch &&
 	rm -fr .git/rebase-apply &&
-- 
1.9.1
Matthieu Moy· Jun 2, 2015, 13:37 UTC · re: Remi Lespinet · lore

Re: [PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:
> +if test "$(git config --bool --get am.threeWay)" = true
> +then
> +    threeway=t
> +fi
I think you missed Paul's remark on this:
http://article.gmane.org/gmane.comp.version-control.git/270150
Not terribly important since am will be rewritten soon, though.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Remi LESPINET· Jun 2, 2015, 13:52 UTC · re: Matthieu Moy · lore

[PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 12 quoted lines
> Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:
>
> > +if test "$(git config --bool --get am.threeWay)" = true
> > +then
> > +    threeway=t
> > +fi
>
> I think you missed Paul's remark on this:
>
> http://article.gmane.org/gmane.comp.version-control.git/270150
>
> Not terribly important since am will be rewritten soon, though.
Oh right, sorry about that, I modify it and I resend the patch asap
Eric Sunshine· Jun 2, 2015, 14:01 UTC · re: Remi LESPINET · lore

Re: [PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

On Tue, Jun 2, 2015 at 9:52 AM, Remi LESPINET <remi.lespinet@ensimag.grenoble-inp.fr> wrote:

Show 16 quoted lines
> Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
>
>> Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:
>>
>> > +if test "$(git config --bool --get am.threeWay)" = true
>> > +then
>> > +    threeway=t
>> > +fi
>>
>> I think you missed Paul's remark on this:
>>
>> http://article.gmane.org/gmane.comp.version-control.git/270150
>>
>> Not terribly important since am will be rewritten soon, though.
>
> Oh right, sorry about that, I modify it and I resend the patch asap

In fact, it looks like all of Paul's remarks were missed. (The bit at the bottom of his review is also important.)

Paul Tan· Jun 2, 2015, 14:37 UTC · re: Matthieu Moy · lore

Re: [PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

Hi,

On Tue, Jun 2, 2015 at 9:37 PM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 12 quoted lines
> Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:
>
>> +if test "$(git config --bool --get am.threeWay)" = true
>> +then
>> +    threeway=t
>> +fi
>
> I think you missed Paul's remark on this:
>
> http://article.gmane.org/gmane.comp.version-control.git/270150
>
> Not terribly important since am will be rewritten soon, though.

As the person who had to do four preparatory patch series' to fix bugs for the rewrite of git-pull, I respectfully disagree ;-)

Regards, Paul

Mikael Magnusson· Jun 2, 2015, 13:58 UTC · re: Remi Lespinet · lore

Re: [PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

On Tue, Jun 2, 2015 at 3:24 PM, Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> wrote:

Show 28 quoted lines
> Add the am.threeWay configuration variable to use the -3 or --3way
> option of git am by default. When am.threeway is set and not desired
> for a specific git am command, the --no-3way option can be used to
> override it.
>
> Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
> ---
>  Documentation/config.txt |  7 +++++++
>  Documentation/git-am.txt |  6 ++++--
>  git-am.sh                |  7 +++++++
>  t/t4150-am.sh            | 19 +++++++++++++++++++
>  4 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index d44bc85..8e42752 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -769,6 +769,13 @@ am.keepcr::
>         by giving '--no-keep-cr' from the command line.
>         See linkgit:git-am[1], linkgit:git-mailsplit[1].
>
> +am.threeWay::
> +       If true, git-am will fall back on 3-way merge when the patch
> +       cannot be applied cleanly, in the same way as the '-3' or
> +       '--3-way' option. Can be overridden by giving '--no-3-way'
> +       from the command line.
> +       See linkgit:git-am[1].
> +
This part spells it 3-way while everywhere else appears to be 3way.
-- 
Mikael Magnusson
Matthieu Moy· Jun 2, 2015, 14:13 UTC · re: Remi Lespinet · lore

Re: [PATCH/RFC v2 2/2] git-am: add am.threeWay config variable

Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr> writes:
Show 23 quoted lines
> Add the am.threeWay configuration variable to use the -3 or --3way
> option of git am by default. When am.threeway is set and not desired
> for a specific git am command, the --no-3way option can be used to
> override it.
>
> Signed-off-by: Remi Lespinet <remi.lespinet@ensimag.grenoble-inp.fr>
> ---
>  Documentation/config.txt |  7 +++++++
>  Documentation/git-am.txt |  6 ++++--
>  git-am.sh                |  7 +++++++
>  t/t4150-am.sh            | 19 +++++++++++++++++++
>  4 files changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index d44bc85..8e42752 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -769,6 +769,13 @@ am.keepcr::
>  	by giving '--no-keep-cr' from the command line.
>  	See linkgit:git-am[1], linkgit:git-mailsplit[1].
>  
> +am.threeWay::
> +	If true, git-am will fall back on 3-way merge when the patch

git-am should be spelled `git am` or 'git am' (the second is used a lot in git-am.txt, but Documentation/CodingGuidelines says:

 Literal examples (e.g. use of command-line options, command names, and
 configuration variables) are typeset in monospace, and if you can use
 `backticks around word phrases`, do so.
   `--pretty=oneline`
   `git rev-list`
   `remote.pushDefault`
) so I guess the first is the right way to typeset it.
FYI, the syntax git-am actually existed in the past (before git 1.6).
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads