chiark / gitweb /
dgit: gitattributes: Defuse working-tree-encoding
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 20 Jun 2018 13:10:02 +0000 (14:10 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 20 Jun 2018 13:29:38 +0000 (14:29 +0100)
* Add -working-tree-encoding to $negate_harmful_gitattrs.

* Add new arrangements for updating an existing dgit-defuse-attrs
  macro definition:
    - is_gitattrs: say whether the macro is up to date
    - setup_gitattrs: update an existing out-of-date macro
    - minor message changes
    - document the new behaviour

One consequence is that we have had to breach the promise about how to
stop future dgit setup-new-tree runs messing with this: it is now
necessary to disapply the macro, rather than redefine it.

Closes:#901900.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Debian/Dgit.pm
dgit
dgit.1

index 960f505aa1579036d27f3d7374b18d74490f6e37..aec5a23980ed0bb72450834df43840dd31aaf7d6 100644 (file)
@@ -101,7 +101,9 @@ sub NOCOMMITCHECK () { return 0x8; }
 our $debugprefix;
 our $debuglevel = 0;
 
-our $negate_harmful_gitattrs = "-text -eol -crlf -ident -filter";
+our $negate_harmful_gitattrs =
+    "-text -eol -crlf -ident -filter -working-tree-encoding";
+    # ^ when updating this, alter the regexp in dgit:is_gitattrs_setup
 
 our $forkcheck_mainprocess;
 
diff --git a/dgit b/dgit
index e7a6904151a842c9d5b7bf7b2afb3b48fdba4ce7..94f915efe5ab16836fbe1f9f36f4b2f4f46983f9 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -3396,15 +3396,23 @@ sub open_main_gitattrs () {
 our $gitattrs_ourmacro_re = qr{^\[attr\]dgit-defuse-attrs\s};
 
 sub is_gitattrs_setup () {
+    # return values:
+    #  trueish
+    #     1: gitattributes set up and should be left alone
+    #  falseish
+    #     0: there is a dgit-defuse-attrs but it needs fixing
+    #     undef: there is none
     my $gai = open_main_gitattrs();
     return 0 unless $gai;
     while (<$gai>) {
        next unless m{$gitattrs_ourmacro_re};
-       return 1;
+       return 1 if m{\s-working-tree-encoding\s};
+       printdebug "is_gitattrs_setup: found old macro\n";
+       return 0;
     }
     $gai->error and die $!;
     printdebug "is_gitattrs_setup: found nothing\n";
-    return 0;
+    return undef;
 }    
 
 sub setup_gitattrs (;$) {
@@ -3414,7 +3422,7 @@ sub setup_gitattrs (;$) {
     my $already = is_gitattrs_setup();
     if ($already) {
        progress <<END;
-[attr]dgit-defuse-attrs already found in .git/info/attributes
+[attr]dgit-defuse-attrs already found, and proper, in .git/info/attributes
  not doing further gitattributes setup
 END
        return;
@@ -3424,7 +3432,7 @@ END
     ensuredir "$maindir_gitcommon/info";
 
     open GAO, "> $af.new" or die $!;
-    print GAO <<END or die $!;
+    print GAO <<END or die $! unless defined $already;
 *      dgit-defuse-attrs
 $new
 # ^ see GITATTRIBUTES in dgit(7) and dgit setup-new-tree in dgit(1)
@@ -3432,6 +3440,10 @@ END
     my $gai = open_main_gitattrs();
     if ($gai) {
        while (<$gai>) {
+           if (m{$gitattrs_ourmacro_re}) {
+               die unless defined $already;
+               $_ = $new;
+           }
            chomp;
            print GAO $_, "\n" or die $!;
        }
@@ -3466,7 +3478,7 @@ sub check_gitattrs ($$) {
        # oh dear, found one
        print STDERR <<END;
 dgit: warning: $what contains .gitattributes
-dgit: .gitattributes have not been defused.  Recommended: dgit setup-new-tree.
+dgit: .gitattributes not (fully) defused.  Recommended: dgit setup-new-tree.
 END
        close $gafl;
        return;
diff --git a/dgit.1 b/dgit.1
index 56ba402fd72daa09685af2fc8541dcdf0218cf91..c5d76884871315a815cfa6f2dd6fbd24de8d8726 100644 (file)
--- a/dgit.1
+++ b/dgit.1
@@ -268,10 +268,19 @@ For why, see
 in
 .BR dgit(7) .
 
+If there is an existing macro attribute line
+.B [attr]dgit-defuse-attrs
+in .git/info/attributes,
+but it is insufficient,
+because it was made by an earlier version of dgit
+and git has since introduced new transforming attributes,
+modifies the macro to disable the newer transformations.
+
 (If there is already a macro attribute line
 .B [attr]dgit-defuse-attrs
 in .git/info/attributes
-(whatever its effects),
+which does what dgit requires
+(whatever files it effects),
 this operation does nothing further.
 This fact can be used to defeat or partially defeat
 dgit setup-gitattributes