summaryrefslogtreecommitdiff
path: root/t/t3705-add-sparse-checkout.sh
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2021-04-08 20:41:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-08 21:18:03 (GMT)
commita20f70478ffcc66d30936920ebcc35ebfc12a7c7 (patch)
tree1e5865434bde7d8f5a94bb6f93ba304df307bd4c /t/t3705-add-sparse-checkout.sh
parentb243012cb39e2151ffae96bded2387751d876d12 (diff)
downloadgit-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.zip
git-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.tar.gz
git-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.tar.bz2
add: warn when asked to update SKIP_WORKTREE entries
`git add` already refrains from updating SKIP_WORKTREE entries, but it silently exits with zero code when it is asked to do so. Instead, let's warn the user and display a hint on how to update these entries. Note that we only warn the user whey they give a pathspec item that matches no eligible path for updating, but it does match one or more SKIP_WORKTREE entries. A warning was chosen over erroring out right away to reproduce the same behavior `add` already exhibits with ignored files. This also allow users to continue their workflow without having to invoke `add` again with only the eligible paths (as those will have already been added). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3705-add-sparse-checkout.sh')
-rwxr-xr-xt/t3705-add-sparse-checkout.sh73
1 files changed, 66 insertions, 7 deletions
diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh
index 00b10ac..2b1fd0d 100755
--- a/t/t3705-add-sparse-checkout.sh
+++ b/t/t3705-add-sparse-checkout.sh
@@ -36,10 +36,26 @@ setup_gitignore () {
EOF
}
+test_expect_success 'setup' "
+ cat >sparse_error_header <<-EOF &&
+ The following pathspecs didn't match any eligible path, but they do match index
+ entries outside the current sparse checkout:
+ EOF
+
+ cat >sparse_hint <<-EOF &&
+ hint: Disable or modify the sparsity rules if you intend to update such entries.
+ hint: Disable this message with \"git config advice.updateSparsePath false\"
+ EOF
+
+ echo sparse_entry | cat sparse_error_header - >sparse_entry_error &&
+ cat sparse_entry_error sparse_hint >error_and_hint
+"
+
test_expect_success 'git add does not remove sparse entries' '
setup_sparse_entry &&
rm sparse_entry &&
- git add sparse_entry &&
+ test_must_fail git add sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
test_sparse_entry_unchanged
'
@@ -47,7 +63,8 @@ test_expect_success 'git add -A does not remove sparse entries' '
setup_sparse_entry &&
rm sparse_entry &&
setup_gitignore &&
- git add -A &&
+ git add -A 2>stderr &&
+ test_must_be_empty stderr &&
test_sparse_entry_unchanged
'
@@ -55,7 +72,13 @@ test_expect_success 'git add . does not remove sparse entries' '
setup_sparse_entry &&
rm sparse_entry &&
setup_gitignore &&
- git add . &&
+ test_must_fail git add . 2>stderr &&
+
+ cat sparse_error_header >expect &&
+ echo . >>expect &&
+ cat sparse_hint >>expect &&
+
+ test_cmp expect stderr &&
test_sparse_entry_unchanged
'
@@ -64,7 +87,8 @@ do
test_expect_success "git add${opt:+ $opt} does not update sparse entries" '
setup_sparse_entry &&
echo modified >sparse_entry &&
- git add $opt sparse_entry &&
+ test_must_fail git add $opt sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
test_sparse_entry_unchanged
'
done
@@ -73,14 +97,16 @@ test_expect_success 'git add --refresh does not update sparse entries' '
setup_sparse_entry &&
git ls-files --debug sparse_entry | grep mtime >before &&
test-tool chmtime -60 sparse_entry &&
- git add --refresh sparse_entry &&
+ test_must_fail git add --refresh sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
git ls-files --debug sparse_entry | grep mtime >after &&
test_cmp before after
'
test_expect_success 'git add --chmod does not update sparse entries' '
setup_sparse_entry &&
- git add --chmod=+x sparse_entry &&
+ test_must_fail git add --chmod=+x sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
test_sparse_entry_unchanged &&
! test -x sparse_entry
'
@@ -89,8 +115,41 @@ test_expect_success 'git add --renormalize does not update sparse entries' '
test_config core.autocrlf false &&
setup_sparse_entry "LINEONE\r\nLINETWO\r\n" &&
echo "sparse_entry text=auto" >.gitattributes &&
- git add --renormalize sparse_entry &&
+ test_must_fail git add --renormalize sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
+ test_sparse_entry_unchanged
+'
+
+test_expect_success 'git add --dry-run --ignore-missing warn on sparse path' '
+ setup_sparse_entry &&
+ rm sparse_entry &&
+ test_must_fail git add --dry-run --ignore-missing sparse_entry 2>stderr &&
+ test_cmp error_and_hint stderr &&
test_sparse_entry_unchanged
'
+test_expect_success 'do not advice about sparse entries when they do not match the pathspec' '
+ setup_sparse_entry &&
+ test_must_fail git add nonexistent 2>stderr &&
+ grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
+ ! grep -F -f sparse_error_header stderr
+'
+
+test_expect_success 'do not warn when pathspec matches dense entries' '
+ setup_sparse_entry &&
+ echo modified >sparse_entry &&
+ >dense_entry &&
+ git add "*_entry" 2>stderr &&
+ test_must_be_empty stderr &&
+ test_sparse_entry_unchanged &&
+ git ls-files --error-unmatch dense_entry
+'
+
+test_expect_success 'add obeys advice.updateSparsePath' '
+ setup_sparse_entry &&
+ test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr &&
+ test_cmp sparse_entry_error stderr
+
+'
+
test_done