git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [RFC PATCH v4 19/19] sparse checkout: inhibit empty worktree
Date: Thu, 20 Aug 2009 20:47:13 +0700	[thread overview]
Message-ID: <1250776033-12395-20-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1250776033-12395-19-git-send-email-pclouds@gmail.com>

The way sparse checkout works, users may empty their worktree
completely, because of non-matching sparse-checkout spec, or empty
spec. I believe this is not desired. This patch makes Git refuse to
produce such worktree.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 t/t1009-read-tree-sparse-checkout.sh |   10 +++-------
 unpack-trees.c                       |    7 +++++++
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/t/t1009-read-tree-sparse-checkout.sh b/t/t1009-read-tree-sparse-checkout.sh
index 2192f5a..62246db 100755
--- a/t/t1009-read-tree-sparse-checkout.sh
+++ b/t/t1009-read-tree-sparse-checkout.sh
@@ -55,20 +55,16 @@ test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-
 	test -f sub/added
 '
 
-cat >expected.swt <<EOF
-S init.t
-S sub/added
-EOF
 test_expect_success 'read-tree with empty .git/info/sparse-checkout' '
 	git config core.sparsecheckout true &&
 	echo > .git/info/sparse-checkout &&
-	git read-tree -m -u HEAD &&
+	test_must_fail git read-tree -m -u HEAD &&
 	git ls-files --stage > result &&
 	test_cmp expected result &&
 	git ls-files -t > result &&
 	test_cmp expected.swt result &&
-	test ! -f init.t &&
-	test ! -f sub/added
+	test -f init.t &&
+	test -f sub/added
 '
 
 cat >expected.swt <<EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 72743b3..80ae2a0 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -498,6 +498,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 	}
 
 	if (!o->skip_sparse_checkout) {
+		int empty_worktree = 1;
 		for (i = 0;i < o->result.cache_nr;i++) {
 			struct cache_entry *ce = o->result.cache[i];
 
@@ -512,8 +513,14 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			 */
 			if (ce_skip_worktree(ce))
 				ce->ce_flags &= ~(CE_UPDATE | CE_REMOVE);
+			else
+				empty_worktree = 0;
 
 		}
+		if (o->result.cache_nr && empty_worktree) {
+			ret = unpack_failed(o, "Sparse checkout leaves no entry on working directory");
+			goto done;
+		}
 	}
 
 	o->src_index = NULL;
-- 
1.6.3.GIT

  reply	other threads:[~2009-08-20 13:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-20 13:46 [RFC PATCH v4 00/19] Sparse checkout Nguyễn Thái Ngọc Duy
2009-08-20 13:46 ` [RFC PATCH v4 01/19] update-index: refactor mark_valid() in preparation for new options Nguyễn Thái Ngọc Duy
2009-08-20 13:46   ` [RFC PATCH v4 02/19] Add test-index-version Nguyễn Thái Ngọc Duy
2009-08-20 13:46     ` [RFC PATCH v4 03/19] Introduce "skip-worktree" bit in index, teach Git to get/set this bit Nguyễn Thái Ngọc Duy
2009-08-20 13:46       ` [RFC PATCH v4 04/19] Teach Git to respect skip-worktree bit (reading part) Nguyễn Thái Ngọc Duy
2009-08-20 13:46         ` [RFC PATCH v4 05/19] Teach Git to respect skip-worktree bit (writing part) Nguyễn Thái Ngọc Duy
2009-08-20 13:47           ` [RFC PATCH v4 06/19] Avoid writing to buffer in add_excludes_from_file_1() Nguyễn Thái Ngọc Duy
2009-08-20 13:47             ` [RFC PATCH v4 07/19] Read .gitignore from index if it is skip-worktree Nguyễn Thái Ngọc Duy
2009-08-20 13:47               ` [RFC PATCH v4 08/19] unpack-trees(): carry skip-worktree bit over in merged_entry() Nguyễn Thái Ngọc Duy
2009-08-20 13:47                 ` [RFC PATCH v4 09/19] excluded_1(): support exclude files in index Nguyễn Thái Ngọc Duy
2009-08-20 13:47                   ` [RFC PATCH v4 10/19] dir.c: export excluded_1() and add_excludes_from_file_1() Nguyễn Thái Ngọc Duy
2009-08-20 13:47                     ` [RFC PATCH v4 11/19] Introduce "sparse checkout" Nguyễn Thái Ngọc Duy
2009-08-20 13:47                       ` [RFC PATCH v4 12/19] unpack-trees(): add CE_WT_REMOVE to remove on worktree alone Nguyễn Thái Ngọc Duy
2009-08-20 13:47                         ` [RFC PATCH v4 13/19] unpack-trees.c: generalize verify_* functions Nguyễn Thái Ngọc Duy
2009-08-20 13:47                           ` [RFC PATCH v4 14/19] unpack-trees(): "enable" sparse checkout and load $GIT_DIR/info/sparse-checkout Nguyễn Thái Ngọc Duy
2009-08-20 13:47                             ` [RFC PATCH v4 15/19] unpack_trees(): apply $GIT_DIR/info/sparse-checkout to the final index Nguyễn Thái Ngọc Duy
2009-08-20 13:47                               ` [RFC PATCH v4 16/19] unpack-trees(): ignore worktree check outside checkout area Nguyễn Thái Ngọc Duy
2009-08-20 13:47                                 ` [RFC PATCH v4 17/19] read-tree: add --no-sparse-checkout to disable sparse checkout support Nguyễn Thái Ngọc Duy
2009-08-20 13:47                                   ` [RFC PATCH v4 18/19] Add tests for sparse checkout Nguyễn Thái Ngọc Duy
2009-08-20 13:47                                     ` Nguyễn Thái Ngọc Duy [this message]
2009-08-21  9:19         ` [RFC PATCH v4 04/19] Teach Git to respect skip-worktree bit (reading part) Nguyen Thai Ngoc Duy
2009-08-21 17:32           ` Junio C Hamano
2009-08-22 11:56             ` Nguyen Thai Ngoc Duy
2009-08-20 15:21 ` [RFC PATCH v4 00/19] Sparse checkout Jakub Narebski
2009-08-20 15:31   ` Matthieu Moy
2009-08-21  7:50 ` Junio C Hamano
2009-08-21  9:15   ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1250776033-12395-20-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).