summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2017-01-16 01:04:25 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2017-01-16 01:13:58 +0000
commita4e7ac2715ea7077ccedb190a783c64c06a9c539 (patch)
tree1097dfbe186d10fe8ddd8f9a2c435eedc61391c5
parentafe62f515927bdedb8bd0b9cb5fe3230b3ae28c0 (diff)
dgit: gitattributes: Provide setup_gitattrs (internal function)
This is the idempotent function which adds the appropriate runes to .git/info/attributes. No callers yet. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
-rwxr-xr-xdgit48
1 files changed, 48 insertions, 0 deletions
diff --git a/dgit b/dgit
index dbfe1ac..ede7010 100755
--- a/dgit
+++ b/dgit
@@ -143,6 +143,7 @@ our %opts_cfg_insertpos = map {
} keys %opts_opt_map;
sub parseopts_late_defaults();
+sub setup_gitattrs(;$);
our $keyid;
@@ -3315,6 +3316,53 @@ sub ensure_setup_existing_tree () {
set_local_git_config $k, 'true';
}
+sub open_gitattrs () {
+ my $gai = new IO::File ".git/info/attributes"
+ or $!==ENOENT
+ or die "open .git/info/attributes: $!";
+ return $gai;
+}
+
+sub is_gitattrs_setup () {
+ my $gai = open_gitattrs();
+ return 0 unless $gai;
+ while (<$gai>) {
+ return 1 if m{^\[attr\]dgit-defuse-attrs\s};
+ }
+ $gai->error and die $!;
+ return 0;
+}
+
+sub setup_gitattrs (;$) {
+ my ($always) = @_;
+ return unless $always || access_cfg_bool(1, 'setup-gitattributes');
+
+ if (is_gitattrs_setup()) {
+ progress <<END;
+[attr]dgit-defuse-attrs already found in .git/info/attributes
+ not doing further gitattributes setup
+END
+ return;
+ }
+ my $af = ".git/info/attributes";
+ open GAO, "> $af.new" or die $!;
+ print GAO <<END or die $!;
+* dgit-defuse-attrs
+[attr]dgit-defuse-attrs -text -eol -crlf -ident -filter
+# ^ see dgit(7). To undo, leave a definition of [attr]dgit-defuse-attrs
+END
+ my $gai = open_gitattrs();
+ if ($gai) {
+ while (<$gai>) {
+ chomp;
+ print GAO $_, "\n" or die $!;
+ }
+ $gai->error and die $!;
+ }
+ close GAO or die $!;
+ rename "$af.new", "$af" or die "install $af: $!";
+}
+
sub setup_new_tree () {
setup_mergechangelogs();
setup_useremail();