diff options
Diffstat (limited to 'dgit')
-rwxr-xr-x | dgit | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -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(); |