git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] apply: support case-only renames in case-insensitive filesystems

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 12, 2022, 23:30 UTC
Message-ID
<xmqqr13t8np7.fsf@gitster.g>
In-Reply-To
<pull.1257.git.1654967038802.gitgitgadget@gmail.com>
"Tao Klerks via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> +if ! test_have_prereq CASE_INSENSITIVE_FS
> +then
> +	test_set_prereq CASE_SENSITIVE_FS
> +	echo nuts
> +fi

You can easily say !CASE_INSENSITIVE_FS as the prerequiste, so I do not see the point of this. I do not see the point of "nuts", either.

But it probably is a moot point as I do not think you should do the prerequisite at all.

Instead, you can explicitly set the core.ignorecase configuration, i.e. "git -c core.ignorecase=yes/no", and possibly "apply --cached" so that you do not have to worry about the case sensitivity of the filesystem at all.

> +test_expect_success setup '
> +	echo "This is some content in the file." > file1 &&
Style.  Redirection operator ">" sticks to its operand, i.e.
	echo "This is some content in the file." >file1 &&
Show 9 quoted lines
> +	echo "A completely different file." > file2 &&
> +	git update-index --add file1 &&
> +	git update-index --add file2 &&
> +	cat >case_only_rename_patch <<-\EOF
> +	diff --git a/file1 b/File1
> +	similarity index 100%
> +	rename from file1
> +	rename to File1
> +	EOF

You are better off not writing the diff output manually. Instead, you can let the test write it for you, e.g.

	echo "This is some content in the file." >file1 &&
	git update-index --add file1 &&
        file1blob=$(git rev-parse :file1) &&
	git commit -m "Initial - file1" &&
	git update-index --add --cacheinfo 100644,$file1blob,File1 &&
	git rm --cached file1 &&
	git diff --cached -M HEAD >case-only-rename-patch

If you want to be extra careful not to rely on your filesystem corrupting the pathnames you feed (e.g. the redireciton to "file1" might create file FILE1 on MS-DOS ;-), you could even do:

	file1blob=$(echo "This is some content in the file." |
		    git hash-object -w --stdin) &&
	file2blob=$(echo "A completeloy different contents." |
		    git hash-object -w --stdin) &&
	git update-index --add --cacheinfo 100644,$file1blob,file1 &&
	git commit -m "Initial - file1" &&
	git update-index --add --cacheinfo 100644,$file1blob,File1 &&
	git rm --cached file1 &&
	git diff --cached -M HEAD >rename-file1-to-File2 &&
	git reset --hard HEAD &&
        git update-index --add --cacheinfo 100644,$file1blob,file2 &&
	git rm --cached file1 &&
	git diff --cached -M HEAD >rename-file1-to-file2 &&
	# from here on, HEAD has file1 and file2
	git reset --hard HEAD &&
	git update-index --add --cacheinfo 100644,$file2blob,file2 &&
	git commit -m 'file1 and file2'
Show 10 quoted lines
> +'
> +
> +test_expect_success 'refuse to apply rename patch with conflict' '
> +	cat >conflict_patch <<-\EOF &&
> +	diff --git a/file1 b/file2
> +	similarity index 100%
> +	rename from file1
> +	rename to file2
> +	EOF
> +	test_must_fail git apply --index conflict_patch

And then, you could use --cached (not --index) to bypass the working tree altogether, which is a good way to test the feature without getting affected by the underlying filesystem. Check both case sensitive and case insensitive cases:

	# Start from a known state
	git reset --hard HEAD &&
	test_must_fail git -c core.ignorecase=no apply --cached rename-file1-to-file2 &&
	# Start from a known state
	git reset --hard HEAD &&
	test_must_fail git -c core.ignorecase=yes apply --cached rename-file1-to-file2 &&
> +'
> +
> +test_expect_success CASE_SENSITIVE_FS 'refuse to apply case-only rename patch with conflict, in case-sensitive FS' '

Lose the prerequisite, replace --index with --cached, and force core.ignorecase to both case insensitive and sensitive to check the behaviour.

Show 6 quoted lines
> +	test_when_finished "git mv File1 file2" &&
> +	git mv file2 File1 &&
> +	test_must_fail git apply --index case_only_rename_patch
> +'
> +
> +test_expect_success 'apply case-only rename patch without conflict' '
Likewise, try both sensitive and insensitive one.
Show 6 quoted lines
> +	git apply --index case_only_rename_patch
> +'
> +
> +test_done
>
> base-commit: 1e59178e3f65880188caedb965e70db5ceeb2d64
Thanks.
Previous: Tao KlerksNext: Junio C Hamano
Message 9 of 21 in “apply: support case-only renames in case-insensitive filesystems”
  1. apply: support case-only renames in case-insensitive filesystemsTao Klerks via GitGitGadget, Jun 11, 2022
  2. Junio C HamanoJun 11, 2022
  3. Junio C HamanoJun 12, 2022
  4. Tao KlerksJun 14, 2022
  5. Tao KlerksJun 15, 2022
  6. Tao KlerksJun 14, 2022
  7. Junio C HamanoJun 18, 2022
  8. Tao KlerksJun 18, 2022
  9. Junio C HamanoJun 12, 2022
  10. Junio C HamanoJun 13, 2022
  11. Tao KlerksJun 14, 2022
  12. Tao KlerksJun 14, 2022
  13. 0/3 RFC: apply: support case-only renames in case-insensitive filesystemsTao Klerks via GitGitGadget, Jun 19, 2022
  14. 2/3 reset: new failing test for reset of case-insensitive duplicate in indexTao Klerks via GitGitGadget, Jun 19, 2022
  15. 1/3 t4141: test "git apply" with core.ignorecaseJunio C Hamano via GitGitGadget, Jun 19, 2022
  16. 3/3 apply: support case-only renames in case-insensitive filesystemsTao Klerks via GitGitGadget, Jun 19, 2022
  17. Tao KlerksOct 10, 2022
  18. 0/3 apply: support case-only renames in case-insensitive filesystemsTao Klerks via GitGitGadget, May 28, 2023
  19. 2/3 reset: new failing test for reset of case-insensitive duplicate in indexTao Klerks via GitGitGadget, May 28, 2023
  20. 1/3 t4142: test "git apply" with core.ignorecaseJunio C Hamano via GitGitGadget, May 28, 2023
  21. 3/3 apply: support case-only renames in case-insensitive filesystemsTao Klerks via GitGitGadget, May 28, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.