[RFC/PATCH] Add test case for dealing with a tracked file in an ignored directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This test case attempts to match the behavior of 'git add ignore-file'
with 'git add ignore-dir/file' when .gitignore contains entries for
ignore-file and ignore-dir.
---
 t/t3700-add.sh |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

This patch is a follow-up to the thread '[RFC/PATCH] git-add: Don't
exclude explicitly-specified tracked files' at

  http://thread.gmane.org/gmane.comp.version-control.git/153194

In this patch, I propose the desired behavior of 'git add' for files
contained in ignored directories.  I have attempted to mirror the
behavior of 'git add' for ignored files, but I may have gotten that
wrong or that might not actually be what we want here.  Comments on
whether this is the desired behavior and whether these test-cases
accurate capture that behavior would be appreciated.

Thank you,

Greg

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index 7d7140d..97ba9e9 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -288,4 +288,34 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file' '
 	test_cmp expect.err actual.err
 '
 
+cat >expect <<EOF
+The following paths are ignored by one of your .gitignore files:
+ignored-dir
+Use -f if you really want to add them.
+fatal: no files added
+EOF
+
+test_expect_success 'git add with file in ignored directory' '
+	mkdir ignored-dir &&
+	echo ignored-dir >> .gitignore &&
+	touch ignored-dir/file &&
+	test_must_fail git add ignored-dir/file >actual 2>&1 &&
+	test_cmp actual expect &&
+	git add -f ignored-dir/file &&
+	git add ignored-dir/file &&
+	echo change > ignored-dir/file &&
+	git add ignored-dir/file &&
+	! ( git ls-files -m ignored-dir/file | grep ignored-dir/file )
+'
+
+test_expect_success 'git add with ignored directory using git globs' "
+	mkdir ignored-dir2 && echo ignored-dir2 >> .gitignore && touch ignored-dir2/file &&
+	git add 'ignored-dir2/*' >actual 2>&1 &&
+	echo \"fatal: pathspec 'ignored-dir2/*' did not match any files\" | test_cmp - actual
+	git add -f ignored-dir2/file && echo change > ignored-dir2/file &&
+	git add 'ignored-dir2/*' >actual 2>&1 &&
+	echo '' | test_cmp - actual &&
+	git ls-files -m ignored-dir2/file | grep ignored-dir2/file
+"
+
 test_done
-- 
1.7.2.1.68.g1ba78

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]