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 05/19] Teach Git to respect skip-worktree bit (writing part)
Date: Thu, 20 Aug 2009 20:46:59 +0700	[thread overview]
Message-ID: <1250776033-12395-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1250776033-12395-5-git-send-email-pclouds@gmail.com>

This part is mainly to remove CE_VALID shortcuts (and as a
consequence, ce_uptodate() shortcuts as it may be turned on by
CE_VALID) in writing code path if skip-worktree is used. Various tests
are added to avoid future breakages.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 t/t7012-skip-worktree-writing.sh |  146 ++++++++++++++++++++++++++++++++++++++
 unpack-trees.c                   |    4 +-
 2 files changed, 148 insertions(+), 2 deletions(-)
 create mode 100755 t/t7012-skip-worktree-writing.sh

diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh
new file mode 100755
index 0000000..8d8b1c0
--- /dev/null
+++ b/t/t7012-skip-worktree-writing.sh
@@ -0,0 +1,146 @@
+#!/bin/sh
+#
+# Copyright (c) 2008 Nguyễn Thái Ngọc Duy
+#
+
+test_description='test worktree writing operations when skip-worktree is used'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+	test_commit init &&
+	echo modified >> init.t &&
+	touch added &&
+	git add init.t added &&
+	git commit -m "modified and added" &&
+	git tag top
+'
+
+test_expect_success 'read-tree updates worktree, absent case' '
+	git checkout -f top &&
+	git update-index --skip-worktree init.t &&
+	rm init.t &&
+	git read-tree -m -u HEAD^ &&
+	echo init > expected &&
+	test_cmp expected init.t
+'
+
+test_expect_success 'read-tree updates worktree, dirty case' '
+	git checkout -f top &&
+	git update-index --skip-worktree init.t &&
+	echo dirty >> init.t &&
+	test_must_fail git read-tree -m -u HEAD^ &&
+	grep -q dirty init.t &&
+	test "$(git ls-files -t init.t)" = "S init.t" &&
+	git update-index --no-skip-worktree init.t
+'
+
+test_expect_success 'read-tree removes worktree, absent case' '
+	git checkout -f top &&
+	git update-index --skip-worktree added &&
+	rm added &&
+	git read-tree -m -u HEAD^ &&
+	test ! -f added
+'
+
+test_expect_success 'read-tree removes worktree, dirty case' '
+	git checkout -f top &&
+	git update-index --skip-worktree added &&
+	echo dirty >> added &&
+	test_must_fail git read-tree -m -u HEAD^ &&
+	grep -q dirty added &&
+	test "$(git ls-files -t added)" = "S added" &&
+	git update-index --no-skip-worktree added
+'
+
+NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
+ZERO_SHA0=0000000000000000000000000000000000000000
+setup_absent() {
+	test -f 1 && rm 1
+	git update-index --remove 1 &&
+	git update-index --add --cacheinfo 100644 $NULL_SHA1 1 &&
+	git update-index --skip-worktree 1
+}
+
+test_absent() {
+	echo "100644 $NULL_SHA1 0	1" > expected &&
+	git ls-files --stage 1 > result &&
+	test_cmp expected result &&
+	test ! -f 1
+}
+
+setup_dirty() {
+	git update-index --force-remove 1 &&
+	echo dirty > 1 &&
+	git update-index --add --cacheinfo 100644 $NULL_SHA1 1 &&
+	git update-index --skip-worktree 1
+}
+
+test_dirty() {
+	echo "100644 $NULL_SHA1 0	1" > expected &&
+	git ls-files --stage 1 > result &&
+	test_cmp expected result &&
+	echo dirty > expected
+	test_cmp expected 1
+}
+
+cat >expected <<EOF
+S 1
+H 2
+H init.t
+S sub/1
+H sub/2
+EOF
+
+test_expect_success 'index setup' '
+	git checkout -f init &&
+	mkdir sub &&
+	touch ./1 ./2 sub/1 sub/2 &&
+	git add 1 2 sub/1 sub/2 &&
+	git update-index --skip-worktree 1 sub/1 &&
+	git ls-files -t > result &&
+	test_cmp expected result
+'
+
+test_expect_success 'git-add ignores worktree content' '
+	setup_absent &&
+	git add 1 &&
+	test_absent
+'
+
+test_expect_success 'git-add ignores worktree content' '
+	setup_dirty &&
+	git add 1 &&
+	test_dirty
+'
+
+test_expect_success 'git-rm fails if worktree is dirty' '
+	setup_dirty &&
+	test_must_fail git rm 1 &&
+	test_dirty
+'
+
+cat >expected <<EOF
+Would remove expected
+Would remove result
+EOF
+test_expect_success 'git-clean, absent case' '
+	setup_absent &&
+	git clean -n > result &&
+	test_cmp expected result
+'
+
+test_expect_success 'git-clean, dirty case' '
+	setup_dirty &&
+	git clean -n > result &&
+	test_cmp expected result
+'
+
+test_expect_failure 'git-apply adds file' false
+test_expect_failure 'git-apply updates file' false
+test_expect_failure 'git-apply removes file' false
+test_expect_failure 'git-mv to skip-worktree' false
+test_expect_failure 'git-mv from skip-worktree' false
+test_expect_failure 'git-checkout' false
+
+test_done
diff --git a/unpack-trees.c b/unpack-trees.c
index 720f7a1..3eda263 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -450,7 +450,7 @@ static int verify_uptodate(struct cache_entry *ce,
 {
 	struct stat st;
 
-	if (o->index_only || o->reset || ce_uptodate(ce))
+	if (o->index_only || (!ce_skip_worktree(ce) && (o->reset || ce_uptodate(ce))))
 		return 0;
 
 	if (!lstat(ce->name, &st)) {
@@ -1004,7 +1004,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
 
 	if (old && same(old, a)) {
 		int update = 0;
-		if (o->reset && !ce_uptodate(old)) {
+		if (o->reset && !ce_uptodate(old) && !ce_skip_worktree(old)) {
 			struct stat st;
 			if (lstat(old->name, &st) ||
 			    ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID))
-- 
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         ` Nguyễn Thái Ngọc Duy [this message]
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                                     ` [RFC PATCH v4 19/19] sparse checkout: inhibit empty worktree Nguyễn Thái Ngọc Duy
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-6-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).