git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Christian Couder <chriscool@tuxfamily.org>
Subject: [PATCH 1/3] Add corner case tests for diff-index and diff-files
Date: Sun, 30 Mar 2008 17:28:05 -0700	[thread overview]
Message-ID: <7vzlsfu48a.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 7v4panyduy.fsf@gitster.siamese.dyndns.org

diff-index and diff-files can get confused in corner cases when an indexed
blob turns into something else in the work tree.  This patch adds tests to
expose such breakages.

The test is classified under t2XXX series instead of t4XXX series, because
the ultimate objective is to fix "add -u" (and "commit -a" that shares the
same issue).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t2201-add-update-typechange.sh |  140 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100755 t/t2201-add-update-typechange.sh

diff --git a/t/t2201-add-update-typechange.sh b/t/t2201-add-update-typechange.sh
new file mode 100755
index 0000000..75c440c
--- /dev/null
+++ b/t/t2201-add-update-typechange.sh
@@ -0,0 +1,140 @@
+#!/bin/sh
+
+test_description='more git add -u'
+
+. ./test-lib.sh
+
+_z40=0000000000000000000000000000000000000000
+
+test_expect_success setup '
+	>xyzzy &&
+	_empty=$(git hash-object --stdin <xyzzy) &&
+	>yomin &&
+	>caskly &&
+	ln -s frotz nitfol &&
+	mkdir rezrov &&
+	>rezrov/bozbar &&
+	git add caskly xyzzy yomin nitfol rezrov/bozbar &&
+
+	test_tick &&
+	git commit -m initial
+
+'
+
+test_expect_success modify '
+	rm -f xyzzy yomin nitfol caskly &&
+	# caskly disappears (not a submodule)
+	mkdir caskly &&
+	# nitfol changes from symlink to regular
+	>nitfol &&
+	# rezrov/bozbar disappears
+	rm -fr rezrov &&
+	ln -s xyzzy rezrov &&
+	# xyzzy disappears (not a submodule)
+	mkdir xyzzy &&
+	echo gnusto >xyzzy/bozbar &&
+	# yomin gets replaced with a submodule
+	mkdir yomin &&
+	>yomin/yomin &&
+	(
+		cd yomin &&
+		git init &&
+		git add yomin &&
+		git commit -m "sub initial"
+	) &&
+	yomin=$(GIT_DIR=yomin/.git git rev-parse HEAD) &&
+	# yonk is added and then turned into a submodule
+	# this should appear as T in diff-files and as A in diff-index
+	>yonk &&
+	git add yonk &&
+	rm -f yonk &&
+	mkdir yonk &&
+	>yonk/yonk &&
+	(
+		cd yonk &&
+		git init &&
+		git add yonk &&
+		git commit -m "sub initial"
+	) &&
+	yonk=$(GIT_DIR=yonk/.git git rev-parse HEAD) &&
+	# zifmia is added and then removed
+	# this should appear in diff-files but not in diff-index.
+	>zifmia &&
+	git add zifmia &&
+	rm -f zifmia &&
+	mkdir zifmia &&
+	{
+		git ls-tree -r HEAD |
+		sed -e "s/^/:/" -e "
+			/	caskly/{
+				s/	caskly/ $_z40 D&/
+				s/blob/000000/
+			}
+			/	nitfol/{
+				s/	nitfol/ $_z40 T&/
+				s/blob/100644/
+			}
+			/	rezrov.bozbar/{
+				s/	rezrov.bozbar/ $_z40 D&/
+				s/blob/000000/
+			}
+			/	xyzzy/{
+				s/	xyzzy/ $_z40 D&/
+				s/blob/000000/
+			}
+			/	yomin/{
+			    s/	yomin/ $_z40 T&/
+				s/blob/160000/
+			}
+		"
+	} >expect &&
+	{
+		cat expect
+		echo ":100644 160000 $_empty $_z40 T	yonk"
+		echo ":100644 000000 $_empty $_z40 D	zifmia"
+	} >expect-files &&
+	{
+		cat expect
+		echo ":000000 160000 $_z40 $_z40 A	yonk"
+	} >expect-index &&
+	{
+		echo "100644 $_empty 0	nitfol"
+		echo "160000 $yomin 0	yomin"
+		echo "160000 $yonk 0	yonk"
+	} >expect-final
+'
+
+test_expect_failure diff-files '
+	git diff-files --raw >actual &&
+	diff -u expect-files actual
+'
+
+test_expect_failure diff-index '
+	git diff-index --raw HEAD -- >actual &&
+	diff -u expect-index actual
+'
+
+test_expect_failure 'add -u' '
+	rm -f ".git/saved-index" &&
+	cp -p ".git/index" ".git/saved-index" &&
+	git add -u &&
+	git ls-files -s >actual &&
+	diff -u expect-final actual
+'
+
+test_expect_failure 'commit -a' '
+	if test -f ".git/saved-index"
+	then
+		rm -f ".git/index" &&
+		mv ".git/saved-index" ".git/index"
+	fi &&
+	git commit -m "second" -a &&
+	git ls-files -s >actual &&
+	diff -u expect-final actual &&
+	rm -f .git/index &&
+	git read-tree HEAD &&
+	git ls-files -s >actual &&
+	diff -u expect-final actual
+'
+
+test_done
-- 
1.5.5.rc2.131.g3d2f0

  reply	other threads:[~2008-03-31  0:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-29  7:13 Possible d/f conflict bug or regression Christian Couder
2008-03-29  8:01 ` Christian Couder
2008-03-30  1:29 ` Bryan Donlan
2008-03-30  4:44   ` Christian Couder
2008-03-30  4:51     ` Bryan Donlan
2008-03-30 23:46 ` Junio C Hamano
2008-03-31  0:28   ` Junio C Hamano [this message]
2008-03-31  0:29   ` [PATCH 2/3] diff-index: careful when inspecting work tree items Junio C Hamano
2008-03-31  3:12     ` Junio C Hamano
2008-03-31  3:47       ` Christian Couder
2008-03-31  0:30   ` [PATCH 3/3] diff-files: " Junio C Hamano

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=7vzlsfu48a.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=chriscool@tuxfamily.org \
    --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).