Subject: Re: [PATCH 00/14] Add submodule test harness

From: Jens Lehmann <[email-masked]>
Date: Wed, 09 Jul 2014 20:19:31 +0200

Am 09.07.2014 08:14, schrieb Torsten Bögershausen:
> 
>>> There seems to be some other trouble under Mac OS, not yet fully tracked down,
>>> (may be related to the "diff -r")
>> Torsten sees failures of this kind under Mac OS:
>>
>> diff -r .git/modules/sub1/config sub1/.git/config
>> 6d5
>> <     worktree = ../../../sub1
>> 8a8
>>>      worktree = ../../../sub1
>> So the config contains the same content, but the worktree setting moved
>> to a different line. This seems to be the result of setting core.worktree
>> in the test_git_directory_is_unchanged function just before the "diff -r",
>> but only under Mac OS.
>>
> So I was suspecting diff -r beinng non-portable, but that doesn't seem to be the problem here.
> (But I wouldn't be surprised if there where problems with diff -r on some Unix systems)
> Anyway, checking all the files in the working tree seems to be a good thing to do,
> but that does not necessarily work for .git/config.

I agree, but this case is special. The test asserts that nobody
added, modified or removed *anything* inside the .git directory.
The reason for problem we are seeing here is that I have to
remove the core.worktree setting when moving the git directory
from .git/modules into the submodule work tree. So the test adds
it again to be able to diff it, and this happens in a different
line only on Mac OS as comparing the two core sections shows:

> ---------------------
> [core]
>         repositoryformatversion = 0
>         filemode = true
>         bare = false
>         logallrefupdates = true
>         worktree = ../../../sub1
>         ignorecase = true
>         precomposeunicode = true
> [remote "origin"]

vs.

> ----------------
> [core]
>         repositoryformatversion = 0
>         filemode = true
>         bare = false
>         logallrefupdates = true
>         ignorecase = true
>         precomposeunicode = true
>         worktree = ../../../sub1
> [remote "origin"]

And now it's clear what happens here: On Mac OS the ignorecase
and precomposeunicode settings are added behind the worktree
line, then re-adding worktree later for the comparison adds it
after these two.

Could you please test the following? It should avoid this kind
of problem by removing the core.worktree setting temporarily
from the original config in .git/modules instead of adding it
temporarily to .git/config:
-----------------------8<-----------------------
diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh
index 3584755..98c86e3 100755
--- a/t/lib-submodule-update.sh
+++ b/t/lib-submodule-update.sh
@@ -143,18 +143,18 @@ replace_gitfile_with_git_dir () {
 }

 # Test that the .git directory in the submodule is unchanged (except for the
-# core.worktree setting, which we temporarily restore). Call this function
+# core.worktree setting, which we temporarily remove). Call this function
 # before test_submodule_content as the latter might write the index file
 # leading to false positive index differences.
 test_git_directory_is_unchanged () {
 	(
-		cd "$1" &&
-		git config core.worktree "../../../$1"
+		cd ".git/modules/$1" &&
+		git config --unset core.worktree
 	) &&
 	diff -r ".git/modules/$1" "$1/.git" &&
 	(
-		cd "$1" &&
-		GIT_WORK_TREE=. git config --unset core.worktree
+		cd ".git/modules/$1" &&
+		git config core.worktree "../../../$1"
 	)
 }