sparse-checkout: error or warn when given individual files
The set and add subcommands accept multiple positional arguments. The meaning of these arguments differs slightly in the two modes: Cone mode only accepts directories. If given a file, it would previously treat it as a directory, causing not just the file itself to be included but all sibling files as well -- likely against users' expectations. Throw an error if the specified path is a file in the index. Provide a --skip-checks argument to allow users to override (e.g. for the case when the given path IS a directory on another branch). Non-cone mode accepts general gitignore patterns. There are many reasons to avoid this mode, but one possible reason to use it instead of cone mode: to be able to select individual files within a directory. However, if a file is passed to set/add in non-cone mode, you won't be selecting a single file, you'll be selecting a file with the same name in any directory. Thus users will likely want to prefix any paths they specify with a leading '/' character; warn users if the patterns they specify exactly name a file because it means they are likely missing such a leading slash. Reviewed-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
bb8b5e9a90
commit
4ce504360b
@ -562,7 +562,7 @@ test_expect_success 'different sparse-checkouts with worktrees' '
|
||||
'
|
||||
|
||||
test_expect_success 'set using filename keeps file on-disk' '
|
||||
git -C repo sparse-checkout set a deep &&
|
||||
git -C repo sparse-checkout set --skip-checks a deep &&
|
||||
cat >expect <<-\EOF &&
|
||||
/*
|
||||
!/*/
|
||||
@ -839,4 +839,18 @@ test_expect_success 'set from subdir in non-cone mode throws an error' '
|
||||
grep "run from the toplevel directory in non-cone mode" error
|
||||
'
|
||||
|
||||
test_expect_success 'by default, cone mode will error out when passed files' '
|
||||
git -C repo sparse-checkout reapply --cone &&
|
||||
test_must_fail git -C repo sparse-checkout add .gitignore 2>error &&
|
||||
|
||||
grep ".gitignore.*is not a directory" error
|
||||
'
|
||||
|
||||
test_expect_success 'by default, non-cone mode will warn on individual files' '
|
||||
git -C repo sparse-checkout reapply --no-cone &&
|
||||
git -C repo sparse-checkout add .gitignore 2>warning &&
|
||||
|
||||
grep "pass a leading slash before paths.*if you want a single file" warning
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user