From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, newren@gmail.com,
Phillip Wood <phillip.wood123@gmail.com>,
Derrick Stolee <stolee@gmail.com>,
Derrick Stolee <stolee@gmail.com>
Subject: [PATCH v2 3/4] reset: integrate sparse index with --patch
Date: Fri, 16 May 2025 14:55:29 +0000 [thread overview]
Message-ID: <d1482a29d8f23699c713238ba37266fe9efa9aea.1747407330.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1914.v2.git.1747407330.gitgitgadget@gmail.com>
From: Derrick Stolee <stolee@gmail.com>
Similar to the previous change for 'git add -p', the reset builtin
checked for integration with the sparse index after possibly redirecting
its logic toward the interactive logic. This means that the builtin
would expand the sparse index to a full one upon read.
Move this check earlier within cmd_reset() to improve performance here.
Add tests to guarantee that we are not universally expanding the index.
Add behavior tests to check that we are doing the same operations as a
full index.
Signed-off-by: Derrick Stolee <stolee@gmail.com>
---
builtin/reset.c | 6 ++--
t/t1092-sparse-checkout-compatibility.sh | 42 ++++++++++++++++++++++--
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/builtin/reset.c b/builtin/reset.c
index 73b4537a9a56..dc50ffc1ac59 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -420,6 +420,9 @@ int cmd_reset(int argc,
oidcpy(&oid, &tree->object.oid);
}
+ prepare_repo_settings(the_repository);
+ the_repository->settings.command_requires_full_index = 0;
+
if (patch_mode) {
if (reset_type != NONE)
die(_("options '%s' and '%s' cannot be used together"), "--patch", "--{hard,mixed,soft}");
@@ -457,9 +460,6 @@ int cmd_reset(int argc,
if (intent_to_add && reset_type != MIXED)
die(_("the option '%s' requires '%s'"), "-N", "--mixed");
- prepare_repo_settings(the_repository);
- the_repository->settings.command_requires_full_index = 0;
-
if (repo_read_index(the_repository) < 0)
die(_("index file corrupt"));
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index c419d8b57e84..d8101139b40a 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -384,7 +384,7 @@ test_expect_success 'add, commit, checkout' '
test_all_match git checkout -
'
-test_expect_success 'git add -p' '
+test_expect_success 'git add, checkout, and reset with -p' '
init_repos &&
write_script edit-contents <<-\EOF &&
@@ -398,7 +398,7 @@ test_expect_success 'git add -p' '
test_write_lines y n >in &&
run_on_all git add -p <in &&
test_all_match git status --porcelain=v2 &&
- test_all_match git reset &&
+ test_all_match git reset -p <in &&
test_write_lines u 1 "" q >in &&
run_on_all git add -i <in &&
@@ -413,6 +413,12 @@ test_expect_success 'git add -p' '
test_sparse_match git reset &&
test_write_lines u 2 3 "" q >in &&
run_on_all git add -i <in &&
+ test_sparse_match git status --porcelain=v2 &&
+
+ run_on_all git add --sparse folder1 &&
+ run_on_all git commit -m "take changes" &&
+ test_write_lines y n y >in &&
+ test_sparse_match git checkout HEAD~1 --patch <in &&
test_sparse_match git status --porcelain=v2
'
@@ -2458,6 +2464,38 @@ test_expect_success 'sparse-index is not expanded: git add -p' '
ensure_expanded add -i <in
'
+test_expect_success 'sparse-index is not expanded: checkout -p, reset -p' '
+ init_repos &&
+
+ # Does not expand when edits are within sparse checkout.
+ echo "new content" >sparse-index/deep/a &&
+ echo "new content" >sparse-index/deep/deeper1/a &&
+ git -C sparse-index commit -a -m "inside-changes" &&
+
+ test_write_lines y y >in &&
+ ensure_not_expanded checkout HEAD~1 --patch <in &&
+
+ echo "new content" >sparse-index/deep/a &&
+ echo "new content" >sparse-index/deep/deeper1/a &&
+ git -C sparse-index add . &&
+ ensure_not_expanded reset --patch <in &&
+
+ # -p does expand when edits are outside sparse checkout.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ git -C sparse-index add --sparse folder1 &&
+ git -C sparse-index sparse-checkout reapply &&
+ ensure_expanded reset --patch <in &&
+
+ # Fully reset the index.
+ mkdir -p sparse-index/folder1 &&
+ echo "new content" >sparse-index/folder1/a &&
+ git -C sparse-index add --sparse folder1 &&
+ git -C sparse-index commit -m "folder1 change" &&
+ git -C sparse-index sparse-checkout reapply &&
+ ensure_expanded checkout HEAD~1 --patch <in
+'
+
test_expect_success 'advice.sparseIndexExpanded' '
init_repos &&
--
gitgitgadget
next prev parent reply other threads:[~2025-05-16 14:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 0:55 [PATCH 0/3] Integrate the sparse index with 'git apply' and 'git add -p/-i' Derrick Stolee via GitGitGadget
2025-05-07 0:55 ` [PATCH 1/3] apply: integrate with the sparse index Derrick Stolee via GitGitGadget
2025-05-10 3:18 ` Elijah Newren
2025-05-16 12:49 ` Derrick Stolee
2025-05-07 0:55 ` [PATCH 2/3] git add: make -p/-i aware of " Derrick Stolee via GitGitGadget
2025-05-10 4:38 ` Elijah Newren
2025-05-16 12:54 ` Derrick Stolee
2025-05-07 0:55 ` [PATCH 3/3] p2000: add performance test for 'git add -p' Derrick Stolee via GitGitGadget
2025-05-10 4:39 ` Elijah Newren
2025-05-08 18:26 ` [PATCH 0/3] Integrate the sparse index with 'git apply' and 'git add -p/-i' Junio C Hamano
2025-05-14 15:16 ` Phillip Wood
2025-05-16 13:28 ` Derrick Stolee
2025-05-20 15:07 ` phillip.wood123
2025-05-16 14:55 ` [PATCH v2 0/4] Integrate the sparse index with 'git apply' and interactive add, checkout, and reset Derrick Stolee via GitGitGadget
2025-05-16 14:55 ` [PATCH v2 1/4] apply: integrate with the sparse index Derrick Stolee via GitGitGadget
2025-05-16 14:55 ` [PATCH v2 2/4] git add: make -p/-i aware of " Derrick Stolee via GitGitGadget
2025-05-16 14:55 ` Derrick Stolee via GitGitGadget [this message]
2025-05-16 16:20 ` [PATCH v2 3/4] reset: integrate sparse index with --patch Elijah Newren
2025-05-16 14:55 ` [PATCH v2 4/4] p2000: add performance test for patch-mode commands Derrick Stolee via GitGitGadget
2025-05-16 15:32 ` [PATCH v2 0/4] Integrate the sparse index with 'git apply' and interactive add, checkout, and reset Elijah Newren
2025-05-16 16:35 ` Derrick Stolee
2025-05-16 18:55 ` 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=d1482a29d8f23699c713238ba37266fe9efa9aea.1747407330.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=stolee@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).