mirror of
https://github.com/git/git.git
synced 2026-04-10 00:40:14 +02:00
sparse-checkout: check for dirty status
The index-merge performed by 'git sparse-checkout' will erase any staged changes, which can lead to data loss. Prevent these attempts by requiring a clean 'git status' output. Helped-by: Szeder Gábor <szeder.dev@gmail.com> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
416adc8711
commit
cff4e9138d
@@ -250,10 +250,11 @@ test_expect_success 'cone mode: set with nested folders' '
|
||||
'
|
||||
|
||||
test_expect_success 'revert to old sparse-checkout on bad update' '
|
||||
test_when_finished git -C repo reset --hard &&
|
||||
echo update >repo/deep/deeper2/a &&
|
||||
cp repo/.git/info/sparse-checkout expect &&
|
||||
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
|
||||
test_i18ngrep "Cannot update sparse checkout" err &&
|
||||
test_i18ngrep "cannot set sparse-checkout patterns" err &&
|
||||
test_cmp repo/.git/info/sparse-checkout expect &&
|
||||
ls repo/deep >dir &&
|
||||
cat >expect <<-EOF &&
|
||||
@@ -291,4 +292,16 @@ test_expect_success '.gitignore should not warn about cone mode' '
|
||||
test_i18ngrep ! "disabling cone patterns" err
|
||||
'
|
||||
|
||||
test_expect_success 'sparse-checkout (init|set|disable) fails with dirty status' '
|
||||
git clone repo dirty &&
|
||||
echo dirty >dirty/folder1/a &&
|
||||
test_must_fail git -C dirty sparse-checkout init &&
|
||||
test_must_fail git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
|
||||
test_must_fail git -C dirty sparse-checkout disable &&
|
||||
git -C dirty reset --hard &&
|
||||
git -C dirty sparse-checkout init &&
|
||||
git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* &&
|
||||
git -C dirty sparse-checkout disable
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user