* Re: [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails [not found] <1316602259-22576-1-git-send-email-pclouds@gmail.com> @ 2011-09-21 19:15 ` Joshua Jensen 2011-09-21 20:50 ` Junio C Hamano 1 sibling, 0 replies; 5+ messages in thread From: Joshua Jensen @ 2011-09-21 19:15 UTC (permalink / raw) To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano, git ----- Original Message ----- From: Nguyễn Thái Ngọc Duy Date: 9/21/2011 4:50 AM > if (ce->ce_flags& CE_ADDED&& > verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) > - return -1; > + goto return_failed; > > - if (apply_sparse_checkout(ce, o)) { > - ret = -1; > - goto done; > - } > + if (apply_sparse_checkout(ce, o)) > + goto return_failed; > if (!ce_skip_worktree(ce)) > empty_worktree = 0; Unfortunately, this patch only collects and displays the first untracked file for me. It does not display all of the files that would be overwritten (desired behavior, IMHO). This script illustrates: #!/bin/sh rm -Rf utest || exit 1 mkdir utest || exit 1 cd utest || exit 1 git init git config core.sparseCheckout true echo *>.git/info/sparse-checkout echo tracked>a git add a git commit -m a a git branch side echo tracked>b echo tracked>c git add b c git commit -m bc cat b git checkout side cat b echo untracked>b echo untracked>c cat b git checkout master cat b -Josh ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails [not found] <1316602259-22576-1-git-send-email-pclouds@gmail.com> 2011-09-21 19:15 ` [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails Joshua Jensen @ 2011-09-21 20:50 ` Junio C Hamano 2011-09-22 11:24 ` [PATCH v2 " Nguyễn Thái Ngọc Duy 2011-09-22 11:24 ` [PATCH v2 2/2] Add explanation why we do not allow to sparse checkout to empty working tree Nguyễn Thái Ngọc Duy 1 sibling, 2 replies; 5+ messages in thread From: Junio C Hamano @ 2011-09-21 20:50 UTC (permalink / raw) To: Nguyễn Thái Ngọc Duy Cc: git, Michael, J, Gruber, git, Joshua Jensen Please add a test when you reroll this, hopefully with help from Joshua. Thanks. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] sparse checkout: show error messages when worktree shaping fails 2011-09-21 20:50 ` Junio C Hamano @ 2011-09-22 11:24 ` Nguyễn Thái Ngọc Duy 2011-09-22 19:57 ` Joshua Jensen 2011-09-22 11:24 ` [PATCH v2 2/2] Add explanation why we do not allow to sparse checkout to empty working tree Nguyễn Thái Ngọc Duy 1 sibling, 1 reply; 5+ messages in thread From: Nguyễn Thái Ngọc Duy @ 2011-09-22 11:24 UTC (permalink / raw) To: git, Junio C Hamano Cc: Michael J Gruber, Joshua Jensen, Nguyễn Thái Ngọc Duy verify_* functions can queue errors up and to be printed later at label return_failed. In case of errors, do not go to label "done" directly because all queued messages would be dropped on the floor. Found-by: Joshua Jensen <jjensen@workspacewhiz.com> Tracked-down-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- Now print all errors. t/t1011-read-tree-sparse-checkout.sh | 15 +++++++++++++++ unpack-trees.c | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index 018c354..efcd8ab 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -234,4 +234,19 @@ test_expect_success 'read-tree --reset removes outside worktree' ' 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. +EOF + test_cmp expected actual +' + test_done diff --git a/unpack-trees.c b/unpack-trees.c index cc616c3..fcf40a0 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1089,6 +1089,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); + ret = 0; for (i = 0; i < o->result.cache_nr; i++) { struct cache_entry *ce = o->result.cache[i]; @@ -1101,17 +1102,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options * correct CE_NEW_SKIP_WORKTREE */ if (ce->ce_flags & CE_ADDED && - verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) - return -1; + verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) { + if (!o->show_all_errors) + goto return_failed; + ret = -1; + } if (apply_sparse_checkout(ce, o)) { + if (!o->show_all_errors) + goto return_failed; ret = -1; - goto done; } if (!ce_skip_worktree(ce)) empty_worktree = 0; } + if (ret < 0) + goto return_failed; if (o->result.cache_nr && empty_worktree) { /* dubious---why should this fail??? */ ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory"); -- 1.7.3.1.256.g2539c.dirty ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] sparse checkout: show error messages when worktree shaping fails 2011-09-22 11:24 ` [PATCH v2 " Nguyễn Thái Ngọc Duy @ 2011-09-22 19:57 ` Joshua Jensen 0 siblings, 0 replies; 5+ messages in thread From: Joshua Jensen @ 2011-09-22 19:57 UTC (permalink / raw) To: Nguyễn Thái Ngọc Duy Cc: git, Junio C Hamano, Michael J Gruber ----- Original Message ----- From: Nguyễn Thái Ngọc Duy Date: 9/22/2011 5:24 AM > diff --git a/unpack-trees.c b/unpack-trees.c > index cc616c3..fcf40a0 100644 > --- a/unpack-trees.c > +++ b/unpack-trees.c > @@ -1089,6 +1089,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); > > + ret = 0; > for (i = 0; i< o->result.cache_nr; i++) { > struct cache_entry *ce = o->result.cache[i]; > > @@ -1101,17 +1102,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options > * correct CE_NEW_SKIP_WORKTREE > */ > if (ce->ce_flags& CE_ADDED&& > - verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) > - return -1; > + verify_absent(ce, ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN, o)) { > + if (!o->show_all_errors) > + goto return_failed; > + ret = -1; > + } > > if (apply_sparse_checkout(ce, o)) { > + if (!o->show_all_errors) > + goto return_failed; > ret = -1; > - goto done; > } > if (!ce_skip_worktree(ce)) > empty_worktree = 0; > > } > + if (ret< 0) > + goto return_failed; > if (o->result.cache_nr&& empty_worktree) { > /* dubious---why should this fail??? */ > ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory"); I can confirm that this version of the patch works for me with multiple untracked files in a sparse checkout. -Josh ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] Add explanation why we do not allow to sparse checkout to empty working tree 2011-09-21 20:50 ` Junio C Hamano 2011-09-22 11:24 ` [PATCH v2 " Nguyễn Thái Ngọc Duy @ 2011-09-22 11:24 ` Nguyễn Thái Ngọc Duy 1 sibling, 0 replies; 5+ messages in thread From: Nguyễn Thái Ngọc Duy @ 2011-09-22 11:24 UTC (permalink / raw) To: git, Junio C Hamano Cc: Michael J Gruber, Joshua Jensen, Nguyễn Thái Ngọc Duy Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- unpack-trees.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index fcf40a0..bacb473 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1119,8 +1119,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } 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) { - /* dubious---why should this fail??? */ ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory"); goto done; } -- 1.7.3.1.256.g2539c.dirty ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-09-22 19:56 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <1316602259-22576-1-git-send-email-pclouds@gmail.com> 2011-09-21 19:15 ` [PATCH 1/2] sparse checkout: show error messages when worktree shaping fails Joshua Jensen 2011-09-21 20:50 ` Junio C Hamano 2011-09-22 11:24 ` [PATCH v2 " Nguyễn Thái Ngọc Duy 2011-09-22 19:57 ` Joshua Jensen 2011-09-22 11:24 ` [PATCH v2 2/2] Add explanation why we do not allow to sparse checkout to empty working tree Nguyễn Thái Ngọc Duy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).