[xen-tools-dev] [PATCH 04/13] Add a gitignore coherency test
Stéphane Jourdois
sjourdois at gmail.com
Sun Jul 18 18:22:59 CEST 2010
This tests helps to maintain .gitignore up to date, by :
- testing if all ignored files have to be ignored, and
- testing if all untracked files are ignored.
---
.gitignore | 5 ++---
t/gitignore.t | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 3 deletions(-)
create mode 100644 t/gitignore.t
diff --git a/.gitignore b/.gitignore
index 6c54293..d9bc9cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
-# Note! Please use 'git ls-files -i --exclude-standard'
-# command after changing this file, to see if there are
-# any tracked files which get ignored after the change.
+# Note! Please run 'prove t/gitignore.t' after changing
+# this file, to check its coherency
# all dotfiles
.*
diff --git a/t/gitignore.t b/t/gitignore.t
new file mode 100644
index 0000000..d7b8e34
--- /dev/null
+++ b/t/gitignore.t
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+#
+# Test that .gitignore is coherent
+#
+# Stéphane (kwisatz) Jourdois
+# --
+#
+
+use strict;
+use Test::More tests => 3;
+
+BEGIN { use_ok( 'Git' ); }
+
+
+# First, check that no tracked files are ignored
+my $cmd = Git::command_output_pipe('ls-files', '--ignored', '--exclude-standard');
+my $output;
+while (<$cmd>) { $output .= "--> $_" }
+close $cmd;
+
+ok(!defined $output, 'No tracked file is ignored')
+ or diag(<<EOF
+
+Check that the following tracked files _have_to_ be ignored, and then either :
+ - 'git rm' them
+ - modify .gitignore to not ignore them
+EOF
+ . $output . "\n");
+
+
+# Now, check that no untracked files are present
+$cmd = Git::command_output_pipe('status', '--porcelain');
+undef $output;
+while (<$cmd>) { $output .= "--> $_" if s/^\?\? // }
+close $cmd;
+
+ok(!defined $output, 'No untracked file is present')
+ or diag(<<EOF
+
+Check whether the following untracked files have to be ignored or
+tracked, and either :
+ - 'git add' them
+ - modify .gitignore to ignore them
+EOF
+ . $output . "\n");
--
1.7.1.1
More information about the xen-tools-dev
mailing list