From: Junio C Hamano <gitster@pobox.com>
To: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Cc: git@vger.kernel.org, phillip.wood123@gmail.com,
christian.couder@gmail.com
Subject: Re: [PATCH v5 1/2] t7501: add tests for --include and --only
Date: Tue, 16 Jan 2024 07:56:07 -0800 [thread overview]
Message-ID: <xmqq1qah46i0.fsf@gitster.g> (raw)
In-Reply-To: <20240113042254.38602-2-shyamthakkar001@gmail.com> (Ghanshyam Thakkar's message of "Sat, 13 Jan 2024 09:51:54 +0530")
Ghanshyam Thakkar <shyamthakkar001@gmail.com> writes:
> +test_expect_success 'fail to commit untracked pathspec (even with --include/--only)' '
"untracked pathspec" is a nonsense word. We do not track pathspec;
you may use pathspec to specify which path(s) to work on. I think
this is more about untracked files being ignored for the purpose of
"-i" and "-o".
You used to call this "untracked file", which probably makes more
sense.
> + # TODO: as for --include, the below command will fail because nothing is
> + # staged. If something was staged, it would not fail even if the
> + # pathspec was untracked (however, pathspec will remain untracked and
> + # staged changes would be committed.) In either cases, no error is
Both uses of "pathspec" here are nonsense. Saying "even though the
pathspec does not match any tracked path" is OK. "(however, the
untracked path that match the pathspec are not added and only the
changes in the index gets commit)" is also OK.
> + # returned to stderr like in (-o and without -o/-i) cases. In a
> + # similar manner, "git add -u baz" also does not error out.
> + #
> + # Therefore, the below test is just to document the current behavior
> + # and is not an endorsement to the current behavior, and we may
> + # want to fix this. And when that happens, this test should be
> + # updated accordingly.
OK.
> @@ -117,6 +143,55 @@ test_expect_success '--long with stuff to commit returns ok' '
> git commit -m next -a --long
> '
>
> +for opt in "" "-o" "--only"
> +do
> + test_expect_success 'exclude additional staged changes when given pathspec' '
> + echo content >>file &&
> + echo content >>baz &&
> + git add baz &&
> + git commit $opt -m "file" file &&
> +
> + git diff --name-only >actual &&
> + test_must_be_empty actual &&
> +
> + git diff --name-only --staged >actual &&
> + test_cmp - actual <<-EOF &&
> + baz
> + EOF
It is probably more common to say
test_write_lines baz >expect &&
git diff --name-only --cached >actual &&
test_cmp expect actual
especially when the expected pattern is a file with short lines,
instead of here-text. It makes it easier to debug tests, too,
because after "sh t7501-*.sh -i" fails, you can go to the trash
directory and the expectation as well as the actual output are
there in files.
> + git diff --name-only HEAD^ HEAD >actual &&
> + test_cmp - actual <<-EOF
> + file
> + EOF
Ditto.
This tests the most important aspect of "-o"; even when the index
has other changes relative to HEAD already, they are skipped over
and only the changes to paths that match the given pathspec are
committed, and this test demonstrates it. Well done.
> +test_expect_success '-i/--include includes staged changes' '
> + echo content >>file &&
> + echo content >>baz &&
> + git add file &&
> +
> + # baz is in the index, therefore, it will be committed
> + git commit --include -m "file and baz" baz &&
> +
> + git diff --name-only HEAD >remaining &&
> + test_must_be_empty remaining &&
> +
> + git diff --name-only HEAD^ HEAD >changes &&
> + test_cmp - changes <<-EOF
> + baz
> + file
> + EOF
Again with "test_write_lines baz file >expect", this test becomes a
bit shorter.
This tests the most important aspect of "-i"; changes to the paths
that match the given pathspec are added to the index, and recorded
together with changes added to the index already to the commit.
Well done.
> +'
> +
> +test_expect_success '--include and --only do not mix' '
> + test_when_finished "git reset --hard" &&
> + echo content >>file &&
> + echo content >>baz &&
> + test_must_fail git commit --include --only -m "file baz" file baz 2>actual &&
> + test_grep -e "fatal: options .-i/--include. and .-o/--only. cannot be used together" actual
> +'
> +
> test_expect_success 'commit message from non-existing file' '
> echo more bongo: bongo bongo bongo bongo >file &&
> test_must_fail git commit -F gah -a
Very nicely done.
Thanks.
next prev parent reply other threads:[~2024-01-16 15:56 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-09 6:04 [PATCH 0/2][GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and amending commit to add signoff Ghanshyam Thakkar
2024-01-09 6:04 ` [PATCH 1/2] t7501: Add tests for various index usages, -i and -o, of commit command Ghanshyam Thakkar
2024-01-09 9:20 ` Christian Couder
2024-01-09 17:10 ` Ghanshyam Thakkar
2024-01-09 17:35 ` Junio C Hamano
2024-01-09 6:04 ` [PATCH 2/2] t7501: Add test for amending commit to add signoff Ghanshyam Thakkar
2024-01-09 10:44 ` Phillip Wood
2024-01-09 17:24 ` Ghanshyam Thakkar
2024-01-09 17:45 ` Junio C Hamano
2024-01-09 9:32 ` [PATCH 0/2][GSOC] t7501: Add tests for various index usages, -i and -o, of commit command and " Christian Couder
2024-01-09 16:51 ` [PATCH v2 0/2] t7501: add tests for --include, --only, Ghanshyam Thakkar
2024-01-10 16:35 ` [PATCH v3 0/2] t7501: add tests for --include, --only and Ghanshyam Thakkar
2024-01-12 18:00 ` [PATCH v4 0/2] t7501: add tests for --include, --only, --signoff Ghanshyam Thakkar
2024-01-12 18:00 ` [PATCH v4 1/2] t7501: add tests for --include and --only Ghanshyam Thakkar
2024-01-12 23:10 ` Junio C Hamano
2024-01-13 1:00 ` Ghanshyam Thakkar
2024-01-13 1:16 ` Junio C Hamano
2024-01-13 1:47 ` Ghanshyam Thakkar
2024-01-12 18:00 ` [PATCH v4 2/2] t7501: add tests for --amend --signoff Ghanshyam Thakkar
2024-01-13 4:21 ` [PATCH v5 0/2] t7501: add tests for --include, --only, --signoff Ghanshyam Thakkar
2024-01-13 4:21 ` [PATCH v5 1/2] t7501: add tests for --include and --only Ghanshyam Thakkar
2024-01-16 15:41 ` Junio C Hamano
2024-01-16 15:56 ` Junio C Hamano [this message]
2024-01-13 4:21 ` [PATCH v5 2/2] t7501: add tests for --amend --signoff Ghanshyam Thakkar
2024-01-17 16:13 ` [PATCH v6 0/2] t7501: add tests for --include, --only, --signoff Ghanshyam Thakkar
2024-01-17 16:13 ` [PATCH v6 1/2] t7501: add tests for --include and --only Ghanshyam Thakkar
2024-01-17 16:13 ` [PATCH v6 2/2] t7501: add tests for --amend --signoff Ghanshyam Thakkar
2024-01-17 21:33 ` [PATCH v6 0/2] t7501: add tests for --include, --only, --signoff Junio C Hamano
2024-01-10 16:35 ` [PATCH v3 1/2] t7501: add tests for --include and --only Ghanshyam Thakkar
2024-01-10 18:37 ` Junio C Hamano
2024-01-11 1:58 ` Ghanshyam Thakkar
2024-01-11 16:33 ` phillip.wood123
2024-01-10 16:35 ` [PATCH v3 2/2] t7501: add tests for --amend --signoff Ghanshyam Thakkar
2024-01-11 16:30 ` phillip.wood123
2024-01-09 16:51 ` [PATCH v2 1/2] t7501: add tests for --include, --only of commit Ghanshyam Thakkar
2024-01-09 17:50 ` Junio C Hamano
2024-01-09 16:51 ` [PATCH v2 2/2] t7501: add test for --amend with --signoff Ghanshyam Thakkar
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=xmqq1qah46i0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood123@gmail.com \
--cc=shyamthakkar001@gmail.com \
/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).