chiark / gitweb /
gitattributes: Issue a warning on un-defused .gitattributes
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 16 Jan 2017 01:11:51 +0000 (01:11 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 16 Jan 2017 01:25:19 +0000 (01:25 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit
dgit.7

diff --git a/dgit b/dgit
index be11a49802720fe06df4bfd3c7992752aa0c5ec4..3d81558fc21bc1044ddc50684a1ff8ea058724e8 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -144,6 +144,7 @@ our %opts_cfg_insertpos = map {
 
 sub parseopts_late_defaults();
 sub setup_gitattrs(;$);
 
 sub parseopts_late_defaults();
 sub setup_gitattrs(;$);
+sub check_gitattrs($$);
 
 our $keyid;
 
 
 our $keyid;
 
@@ -3256,6 +3257,8 @@ END
 
     lrfetchref_used lrfetchref();
 
 
     lrfetchref_used lrfetchref();
 
+    check_gitattrs($hash, "fetched source tree");
+
     unshift @end, $del_lrfetchrefs;
     return $hash;
 }
     unshift @end, $del_lrfetchrefs;
     return $hash;
 }
@@ -3370,6 +3373,35 @@ sub setup_new_tree () {
     setup_gitattrs();
 }
 
     setup_gitattrs();
 }
 
+sub check_gitattrs ($$) {
+    my ($treeish, $what) = @_;
+
+    return if is_gitattrs_setup;
+
+    local $/="\0";
+    my @cmd = (@git, qw(ls-tree -lrz --), "${treeish}:");
+    debugcmd "|",@cmd;
+    my $gafl = new IO::File;
+    open $gafl, "-|", @cmd or die $!;
+    while (<$gafl>) {
+       chomp or die;
+       s/^\d+\s+\w+\s+\w+\s+(\d+)\t// or die;
+       next if $1 == 0;
+       next unless m{(?:^|/)\.gitattributes$};
+
+       # oh dear, found one
+       print STDERR <<END;
+dgit: warning: $what contains .gitattributes
+dgit: .gitattributes have not been defused.  See GITATTRIBUTES in dgit(7).
+END
+       close $gafl;
+       return;
+    }
+    # tree contains no .gitattributes files
+    $?=0; $!=0; close $gafl or failedcmd @cmd;
+}
+
+
 sub multisuite_suite_child ($$$) {
     my ($tsuite, $merginputs, $fn) = @_;
     # in child, sets things up, calls $fn->(), and returns undef
 sub multisuite_suite_child ($$$) {
     my ($tsuite, $merginputs, $fn) = @_;
     # in child, sets things up, calls $fn->(), and returns undef
@@ -6103,6 +6135,8 @@ sub import_dsc_result {
     my ($dstref, $newhash, $what_log, $what_msg) = @_;
     my @cmd = (@git, qw(update-ref -m), $what_log, $dstref, $newhash);
     runcmd @cmd;
     my ($dstref, $newhash, $what_log, $what_msg) = @_;
     my @cmd = (@git, qw(update-ref -m), $what_log, $dstref, $newhash);
     runcmd @cmd;
+    check_gitattrs($newhash, "source tree");
+
     progress "dgit: import-dsc: $what_msg";
 }
 
     progress "dgit: import-dsc: $what_msg";
 }
 
diff --git a/dgit.7 b/dgit.7
index acc7cc1a36d71f3dfc67b740ff3aa31a4e1663f2..09bb8f4424f9d235e8ca115b61c593980bfd93ae 100644 (file)
--- a/dgit.7
+++ b/dgit.7
@@ -227,6 +227,16 @@ and dgit setup-new-tree
 disable transforming gitattributes
 by default,
 by creating a .git/info/attributes.
 disable transforming gitattributes
 by default,
 by creating a .git/info/attributes.
+When fetching or importing sources
+dgit warns if it finds .gitattributes file
+and the transforming gitattributes have not been defused
+(e.g. in the case of a tree not made with dgit clone).
+
+See
+.B dgit setup-new-tree
+and
+.B dgit setup-gitattributes
+in dgit(1).
 .SH PACKAGE SOURCE FORMATS
 If you are not the maintainer, you do not need to worry about the
 source format of the package.  You can just make changes as you like
 .SH PACKAGE SOURCE FORMATS
 If you are not the maintainer, you do not need to worry about the
 source format of the package.  You can just make changes as you like