From: Johannes Sixt <j.sixt@viscovery.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Hedberg <tmhedberg@gmail.com>,
Bertrand BENOIT <projettwk@users.sourceforge.net>,
git@vger.kernel.org
Subject: [PATCH] Add test that checkout does not overwrite entries in .git/info/exclude
Date: Mon, 21 Nov 2011 08:23:45 +0100 [thread overview]
Message-ID: <4EC9FC81.3080306@viscovery.net> (raw)
In-Reply-To: <7vzkfqgn91.fsf@alter.siamese.dyndns.org>
From: Johannes Sixt <j6t@kdbg.org>
It is an unintended accident that entries matched by .git/info/exclude are
considered precious, but entries matched by .gitignore are not. That is,
'git checkout' will overwrite untracked files matched by .gitignore, but
refuses to overwrite files matched by .git/info/exclude.
It is a lucky accident: it allows the distinction between "untracked but
precious" and "untracked and garbage". And it is a doubly lucky accident:
.gitignore entries are meant for files like build products, which usually
affect all consumers of a repository, whereas .git/info/exclude is
intended for personal files, which frequently are precious (think of a
TODO file).
Add a test that codifies the accident as wanted behavior.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
Am 11/21/2011 4:36, schrieb Junio C Hamano:
> As far as I am aware, info/exclude should work exactly the same as having
> a .gitignore file at the root level of the working tree. Can you show a
> minimum reproduction recipe in a form of a patch to our test scripts in t/
> hierarchy?
Here you are. As you can see from my commit message, IMO, this is
a very useful accident. Therefore, there is no 'test_expect_failure'
in the test script :-)
-- Hannes
t/t2023-checkout-ignored.sh | 51 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
create mode 100755 t/t2023-checkout-ignored.sh
diff --git a/t/t2023-checkout-ignored.sh b/t/t2023-checkout-ignored.sh
new file mode 100755
index 0000000..03a5a56
--- /dev/null
+++ b/t/t2023-checkout-ignored.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+test_description='checkout overwrites or preserves ignored files
+
+`git checkout` makes a distinction between files mentioned in
+.gitignore and .git/info/exclude in that untracked files matched
+by the latter are considered precious and are not overwritten.
+'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+ echo excluded > excluded &&
+ echo ignored > ignored &&
+ git add . &&
+ test_commit initial &&
+ git checkout -b side &&
+ git rm excluded &&
+ git mv ignored .gitignore &&
+ test_commit side &&
+ echo excluded >> .git/info/exclude
+'
+
+test_expect_success 'files are ignored' '
+
+ echo keep > excluded &&
+ echo overwrite > ignored &&
+ list=$(git ls-files --others --exclude-standard) &&
+ test -z "$list"
+'
+
+test_expect_success 'entries in .git/info/exclude are precious' '
+
+ test_must_fail git checkout master 2>errors &&
+ test_i18ngrep "would be overwritten" errors &&
+ grep " excluded" errors &&
+ ! grep " ignored" errors &&
+ grep keep excluded &&
+ grep overwrite ignored
+'
+
+test_expect_success 'entries in .gitignore are not precious' '
+
+ rm -f excluded &&
+ git checkout master &&
+ grep excluded excluded &&
+ grep ignored ignored
+'
+
+test_done
--
1.7.8.rc0.126.gd15506
next prev parent reply other threads:[~2011-11-21 7:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-20 13:42 Bug report - local (and git ignored) file silently removed after checkout Bertrand BENOIT
2011-11-20 21:16 ` Junio C Hamano
2011-11-20 22:19 ` Taylor Hedberg
2011-11-21 3:36 ` Junio C Hamano
2011-11-21 7:23 ` Johannes Sixt [this message]
2011-11-21 7:45 ` [PATCH] Add test that checkout does not overwrite entries in .git/info/exclude Philip Oakley
2011-11-21 7:59 ` Junio C Hamano
2011-11-21 7:50 ` Junio C Hamano
2011-11-21 8:52 ` Nguyen Thai Ngoc Duy
2011-11-21 17:27 ` Junio C Hamano
2011-11-23 11:31 ` Nguyen Thai Ngoc Duy
2011-11-21 8:17 ` Nguyen Thai Ngoc Duy
2011-11-21 15:18 ` Junio C Hamano
2011-11-21 15:44 ` Bertrand BENOIT
2011-11-23 11:40 ` Nguyen Thai Ngoc Duy
2011-11-23 17:16 ` Junio C Hamano
2011-11-24 1:35 ` Nguyen Thai Ngoc Duy
2011-11-24 5:17 ` Junio C Hamano
2011-11-24 5:39 ` Nguyen Thai Ngoc Duy
2011-11-27 10:13 ` Nguyen Thai Ngoc Duy
2011-11-27 10:15 ` [PATCH 1/2] checkout,merge: loosen overwriting untracked file check based on info/exclude Nguyễn Thái Ngọc Duy
2011-11-27 10:15 ` [PATCH 2/2] checkout,merge: disallow overwriting ignored files with --no-overwrite-ignore Nguyễn Thái Ngọc Duy
2011-11-29 18:17 ` [PATCH 1/2] checkout,merge: loosen overwriting untracked file check based on info/exclude 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=4EC9FC81.3080306@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=projettwk@users.sourceforge.net \
--cc=tmhedberg@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.