Skip to content

Commit

Permalink
squash! sparse-checkout: error by default when given individual files
Browse files Browse the repository at this point in the history
"""sparse-checkout: error or warn when given individual files"""

also, cut off at "...likely missing such a leading slash." (and remove
extra "missing".

Maybe comment that we warning() instead of die() because leading slashes
on Windows boxes are often corrupted unless quoted.
  • Loading branch information
newren committed Feb 18, 2022
1 parent 60256fc commit ff0eb2c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion builtin/sparse-checkout.c
Expand Up @@ -735,7 +735,7 @@ static void sanitize_paths(int argc, const char **argv,
if (core_sparse_checkout_cone)
die(_("'%s' is not a directory; to treat it as a directory anyway, rerun with --skip-checks"), argv[i]);
else
die(_("pass a leading slash before paths such as '%s' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), argv[i]);
warning(_("pass a leading slash before paths such as '%s' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), argv[i]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions t/t1091-sparse-checkout-builtin.sh
Expand Up @@ -387,7 +387,7 @@ test_expect_success 'revert to old sparse-checkout on empty update' '
git sparse-checkout set nothing 2>err &&
test_i18ngrep ! "Sparse checkout leaves no entry on working directory" err &&
test_i18ngrep ! ".git/index.lock" err &&
git sparse-checkout set /file
git sparse-checkout set file
)
'

Expand Down Expand Up @@ -848,9 +848,9 @@ test_expect_success 'by default, cone mode will error out when passed files' '

test_expect_success 'by default, non-cone mode will warn on individual files' '
git -C repo sparse-checkout reapply --no-cone &&
test_must_fail git -C repo sparse-checkout add .gitignore 2>error &&
git -C repo sparse-checkout add .gitignore 2>warning &&
grep "pass a leading slash before paths.*if you want a single file" error
grep "pass a leading slash before paths.*if you want a single file" warning
'

test_done
12 changes: 6 additions & 6 deletions t/t3602-rm-sparse-checkout.sh
Expand Up @@ -30,7 +30,7 @@ test_expect_success 'setup' "
for opt in "" -f --dry-run
do
test_expect_success "rm${opt:+ $opt} does not remove sparse entries" '
git sparse-checkout set /a &&
git sparse-checkout set a &&
test_must_fail git rm $opt b 2>stderr &&
test_cmp b_error_and_hint stderr &&
git ls-files --error-unmatch b
Expand Down Expand Up @@ -70,22 +70,22 @@ test_expect_success 'recursive rm --sparse removes sparse entries' '

test_expect_success 'rm obeys advice.updateSparsePath' '
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr &&
test_cmp sparse_entry_b_error stderr
'

test_expect_success 'do not advice about sparse entries when they do not match the pathspec' '
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
test_must_fail git rm 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 about sparse entries when pathspec matches dense entries' '
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
git rm "[ba]" 2>stderr &&
test_must_be_empty stderr &&
git ls-files --error-unmatch b &&
Expand All @@ -94,15 +94,15 @@ test_expect_success 'do not warn about sparse entries when pathspec matches dens

test_expect_success 'do not warn about sparse entries with --ignore-unmatch' '
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
git rm --ignore-unmatch b 2>stderr &&
test_must_be_empty stderr &&
git ls-files --error-unmatch b
'

test_expect_success 'refuse to rm a non-skip-worktree path outside sparse cone' '
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
git update-index --no-skip-worktree b &&
test_must_fail git rm b 2>stderr &&
test_cmp b_error_and_hint stderr &&
Expand Down
4 changes: 2 additions & 2 deletions t/t6428-merge-conflicts-sparse.sh
Expand Up @@ -87,7 +87,7 @@ test_expect_success 'conflicting entries written to worktree even if sparse' '
test_path_is_file numerals &&
git sparse-checkout init &&
git sparse-checkout set /README &&
git sparse-checkout set README &&
test_path_is_file README &&
test_path_is_missing numerals &&
Expand Down Expand Up @@ -123,7 +123,7 @@ test_expect_merge_algorithm failure success 'present-despite-SKIP_WORKTREE handl
test_path_is_file numerals &&
git sparse-checkout init &&
git sparse-checkout set /README &&
git sparse-checkout set README &&
test_path_is_file README &&
test_path_is_missing numerals &&
Expand Down
12 changes: 6 additions & 6 deletions t/t7002-mv-sparse-checkout.sh
Expand Up @@ -27,7 +27,7 @@ test_expect_success 'setup' "
test_expect_success 'mv refuses to move sparse-to-sparse' '
test_when_finished rm -f e &&
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
touch b &&
test_must_fail git mv b e 2>stderr &&
cat sparse_error_header >expect &&
Expand All @@ -42,7 +42,7 @@ test_expect_success 'mv refuses to move sparse-to-sparse' '
test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
test_when_finished rm -f b c e &&
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
# tracked-to-untracked
touch b &&
Expand Down Expand Up @@ -81,7 +81,7 @@ test_expect_success 'mv refuses to move sparse-to-sparse, ignores failure' '
test_expect_success 'mv refuses to move non-sparse-to-sparse' '
test_when_finished rm -f b c e &&
git reset --hard &&
git sparse-checkout set /a &&
git sparse-checkout set a &&
# tracked-to-untracked
test_must_fail git mv a e 2>stderr &&
Expand Down Expand Up @@ -115,7 +115,7 @@ test_expect_success 'mv refuses to move non-sparse-to-sparse' '
test_expect_success 'mv refuses to move sparse-to-non-sparse' '
test_when_finished rm -f b c e &&
git reset --hard &&
git sparse-checkout set /a e &&
git sparse-checkout set a e &&
# tracked-to-untracked
touch b &&
Expand Down Expand Up @@ -187,7 +187,7 @@ test_expect_success 'recursive mv refuses to move sparse' '
test_expect_success 'can move files to non-sparse dir' '
git reset --hard &&
git sparse-checkout init --no-cone &&
git sparse-checkout set /a /b /c /w !/x y/ &&
git sparse-checkout set a b c w !/x y/ &&
mkdir -p w x/y &&
git mv a w/new-a 2>stderr &&
Expand All @@ -198,7 +198,7 @@ test_expect_success 'can move files to non-sparse dir' '
test_expect_success 'refuse to move file to non-skip-worktree sparse path' '
git reset --hard &&
git sparse-checkout init --no-cone &&
git sparse-checkout set /a !/x y/ !x/y/z &&
git sparse-checkout set a !/x y/ !x/y/z &&
mkdir -p x/y/z &&
test_must_fail git mv a x/y/z/new-a 2>stderr &&
Expand Down
2 changes: 1 addition & 1 deletion t/t7817-grep-sparse-checkout.sh
Expand Up @@ -66,7 +66,7 @@ test_expect_success 'setup' '
git add a b dir &&
git commit -m super &&
git sparse-checkout init --no-cone &&
git sparse-checkout set "/*" "!b" "!/*/" "/sub" &&
git sparse-checkout set "/*" "!b" "!/*/" "sub" &&
git tag -am tag-to-commit tag-to-commit HEAD &&
tree=$(git rev-parse HEAD^{tree}) &&
Expand Down

0 comments on commit ff0eb2c

Please sign in to comment.