--- v4
+++ v1
@@ -15,23 +15,22 @@
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
- Documentation/git-ls-files.txt | 5 ++
- builtin/ls-files.c | 12 +++-
- t/t1092-sparse-checkout-compatibility.sh | 91 ++++++++++++++++++++++++
- 3 files changed, 106 insertions(+), 2 deletions(-)
+ Documentation/git-ls-files.txt | 4 ++
+ builtin/ls-files.c | 12 +++++-
+ t/t1092-sparse-checkout-compatibility.sh | 47 ++++++++++++++++++++++++
+ 3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
-index 2e3d695fa21..48cc7c0b6f4 100644
+index 6d11ab506b7..1c5d5f85ec5 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
-@@ -187,6 +187,11 @@ Both the <eolinfo> in the index ("i/<eolinfo>")
+@@ -187,6 +187,10 @@ Both the <eolinfo> in the index ("i/<eolinfo>")
and in the working tree ("w/<eolinfo>") are shown for regular files,
followed by the ("attr/<eolattr>").
+--sparse::
+ If the index is sparse, show the sparse directories without expanding
-+ to the contained files. Sparse directories will be shown with a
-+ trailing slash, such as "x/" for a sparse directory "x".
++ to the contained files.
+
\--::
Do not interpret any more arguments as options.
@@ -81,11 +80,11 @@
if (prefix)
prefix_len = strlen(prefix);
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
-index 8d3c21fc84c..0c51e9bd3b7 100755
+index f8a8dde60af..ffb6052ff60 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
-@@ -816,6 +816,12 @@ test_expect_success 'sparse-index is expanded and converted back' '
- GIT_TRACE2_EVENT="$(pwd)/trace2.txt" \
+@@ -814,6 +814,12 @@ test_expect_success 'sparse-index is expanded and converted back' '
+ GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
git -C sparse-index reset -- folder1/a &&
test_region index convert_to_sparse trace2.txt &&
+ test_region index ensure_full_index trace2.txt &&
@@ -97,7 +96,7 @@
test_region index ensure_full_index trace2.txt
'
-@@ -871,6 +877,7 @@ test_expect_success 'sparse-index is not expanded' '
+@@ -838,6 +844,7 @@ test_expect_success 'sparse-index is not expanded' '
init_repos &&
ensure_not_expanded status &&
@@ -105,57 +104,34 @@
ensure_not_expanded commit --allow-empty -m empty &&
echo >>sparse-index/a &&
ensure_not_expanded commit -a -m a &&
-@@ -1019,6 +1026,90 @@ test_expect_success 'sparse index is not expanded: fetch/pull' '
+@@ -942,6 +949,46 @@ test_expect_success 'sparse index is not expanded: fetch/pull' '
ensure_not_expanded pull full base
'
+test_expect_success 'ls-files' '
+ init_repos &&
+
-+ # Use a smaller sparse-checkout for reduced output
-+ test_sparse_match git sparse-checkout set &&
-+
+ # Behavior agrees by default. Sparse index is expanded.
+ test_all_match git ls-files &&
+
+ # With --sparse, the sparse index data changes behavior.
-+ git -C sparse-index ls-files --sparse >actual &&
-+
-+ cat >expect <<-\EOF &&
-+ a
-+ deep/
-+ e
-+ folder1-
-+ folder1.x
-+ folder1/
-+ folder10
-+ folder2/
-+ g
-+ x/
-+ z
-+ EOF
-+
-+ test_cmp expect actual &&
++ git -C sparse-index ls-files --sparse >sparse-index-out &&
++ grep "^folder1/\$" sparse-index-out &&
++ grep "^folder2/\$" sparse-index-out &&
+
+ # With --sparse and no sparse index, nothing changes.
-+ git -C sparse-checkout ls-files >dense &&
-+ git -C sparse-checkout ls-files --sparse >sparse &&
-+ test_cmp dense sparse &&
++ git -C sparse-checkout ls-files --sparse >sparse-checkout-out &&
++ grep "^folder1/0/0/0\$" sparse-checkout-out &&
++ ! grep "/\$" sparse-checkout-out &&
+
-+ # Set up a strange condition of having a file edit
-+ # outside of the sparse-checkout cone. This is just
-+ # to verify that sparse-checkout and sparse-index
-+ # behave the same in this case.
+ write_script edit-content <<-\EOF &&
+ mkdir folder1 &&
+ echo content >>folder1/a
+ EOF
+ run_on_sparse ../edit-content &&
+
-+ # ls-files does not currently notice modified files whose
-+ # cache entries are marked SKIP_WORKTREE. This may change
-+ # in the future, but here we test that sparse index does
-+ # not accidentally create a change of behavior.
++ # ls-files does not notice modified files whose
++ # cache entries are marked SKIP_WORKTREE.
+ test_sparse_match git ls-files --modified &&
+ test_must_be_empty sparse-checkout-out &&
+ test_must_be_empty sparse-index-out &&
@@ -163,33 +139,12 @@
+ git -C sparse-index ls-files --sparse --modified >sparse-index-out &&
+ test_must_be_empty sparse-index-out &&
+
-+ # Add folder1 to the sparse-checkout cone and
-+ # check that ls-files shows the expanded files.
-+ test_sparse_match git sparse-checkout add folder1 &&
++ run_on_sparse git sparse-checkout add folder1 &&
+ test_sparse_match git ls-files --modified &&
++ grep "^folder1/a\$" sparse-checkout-out &&
++ grep "^folder1/a\$" sparse-index-out &&
+
-+ test_all_match git ls-files &&
-+ git -C sparse-index ls-files --sparse >actual &&
-+
-+ cat >expect <<-\EOF &&
-+ a
-+ deep/
-+ e
-+ folder1-
-+ folder1.x
-+ folder1/0/0/0
-+ folder1/0/1
-+ folder1/a
-+ folder10
-+ folder2/
-+ g
-+ x/
-+ z
-+ EOF
-+
-+ test_cmp expect actual &&
-+
-+ # Double-check index expansion is avoided
++ # Double-check index expansion
+ ensure_not_expanded ls-files --sparse
+'
+
@@ -198,4 +153,3 @@
test_expect_success 'reset mixed and checkout orphan' '
--
gitgitgadget
-