зеркало из https://github.com/microsoft/git.git
Merge branch 'nd/maint-sparse-errors'
* nd/maint-sparse-errors: Add explanation why we do not allow to sparse checkout to empty working tree sparse checkout: show error messages when worktree shaping fails
This commit is contained in:
Коммит
08ec3b5e4d
|
@ -234,4 +234,20 @@ test_expect_success 'read-tree --reset removes outside worktree' '
|
||||||
test_cmp empty result
|
test_cmp empty result
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'print errors when failed to update worktree' '
|
||||||
|
echo sub >.git/info/sparse-checkout &&
|
||||||
|
git checkout -f init &&
|
||||||
|
mkdir sub &&
|
||||||
|
touch sub/added sub/addedtoo &&
|
||||||
|
test_must_fail git checkout top 2>actual &&
|
||||||
|
cat >expected <<\EOF &&
|
||||||
|
error: The following untracked working tree files would be overwritten by checkout:
|
||||||
|
sub/added
|
||||||
|
sub/addedtoo
|
||||||
|
Please move or remove them before you can switch branches.
|
||||||
|
Aborting
|
||||||
|
EOF
|
||||||
|
test_cmp expected actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
|
@ -1091,6 +1091,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
||||||
*/
|
*/
|
||||||
mark_new_skip_worktree(o->el, &o->result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);
|
mark_new_skip_worktree(o->el, &o->result, CE_ADDED, CE_SKIP_WORKTREE | CE_NEW_SKIP_WORKTREE);
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
for (i = 0; i < o->result.cache_nr; i++) {
|
for (i = 0; i < o->result.cache_nr; i++) {
|
||||||
struct cache_entry *ce = o->result.cache[i];
|
struct cache_entry *ce = o->result.cache[i];
|
||||||
|
|
||||||
|
@ -1103,19 +1104,30 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
|
||||||
* correct CE_NEW_SKIP_WORKTREE
|
* correct CE_NEW_SKIP_WORKTREE
|
||||||
*/
|
*/
|
||||||
if (ce->ce_flags & CE_ADDED &&
|
if (ce->ce_flags & CE_ADDED &&
|
||||||
verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o))
|
verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) {
|
||||||
return -1;
|
if (!o->show_all_errors)
|
||||||
|
goto return_failed;
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (apply_sparse_checkout(ce, o)) {
|
if (apply_sparse_checkout(ce, o)) {
|
||||||
|
if (!o->show_all_errors)
|
||||||
|
goto return_failed;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
if (!ce_skip_worktree(ce))
|
if (!ce_skip_worktree(ce))
|
||||||
empty_worktree = 0;
|
empty_worktree = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (ret < 0)
|
||||||
|
goto return_failed;
|
||||||
|
/*
|
||||||
|
* Sparse checkout is meant to narrow down checkout area
|
||||||
|
* but it does not make sense to narrow down to empty working
|
||||||
|
* tree. This is usually a mistake in sparse checkout rules.
|
||||||
|
* Do not allow users to do that.
|
||||||
|
*/
|
||||||
if (o->result.cache_nr && empty_worktree) {
|
if (o->result.cache_nr && empty_worktree) {
|
||||||
/* dubious---why should this fail??? */
|
|
||||||
ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
|
ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче