Skip to contentSkip to conversation

Fix issue with format-patch and diff.submodule

PATCH Superseded Doug Kelly 3 participants 18 messages Jun 15, 2016

lore
Share & tools
lore

Doug Kelly

author
#0 lore raw

cover Fix issue with format-patch and diff.submodule

A colleague found an issue that when using diff.submodule=log in his .gitconfig, format-patch would use the log format for submodule changes, which would be ignored or error out when processed by git-am. format-patch now ignores the diff.submodule option and a testcase for this specific issue now exists.

Since this seems like a bug in current versions, I have based and tested this on the "maint" branch, but there's no reason it shouldn't apply cleanly to master as well.

Apologies for any rawness to the first round of this change. "Long time listener; first time caller." Any feedback is appreciated.

Doug Kelly (2):
t4255: test am submodule with diff.submodule
format-patch: ignore diff.submodule setting

 builtin/log.c           |  2 +-
 t/t4255-am-submodule.sh | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)
Signature · 1 line
2.0.5
author
#1 lore raw

PATCH 1/2 t4255: test am submodule with diff.submodule

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---
 t/t4255-am-submodule.sh | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
t/t4255-am-submodule.sh +83 -0
index 8bde7db..d9a1d79 100755
@@ -18,4 +18,87 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	echo one >one &&
+	git add one &&
+	test_tick &&
+	git commit -m initial &&
+	git rev-parse HEAD >initial &&
+
+	git init submodule &&
+	(cd submodule &&
+		echo two >two &&
+		git add two &&
+		test_tick &&
+		git commit -m "initial submodule" &&
+		git rev-parse HEAD >../initial-submodule) &&
+	git submodule add ./submodule &&
+	test_tick &&
+	git commit -m first &&
+	git rev-parse HEAD >first &&
+
+	(cd submodule &&
+		echo three >three &&
+		git add three &&
+		test_tick &&
+		git commit -m "first submodule" &&
+		git rev-parse HEAD >../first-submodule) &&
+	git add submodule &&
+	test_tick &&
+	git commit -m second &&
+	git rev-parse HEAD >second &&
+
+	(cd submodule &&
+		git mv two four &&
+		test_tick &&
+		git commit -m "second submodule" &&
+		git rev-parse HEAD >../second-submodule) &&
+	git add submodule &&
+	echo four >four &&
+	git add four &&
+	test_tick &&
+	git commit -m third &&
+	git rev-parse HEAD >third &&
+	git submodule update --init
+'
+
+INITIAL=$(cat initial)
+SECOND=$(cat second)
+THIRD=$(cat third)
+
+run_test() {
+	START_COMMIT=$1
+	EXPECT=$2
+	(git am --abort || true) &&
+	git reset --hard $START_COMMIT &&
+	rm -f *.patch &&
+	git format-patch -1 &&
+	git reset --hard $START_COMMIT^ &&
+	git submodule update &&
+	git am *.patch &&
+	git submodule update &&
+	(cd submodule && git rev-parse HEAD >../actual) &&
+	test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+	(git config --unset diff.submodule || true) &&
+	run_test $SECOND 'first-submodule'
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+	(git config --unset diff.submodule || true) &&
+	run_test $THIRD 'second-submodule'
+'
+
+test_expect_success 'diff.submodule=log' '
+	git config diff.submodule log &&
+	run_test $SECOND 'first-submodule'
+'
+
+test_expect_success 'diff.submodule=log with extra file' '
+	git config diff.submodule log &&
+	run_test $THIRD 'second-submodule'
+'
+
 test_done
Signature · 1 line
2.0.5
author
#7 lore raw

PATCH 2/2 format-patch: ignore diff.submodule setting

In reply to Doug Kelly

diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output.

---
 builtin/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/log.c +1 -1
index 734aab3..cb14db4 100644
@@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
-	    !strcmp(var, "color.ui")) {
+	    !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) {
 		return 0;
 	}
 	if (!strcmp(var, "format.numbered")) {
Signature · 1 line
2.0.5
#2 lore raw

Re: [PATCH 1/2] t4255: test am submodule with diff.submodule

In reply to Doug Kelly
Quoted 16 lines · Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---

t/t4255-am-submodule.sh +0 -0
index 8bde7db..d9a1d79 100755

t/t4255-am-submodule.sh am_3way () { · line 21

Quoted 4 lines
t/t4255-am-submodule.sh +1 -0
@@ -18,4 +18,87 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '

Since the tests are actually expected to fail at this point (before you've fixed the problem), use test_expect_failure. The follow-up patch, which fixes the problem, should flip them to test_expect_success.

t/t4255-am-submodule.sh am_3way () { · line 25

Quoted 4 lines
t/t4255-am-submodule.sh +4 -0
+       echo one >one &&
+       git add one &&
+       test_tick &&
+       git commit -m initial &&

Rather than performing these steps manually (here and below), perhaps test_commit would be suitable and more succinct.

t/t4255-am-submodule.sh am_3way () { · line 26

Quoted 1 line
t/t4255-am-submodule.sh +1 -0
+       git rev-parse HEAD >initial &&

Other scripts in the test suite don't bother with this indirection. Instead, they assign the variable here, then reference it in subsequent tests (and no need to redirect to a file).

    INITIAL=$(git rev-parse HEAD) &&

t/t4255-am-submodule.sh am_3way () { · line 34

Quoted 8 lines
t/t4255-am-submodule.sh +8 -0
+
+       git init submodule &&
+       (cd submodule &&
+               echo two >two &&
+               git add two &&
+               test_tick &&
+               git commit -m "initial submodule" &&
+               git rev-parse HEAD >../initial-submodule) &&

Style: Format the subshell like this:

    (
        ...commands...
    ) &&

t/t4255-am-submodule.sh am_3way () { · line 38

Quoted 4 lines
t/t4255-am-submodule.sh +4 -0
+       git submodule add ./submodule &&
+       test_tick &&
+       git commit -m first &&
+       git rev-parse HEAD >first &&

Is file 'first' ever used anywhere?

Quoted 18 lines
t/t4255-am-submodule.sh +18 -0
+       (cd submodule &&
+               echo three >three &&
+               git add three &&
+               test_tick &&
+               git commit -m "first submodule" &&
+               git rev-parse HEAD >../first-submodule) &&
+       git add submodule &&
+       test_tick &&
+       git commit -m second &&
+       git rev-parse HEAD >second &&
+
+       (cd submodule &&
+               git mv two four &&
+               test_tick &&
+               git commit -m "second submodule" &&
+               git rev-parse HEAD >../second-submodule) &&
+       git add submodule &&
+       echo four >four &&

t/t4255-am-submodule.sh am_3way () { · line 67

Quoted 10 lines
t/t4255-am-submodule.sh +10 -0
+       git add four &&
+       test_tick &&
+       git commit -m third &&
+       git rev-parse HEAD >third &&
+       git submodule update --init
+'
+
+INITIAL=$(cat initial)
+SECOND=$(cat second)
+THIRD=$(cat third)

No need for this extra level of indirection. See above.

t/t4255-am-submodule.sh am_3way () { · line 71

Quoted 3 lines
t/t4255-am-submodule.sh +3 -0
+run_test() {
+       START_COMMIT=$1
+       EXPECT=$2

Although it's not specifically wrong here, someone adding code above these two lines later on may not notice the broken &&-chain, so it would be a good idea to keep the &&-chain intact.

Quoted 5 lines
t/t4255-am-submodule.sh +5 -0
+       (git am --abort || true) &&
+       git reset --hard $START_COMMIT &&
+       rm -f *.patch &&
+       git format-patch -1 &&
+       git reset --hard $START_COMMIT^ &&

t/t4255-am-submodule.sh am_3way () { · line 86

Quoted 10 lines
t/t4255-am-submodule.sh +10 -0
+       git submodule update &&
+       git am *.patch &&
+       git submodule update &&
+       (cd submodule && git rev-parse HEAD >../actual) &&
+       test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+       (git config --unset diff.submodule || true) &&
+       run_test $SECOND 'first-submodule'

Note that you're already inside a single-quoted string here, so 'first-submodule' is not quite doing what you expect. Double quotes would be more appropriate. Or, better, drop the quoting of first-submodule altogether since it's unnecessary.

Quoted 20 lines
t/t4255-am-submodule.sh +17 -1
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+       (git config --unset diff.submodule || true) &&
+       run_test $THIRD 'second-submodule'
+'
+
+test_expect_success 'diff.submodule=log' '
+       git config diff.submodule log &&
+       run_test $SECOND 'first-submodule'
+'
+
+test_expect_success 'diff.submodule=log with extra file' '
+       git config diff.submodule log &&
+       run_test $THIRD 'second-submodule'
+'
+
 test_done
--

2.0.5

author
#3 lore raw

Re: [PATCH 1/2] t4255: test am submodule with diff.submodule

Quoted 21 lines · Eric Sunshine
Quoted 19 lines · Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---

t/t4255-am-submodule.sh +0 -0
index 8bde7db..d9a1d79 100755
@@ -18,4 +18,87 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
Quoted 6 lines

t/t4255-am-submodule.sh am_3way () { · line 21

Quoted 1 line
t/t4255-am-submodule.sh +1 -0
+test_expect_success 'setup diff.submodule' '

Since the tests are actually expected to fail at this point (before you've fixed the problem), use test_expect_failure. The follow-up patch, which fixes the problem, should flip them to test_expect_success.

Okay, that's easy enough to do.

Quoted 9 lines

t/t4255-am-submodule.sh am_3way () { · line 25

Quoted 5 lines
t/t4255-am-submodule.sh +4 -0
+       echo one >one &&
+       git add one &&
+       test_tick &&
+       git commit -m initial &&

Rather than performing these steps manually (here and below), perhaps test_commit would be suitable and more succinct.

Quoted 8 lines

t/t4255-am-submodule.sh am_3way () { · line 26

Quoted 1 line
t/t4255-am-submodule.sh +1 -0
+       git rev-parse HEAD >initial &&

Other scripts in the test suite don't bother with this indirection. Instead, they assign the variable here, then reference it in subsequent tests (and no need to redirect to a file).

    INITIAL=$(git rev-parse HEAD) &&

Both good comments; wasn't sure if that'd work. But easy to do!

Quoted 9 lines

t/t4255-am-submodule.sh am_3way () { · line 34

Quoted 8 lines
t/t4255-am-submodule.sh +8 -0
+
+       git init submodule &&
+       (cd submodule &&
+               echo two >two &&
+               git add two &&
+               test_tick &&
+               git commit -m "initial submodule" &&
+               git rev-parse HEAD >../initial-submodule) &&
Quoted 5 lines

Style: Format the subshell like this:

    (
        ...commands...
    ) &&

Yeah, I was unsure on this style (docs were unclear), but that's easy to follow.

Quoted 7 lines

t/t4255-am-submodule.sh am_3way () { · line 38

Quoted 5 lines
t/t4255-am-submodule.sh +4 -0
+       git submodule add ./submodule &&
+       test_tick &&
+       git commit -m first &&
+       git rev-parse HEAD >first &&

Is file 'first' ever used anywhere?

Nope; somewhat vestigial code (that could probably be cleaned out -- and should).
Originally, I was testing the first commit, and then I realized that the second commit
updating the submodule introduces the failure I was looking for.

Quoted 32 lines
Quoted 19 lines
t/t4255-am-submodule.sh +18 -0
+       (cd submodule &&
+               echo three >three &&
+               git add three &&
+               test_tick &&
+               git commit -m "first submodule" &&
+               git rev-parse HEAD >../first-submodule) &&
+       git add submodule &&
+       test_tick &&
+       git commit -m second &&
+       git rev-parse HEAD >second &&
+
+       (cd submodule &&
+               git mv two four &&
+               test_tick &&
+               git commit -m "second submodule" &&
+               git rev-parse HEAD >../second-submodule) &&
+       git add submodule &&
+       echo four >four &&

t/t4255-am-submodule.sh am_3way () { · line 67

Quoted 10 lines
t/t4255-am-submodule.sh +10 -0
+       git add four &&
+       test_tick &&
+       git commit -m third &&
+       git rev-parse HEAD >third &&
+       git submodule update --init
+'
+
+INITIAL=$(cat initial)
+SECOND=$(cat second)
+THIRD=$(cat third)

No need for this extra level of indirection. See above.

Quoted 7 lines

t/t4255-am-submodule.sh am_3way () { · line 71

Quoted 3 lines
t/t4255-am-submodule.sh +3 -0
+run_test() {
+       START_COMMIT=$1
+       EXPECT=$2

Although it's not specifically wrong here, someone adding code above these two lines later on may not notice the broken &&-chain, so it would be a good idea to keep the &&-chain intact.

OK, easy enough.

Quoted 13 lines
Quoted 13 lines
t/t4255-am-submodule.sh +12 -0
+       (git am --abort || true) &&
+       git reset --hard $START_COMMIT &&
+       rm -f *.patch &&
+       git format-patch -1 &&
+       git reset --hard $START_COMMIT^ &&
+       git submodule update &&
+       git am *.patch &&
+       git submodule update &&
+       (cd submodule && git rev-parse HEAD >../actual) &&
+       test_cmp $EXPECT actual
+}
+
Quoted 8 lines

t/t4255-am-submodule.sh am_3way () { · line 86

Quoted 3 lines
t/t4255-am-submodule.sh +3 -0
+test_expect_success 'diff.submodule unset' '
+       (git config --unset diff.submodule || true) &&
+       run_test $SECOND 'first-submodule'

Note that you're already inside a single-quoted string here, so 'first-submodule' is not quite doing what you expect. Double quotes would be more appropriate. Or, better, drop the quoting of first-submodule altogether since it's unnecessary.

Yep. Good note.

Quoted 13 lines
Quoted 13 lines
t/t4255-am-submodule.sh +12 -0
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+       (git config --unset diff.submodule || true) &&
+       run_test $THIRD 'second-submodule'
+'
+
+test_expect_success 'diff.submodule=log' '
+       git config diff.submodule log &&
+       run_test $SECOND 'first-submodule'
+'
+
Quoted 8 lines
Quoted 8 lines
t/t4255-am-submodule.sh +5 -1
+test_expect_success 'diff.submodule=log with extra file' '
+       git config diff.submodule log &&
+       run_test $THIRD 'second-submodule'
+'
+
 test_done
--

2.0.5

One other note that might simplify this extra test case that I thought about while driving home yesterday evening was changing lib-submodule-update to set diff.submodule=log inside prolog(). This wouldn't provide very clear failure causes, but it would perhaps reduce duplicated code and simplify the test case.

Thanks for the feedback, though, I'll send out a new version momentarily.

#4 lore raw

Re: [PATCH 1/2] t4255: test am submodule with diff.submodule

In reply to Eric Sunshine
Quoted 1 line · Eric Sunshine
Quoted 1 line

+ (git am --abort || true) &&

Why (x || y)? Is 'x' so unreliable that we do not know how should exit? Should this be "test_must_fail git am --abort"?

Quoted 1 line
Quoted 1 line

+ (cd submodule && git rev-parse HEAD >../actual) &&

"git -C submodule rev-parse HEAD >actual" perhaps?

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+test_expect_success 'diff.submodule unset' '
+       (git config --unset diff.submodule || true) &&

I think test_config and test_unconfig were invented for things like this (same for all the other use of "git config").

author
#8 lore raw

PATCH v2 1/2 t4255: test am submodule with diff.submodule

In reply to Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---
 t/t4255-am-submodule.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
t/t4255-am-submodule.sh +84 -0
index 8bde7db..a2dc083 100755
@@ -18,4 +18,88 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	echo one >one &&
+	git add one &&
+	test_tick &&
+	git commit -m initial &&
+	INITIAL=$(git rev-parse HEAD) &&
+
+	git init submodule &&
+	(
+		cd submodule &&
+		echo two >two &&
+		git add two &&
+		test_tick &&
+		git commit -m "initial submodule" &&
+		git rev-parse HEAD >../initial-submodule
+	) &&
+	git submodule add ./submodule &&
+	test_tick &&
+	git commit -m first &&
+
+	(
+		cd submodule &&
+		echo three >three &&
+		git add three &&
+		test_tick &&
+		git commit -m "first submodule" &&
+		git rev-parse HEAD >../first-submodule
+	) &&
+	git add submodule &&
+	test_tick &&
+	git commit -m second &&
+	SECOND=$(git rev-parse HEAD) &&
+
+	(
+		cd submodule &&
+		git mv two four &&
+		test_tick &&
+		git commit -m "second submodule" &&
+		git rev-parse HEAD >../second-submodule
+	) &&
+	git add submodule &&
+	echo four >four &&
+	git add four &&
+	test_tick &&
+	git commit -m third &&
+	THIRD=$(git rev-parse HEAD) &&
+	git submodule update --init
+'
+
+run_test() {
+	START_COMMIT=$1 &&
+	EXPECT=$2 &&
+	(git am --abort || true) &&
+	git reset --hard $START_COMMIT &&
+	rm -f *.patch &&
+	git format-patch -1 &&
+	git reset --hard $START_COMMIT^ &&
+	git submodule update &&
+	git am *.patch &&
+	git submodule update &&
+	(cd submodule && git rev-parse HEAD >../actual) &&
+	test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+	(git config --unset diff.submodule || true) &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+	(git config --unset diff.submodule || true) &&
+	run_test $THIRD second-submodule
+'
+
+test_expect_failure 'diff.submodule=log' '
+	git config diff.submodule log &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_failure 'diff.submodule=log with extra file' '
+	git config diff.submodule log &&
+	run_test $THIRD second-submodule
+'
+
 test_done
Signature · 1 line
2.0.5
author
#9 lore raw

PATCH v2 2/2 format-patch: ignore diff.submodule setting

diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output.

---
 builtin/log.c           | 2 +-
 t/t4255-am-submodule.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/log.c +1 -1
index 734aab3..cb14db4 100644
@@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
-	    !strcmp(var, "color.ui")) {
+	    !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) {
 		return 0;
 	}
 	if (!strcmp(var, "format.numbered")) {
t/t4255-am-submodule.sh +2 -2
index a2dc083..b7ec0f1 100755
@@ -92,12 +92,12 @@ test_expect_success 'diff.submodule unset with extra file' '
 	run_test $THIRD second-submodule
 '
 
-test_expect_failure 'diff.submodule=log' '
+test_expect_success 'diff.submodule=log' '
 	git config diff.submodule log &&
 	run_test $SECOND first-submodule
 '
 
-test_expect_failure 'diff.submodule=log with extra file' '
+test_expect_success 'diff.submodule=log with extra file' '
 	git config diff.submodule log &&
 	run_test $THIRD second-submodule
 '
Signature · 1 line
2.0.5
#10 lore raw

Re: [PATCH v2 1/2] t4255: test am submodule with diff.submodule

In reply to Doug Kelly
Quoted 11 lines · Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---

Here below the "---" line is a good place to explain what changed since the last version of the patch (or do so in the cover letter of the new patch series). It's also helpful to reviewers to provide a link to the previous round, like this[1].

[1]: http://thread.gmane.org/gmane.comp.version-control.git/261830

More below.

Quoted 8 lines
 t/t4255-am-submodule.sh | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
t/t4255-am-submodule.sh +0 -0
index 8bde7db..a2dc083 100755

t/t4255-am-submodule.sh am_3way () { · line 25

Quoted 8 lines
t/t4255-am-submodule.sh +5 -0
@@ -18,4 +18,88 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	echo one >one &&
+	git add one &&
+	test_tick &&
+	git commit -m initial &&

Perhaps squash in the following to improve succinctness?

-- >8 --

t/t4255-am-submodule.sh +6 -19
index b7ec0f1..b58e776 100755
@@ -19,50 +19,37 @@ KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
 test_expect_success 'setup diff.submodule' '
-	echo one >one &&
-	git add one &&
-	test_tick &&
-	git commit -m initial &&
+	test_commit one &&
 	INITIAL=$(git rev-parse HEAD) &&
 
 	git init submodule &&
 	(
 		cd submodule &&
-		echo two >two &&
-		git add two &&
-		test_tick &&
-		git commit -m "initial submodule" &&
+		test_commit two &&
 		git rev-parse HEAD >../initial-submodule
 	) &&
 	git submodule add ./submodule &&
-	test_tick &&
 	git commit -m first &&
 
 	(
 		cd submodule &&
-		echo three >three &&
-		git add three &&
-		test_tick &&
-		git commit -m "first submodule" &&
+		test_commit three &&
 		git rev-parse HEAD >../first-submodule
 	) &&
 	git add submodule &&
-	test_tick &&
 	git commit -m second &&
 	SECOND=$(git rev-parse HEAD) &&
 
 	(
 		cd submodule &&
-		git mv two four &&
+		git mv two.t four.t &&
 		test_tick &&
 		git commit -m "second submodule" &&
 		git rev-parse HEAD >../second-submodule
 	) &&
+	test_commit four &&
 	git add submodule &&
-	echo four >four &&
-	git add four &&
-	test_tick &&
-	git commit -m third &&
+	git commit --amend --no-edit &&
 	THIRD=$(git rev-parse HEAD) &&
 	git submodule update --init
 '
Signature · 1 line
2.2.1.302.gdfcd89f
author
#5 lore raw

Re: [PATCH 1/2] t4255: test am submodule with diff.submodule

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 1 line · Eric Sunshine
Quoted 1 line

+ (git am --abort || true) &&

Why (x || y)? Is 'x' so unreliable that we do not know how should exit? Should this be "test_must_fail git am --abort"?

Updated to test_might_fail -- we don't know if a merge is in progress or not. We still need to clean up, but disregard failure if a merge isn't in progress.

Quoted 4 lines
Quoted 1 line
Quoted 1 line

+ (cd submodule && git rev-parse HEAD >../actual) &&

"git -C submodule rev-parse HEAD >actual" perhaps?

Seems sane to me.

Quoted 5 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+test_expect_success 'diff.submodule unset' '
+       (git config --unset diff.submodule || true) &&

I think test_config and test_unconfig were invented for things like this (same for all the other use of "git config").

Yep, much nicer. :) Also updated to test_commit as suggested by Eric.

Thanks!

--Doug

#6 lore raw

Re: [PATCH 1/2] t4255: test am submodule with diff.submodule

Quoted 10 lines · Doug Kelly
Quoted 7 lines · Junio C Hamano
Quoted 1 line · Eric Sunshine
Quoted 1 line

+ (git am --abort || true) &&

Why (x || y)? Is 'x' so unreliable that we do not know how should exit? Should this be "test_must_fail git am --abort"?

Updated to test_might_fail -- we don't know if a merge is in progress or not. We still need to clean up, but disregard failure if a merge isn't in progress.

Ah, OK. But even with "test_might_fail", it may not be clear why it might fail, so it would be easier to maintain if we can read "we don't know if a merge is in progress" next to the "test_might_fail".

For now we can add a comment, but in the longer term it might not be a bad idea to change test_might_fail to require two args, one is a command to run and the other is a text that explains why the outcome is unknown.

Thanks for clarifying.

author
#11 lore raw

PATCH v3 1/2 t4255: test am submodule with diff.submodule

In reply to Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

Thanks-to: Eric Sunshine <[email protected]>
Thanks-to: Junio C Hamano <[email protected]>
---
Updated with Eric Sunshine's comments and changes to reduce complexity, and also changed to include Junio's suggestions for using test_config, test_unconfig, and test_might_fail (since we don't know if a previous am failed or not -- we always want to clean up first).

 t/t4255-am-submodule.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
t/t4255-am-submodule.sh +72 -0
index 8bde7db..523accf 100755
@@ -18,4 +18,76 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	test_commit one &&
+	INITIAL=$(git rev-parse HEAD) &&
+
+	git init submodule &&
+	(
+		cd submodule &&
+		test_commit two &&
+		git rev-parse HEAD >../initial-submodule
+	) &&
+	git submodule add ./submodule &&
+	git commit -m first &&
+
+	(
+		cd submodule &&
+		test_commit three &&
+		git rev-parse HEAD >../first-submodule
+	) &&
+	git add submodule &&
+	test_tick &&
+	git commit -m second &&
+	SECOND=$(git rev-parse HEAD) &&
+
+	(
+		cd submodule &&
+		git mv two.t four.t &&
+		test_tick &&
+		git commit -m "second submodule" &&
+		git rev-parse HEAD >../second-submodule
+	) &&
+	test_commit four &&
+	git add submodule &&
+	git commit --amend --no-edit &&
+	THIRD=$(git rev-parse HEAD) &&
+	git submodule update --init
+'
+
+run_test() {
+	START_COMMIT=$1 &&
+	EXPECT=$2 &&
+	test_might_fail git am --abort &&
+	git reset --hard $START_COMMIT &&
+	rm -f *.patch &&
+	git format-patch -1 &&
+	git reset --hard $START_COMMIT^ &&
+	git submodule update &&
+	git am *.patch &&
+	git submodule update &&
+	git -C submodule rev-parse HEAD >actual &&
+	test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+	test_unconfig diff.submodule &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+	test_unconfig diff.submodule &&
+	run_test $THIRD second-submodule
+'
+
+test_expect_failure 'diff.submodule=log' '
+	test_config diff.submodule log &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_failure 'diff.submodule=log with extra file' '
+	test_config diff.submodule log &&
+	run_test $THIRD second-submodule
+'
+
 test_done
Signature · 1 line
2.0.5
author
#12 lore raw

PATCH v3 2/2 format-patch: ignore diff.submodule setting

diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output.

---
 builtin/log.c           | 2 +-
 t/t4255-am-submodule.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/log.c +1 -1
index 734aab3..cb14db4 100644
@@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
-	    !strcmp(var, "color.ui")) {
+	    !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) {
 		return 0;
 	}
 	if (!strcmp(var, "format.numbered")) {
t/t4255-am-submodule.sh +2 -2
index 523accf..31cbdba 100755
@@ -80,12 +80,12 @@ test_expect_success 'diff.submodule unset with extra file' '
 	run_test $THIRD second-submodule
 '
 
-test_expect_failure 'diff.submodule=log' '
+test_expect_success 'diff.submodule=log' '
 	test_config diff.submodule log &&
 	run_test $SECOND first-submodule
 '
 
-test_expect_failure 'diff.submodule=log with extra file' '
+test_expect_success 'diff.submodule=log with extra file' '
 	test_config diff.submodule log &&
 	run_test $THIRD second-submodule
 '
Signature · 1 line
2.0.5
#13 lore raw

Re: [PATCH v3 1/2] t4255: test am submodule with diff.submodule

In reply to Doug Kelly
Quoted 4 lines · Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

Quoted 8 lines

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

Thanks-to: Eric Sunshine <[email protected]>
Thanks-to: Junio C Hamano <[email protected]>

On this project, it's customary to say "Helped-by:" rather than "Thanks-to:". Also, place your sign-off last.

Quoted 5 lines

---
Updated with Eric Sunshine's comments and changes to reduce complexity, and also changed to include Junio's suggestions for using test_config, test_unconfig, and test_might_fail (since we don't know if a previous am failed or not -- we always want to clean up first).

Looking much better. Thanks. A couple minor comments below...

Quoted 18 lines
t/t4255-am-submodule.sh +10 -0
index 8bde7db..523accf 100755
@@ -18,4 +18,76 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+       test_commit one &&
+       INITIAL=$(git rev-parse HEAD) &&
+
+       git init submodule &&
+       (
+               cd submodule &&
+               test_commit two &&
+               git rev-parse HEAD >../initial-submodule
+       ) &&

t/t4255-am-submodule.sh am_3way () { · line 40

Quoted 10 lines
t/t4255-am-submodule.sh +10 -0
+       git submodule add ./submodule &&
+       git commit -m first &&
+
+       (
+               cd submodule &&
+               test_commit three &&
+               git rev-parse HEAD >../first-submodule
+       ) &&
+       git add submodule &&
+       test_tick &&

You can drop this test_tick (as I did in my "squash"[1]).

t/t4255-am-submodule.sh am_3way () { · line 47

Quoted 7 lines
t/t4255-am-submodule.sh +7 -0
+       git commit -m second &&
+       SECOND=$(git rev-parse HEAD) &&
+
+       (
+               cd submodule &&
+               git mv two.t four.t &&
+               test_tick &&

And this one (which I overlooked in [1]).

The reason I suggest dropping the test_tick invocations is that they do not impact these tests at all, yet their presence misleads the reader into thinking that they are somehow significant.

t/t4255-am-submodule.sh am_3way () { · line 56

Quoted 9 lines
t/t4255-am-submodule.sh +9 -0
+               git commit -m "second submodule" &&
+               git rev-parse HEAD >../second-submodule
+       ) &&
+       test_commit four &&
+       git add submodule &&
+       git commit --amend --no-edit &&
+       THIRD=$(git rev-parse HEAD) &&
+       git submodule update --init
+'

[1]: http://article.gmane.org/gmane.comp.version-control.git/261852

author
#14 lore raw

PATCH v4 1/2 t4255: test am submodule with diff.submodule

In reply to Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---
Updated to remove test_ticks and clean the commit message.

 t/t4255-am-submodule.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)
t/t4255-am-submodule.sh +70 -0
index 8bde7db..a38c305 100755
@@ -18,4 +18,74 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	test_commit one &&
+	INITIAL=$(git rev-parse HEAD) &&
+
+	git init submodule &&
+	(
+		cd submodule &&
+		test_commit two &&
+		git rev-parse HEAD >../initial-submodule
+	) &&
+	git submodule add ./submodule &&
+	git commit -m first &&
+
+	(
+		cd submodule &&
+		test_commit three &&
+		git rev-parse HEAD >../first-submodule
+	) &&
+	git add submodule &&
+	git commit -m second &&
+	SECOND=$(git rev-parse HEAD) &&
+
+	(
+		cd submodule &&
+		git mv two.t four.t &&
+		git commit -m "second submodule" &&
+		git rev-parse HEAD >../second-submodule
+	) &&
+	test_commit four &&
+	git add submodule &&
+	git commit --amend --no-edit &&
+	THIRD=$(git rev-parse HEAD) &&
+	git submodule update --init
+'
+
+run_test() {
+	START_COMMIT=$1 &&
+	EXPECT=$2 &&
+	test_might_fail git am --abort &&
+	git reset --hard $START_COMMIT &&
+	rm -f *.patch &&
+	git format-patch -1 &&
+	git reset --hard $START_COMMIT^ &&
+	git submodule update &&
+	git am *.patch &&
+	git submodule update &&
+	git -C submodule rev-parse HEAD >actual &&
+	test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+	test_unconfig diff.submodule &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+	test_unconfig diff.submodule &&
+	run_test $THIRD second-submodule
+'
+
+test_expect_failure 'diff.submodule=log' '
+	test_config diff.submodule log &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_failure 'diff.submodule=log with extra file' '
+	test_config diff.submodule log &&
+	run_test $THIRD second-submodule
+'
+
 test_done
Signature · 1 line
2.0.5
author
#15 lore raw

PATCH v4 2/2 format-patch: ignore diff.submodule setting

diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output.

---
 builtin/log.c           | 2 +-
 t/t4255-am-submodule.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/log.c +1 -1
index 734aab3..cb14db4 100644
@@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
-	    !strcmp(var, "color.ui")) {
+	    !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) {
 		return 0;
 	}
 	if (!strcmp(var, "format.numbered")) {
t/t4255-am-submodule.sh +2 -2
index a38c305..27ea698 100755
@@ -78,12 +78,12 @@ test_expect_success 'diff.submodule unset with extra file' '
 	run_test $THIRD second-submodule
 '
 
-test_expect_failure 'diff.submodule=log' '
+test_expect_success 'diff.submodule=log' '
 	test_config diff.submodule log &&
 	run_test $SECOND first-submodule
 '
 
-test_expect_failure 'diff.submodule=log with extra file' '
+test_expect_success 'diff.submodule=log with extra file' '
 	test_config diff.submodule log &&
 	run_test $THIRD second-submodule
 '
Signature · 1 line
2.0.5
author
#16 lore raw

PATCH v5 1/2 t4255: test am submodule with diff.submodule

In reply to Doug Kelly

git am will break when using diff.submodule=log; add some test cases to illustrate this breakage as simply as possible. There are currently two ways this can fail:

* With errors ("unrecognized input"), if only change
* Silently (no submodule change), if other files change

Test for both conditions and ensure without diff.submodule this works.

---
Added a comment for why test_might_fail is used to abort merges in progress.

 t/t4255-am-submodule.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
t/t4255-am-submodule.sh +72 -0
index 8bde7db..450d261 100755
@@ -18,4 +18,76 @@ am_3way () {
 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
 test_submodule_switch "am_3way"
 
+test_expect_success 'setup diff.submodule' '
+	test_commit one &&
+	INITIAL=$(git rev-parse HEAD) &&
+
+	git init submodule &&
+	(
+		cd submodule &&
+		test_commit two &&
+		git rev-parse HEAD >../initial-submodule
+	) &&
+	git submodule add ./submodule &&
+	git commit -m first &&
+
+	(
+		cd submodule &&
+		test_commit three &&
+		git rev-parse HEAD >../first-submodule
+	) &&
+	git add submodule &&
+	git commit -m second &&
+	SECOND=$(git rev-parse HEAD) &&
+
+	(
+		cd submodule &&
+		git mv two.t four.t &&
+		git commit -m "second submodule" &&
+		git rev-parse HEAD >../second-submodule
+	) &&
+	test_commit four &&
+	git add submodule &&
+	git commit --amend --no-edit &&
+	THIRD=$(git rev-parse HEAD) &&
+	git submodule update --init
+'
+
+run_test() {
+	START_COMMIT=$1 &&
+	EXPECT=$2 &&
+	# Abort any merges in progress: the previous
+	# test may have failed, and we should clean up.
+	test_might_fail git am --abort &&
+	git reset --hard $START_COMMIT &&
+	rm -f *.patch &&
+	git format-patch -1 &&
+	git reset --hard $START_COMMIT^ &&
+	git submodule update &&
+	git am *.patch &&
+	git submodule update &&
+	git -C submodule rev-parse HEAD >actual &&
+	test_cmp $EXPECT actual
+}
+
+test_expect_success 'diff.submodule unset' '
+	test_unconfig diff.submodule &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_success 'diff.submodule unset with extra file' '
+	test_unconfig diff.submodule &&
+	run_test $THIRD second-submodule
+'
+
+test_expect_failure 'diff.submodule=log' '
+	test_config diff.submodule log &&
+	run_test $SECOND first-submodule
+'
+
+test_expect_failure 'diff.submodule=log with extra file' '
+	test_config diff.submodule log &&
+	run_test $THIRD second-submodule
+'
+
 test_done
Signature · 1 line
2.0.5
author
#17 lore raw

PATCH v5 2/2 format-patch: ignore diff.submodule setting

diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output.

---
 builtin/log.c           | 2 +-
 t/t4255-am-submodule.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/log.c +1 -1
index 734aab3..cb14db4 100644
@@ -705,7 +705,7 @@ static int git_format_config(const char *var, const char *value, void *cb)
 		return 0;
 	}
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") ||
-	    !strcmp(var, "color.ui")) {
+	    !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) {
 		return 0;
 	}
 	if (!strcmp(var, "format.numbered")) {
t/t4255-am-submodule.sh +2 -2
index 450d261..0ba8194 100755
@@ -80,12 +80,12 @@ test_expect_success 'diff.submodule unset with extra file' '
 	run_test $THIRD second-submodule
 '
 
-test_expect_failure 'diff.submodule=log' '
+test_expect_success 'diff.submodule=log' '
 	test_config diff.submodule log &&
 	run_test $SECOND first-submodule
 '
 
-test_expect_failure 'diff.submodule=log with extra file' '
+test_expect_success 'diff.submodule=log with extra file' '
 	test_config diff.submodule log &&
 	run_test $THIRD second-submodule
 '
Signature · 1 line
2.0.5