From: Junio C Hamano <gitster@pobox.com>
To: Mark Mentovai <mark@chromium.org>
Cc: Git Development <git@vger.kernel.org>,
Chandra Pratap <chandrapratap3519@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Subject: Re: [PATCH v2 2/2] apply: set file mode when --reverse creates a deleted file
Date: Fri, 23 May 2025 16:44:33 -0700 [thread overview]
Message-ID: <xmqqbjrivqn2.fsf@gitster.g> (raw)
In-Reply-To: <20250523172154.93810-3-mark@chromium.org> (Mark Mentovai's message of "Fri, 23 May 2025 13:21:54 -0400")
Mark Mentovai <mark@chromium.org> writes:
> +test_file_mode_common() {
Unlike the two callers, this lacks SP before "()".
I would have expected that "no such file" would be expressed with
mode 000000 (taken from "git diff --raw" for a removal/creation
patch), but an empty string works just as well. The same comment
about requiring 0-prefix before 644 and 755 applies here, but as
long as it is done consistently, I wouldn't complain too loudly ;-)
> + test -n "$1" && test_grep "^10$1 " "$2" || test_must_be_empty "$2"
> +}
> +
> test_file_mode_staged () {
> git ls-files --stage -- "$2" >ls-files-output &&
> - test_grep "^10$1 " ls-files-output
> + test_file_mode_common "$1" ls-files-output
> }
>
> test_file_mode_HEAD () {
> git ls-tree HEAD -- "$2" >ls-tree-output &&
> - test_grep "^10$1 " ls-tree-output
> + test_file_mode_common "$1" ls-tree-output
> }
>
> test_expect_success 'git apply respects core.fileMode' '
> @@ -180,6 +184,150 @@ test_expect_success 'git apply warns about incorrect file modes' '
> test_file_mode_HEAD 0755 mode_test
> '
>
> +test_expect_success 'setup: git apply [--reverse] restores file modes (change_x_to_notx)' '
> + test_config core.fileMode false &&
> +
> + touch change_x_to_notx &&
> + git add --chmod=+x change_x_to_notx &&
> + test_file_mode_staged 0755 change_x_to_notx &&
> + test_tick && git commit -m "add change_x_to_notx as executable" &&
> + test_file_mode_HEAD 0755 change_x_to_notx &&
> +
> + git add --chmod=-x change_x_to_notx &&
> + test_file_mode_staged 0644 change_x_to_notx &&
> + test_tick && git commit -m "make change_x_to_notx not executable" &&
> + test_file_mode_HEAD 0644 change_x_to_notx &&
> +
> + git rm change_x_to_notx &&
> + test_file_mode_staged "" change_x_to_notx &&
> + test_tick && git commit -m "remove change_x_to_notx" &&
> + test_file_mode_HEAD "" change_x_to_notx &&
> +
> + git format-patch -o patches -3 &&
> + mv patches/0001-* change_x_to_notx-0001-create-0755.patch &&
> + mv patches/0002-* change_x_to_notx-0002-chmod-0644.patch &&
> + mv patches/0003-* change_x_to_notx-0003-delete.patch &&
> +
> + test_grep "^new file mode 100755$" change_x_to_notx-0001-create-0755.patch &&
> + test_grep "^old mode 100755$" change_x_to_notx-0002-chmod-0644.patch &&
> + test_grep "^new mode 100644$" change_x_to_notx-0002-chmod-0644.patch &&
> + test_grep "^deleted file mode 100644$" change_x_to_notx-0003-delete.patch
> +'
OK.
> +test_expect_success 'git apply restores file modes (change_x_to_notx)' '
> + test_config core.fileMode false &&
Wouldn't this and the subsequent tests want to begin with
git reset --hard <commit> &&
to a known good state? We expect that after successfully running
this test piece, for example, the path is removed after the last
patch that removes change-x-to-notx is applied.
If this one failed, and if the tester is not running the test with
"-i", the index and the working tree state left by failure of this
step would cause the next test start in a state that it is not
expecting. For example, if this one failed after applying
change-x-to-notx but while applying change-x-to-notx again (perhaps
it did not see the right message), the step to apply the deltion
patch is skipped. The next test wants to reverse apply the deletion
patch, which means it wants the path not to exist, but if this test
fails in the middle, that is not guaranteed.
The same comment applies to later ones, as well.
Other than that, we seem to have a very good coverage of the
combinations now. Thanks for a thorough work.
next prev parent reply other threads:[~2025-05-23 23:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 22:02 [PATCH] apply: set file mode when --reverse creates a deleted file Mark Mentovai
2025-05-22 22:24 ` Kristoffer Haugsbakk
2025-05-22 23:15 ` Junio C Hamano
2025-05-22 22:58 ` Junio C Hamano
2025-05-22 23:48 ` Mark Mentovai
2025-05-23 14:49 ` Junio C Hamano
2025-05-23 17:21 ` [PATCH v2 0/2] " Mark Mentovai
2025-05-23 17:21 ` [PATCH v2 1/2] t4129: test that git apply warns for unexpected mode changes Mark Mentovai
2025-05-23 23:32 ` Junio C Hamano
2025-05-24 3:10 ` Mark Mentovai
2025-05-23 17:21 ` [PATCH v2 2/2] apply: set file mode when --reverse creates a deleted file Mark Mentovai
2025-05-23 23:44 ` Junio C Hamano [this message]
2025-05-24 3:19 ` Mark Mentovai
2025-05-24 3:40 ` [PATCH v3 0/2] " Mark Mentovai
2025-05-24 3:40 ` [PATCH v3 1/2] t4129: test that git apply warns for unexpected mode changes Mark Mentovai
2025-05-24 3:40 ` [PATCH v3 2/2] apply: set file mode when --reverse creates a deleted file Mark Mentovai
2025-05-27 13:56 ` [PATCH v3 0/2] " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbjrivqn2.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chandrapratap3519@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=mark@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).