gitattributes

Public
.gitattributes with typical Rails custom hunk-headers
Icons/chart bar
Used 26 times
Created by
V Viktor Schmidt

Usage
This file defines metadata for specific paths in a git repository. This metadata can be used by git and other tools to enhance their behavior. See the gitattributes documentation and linguist for more information.

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zamsP4"
Template Source

Review the code before running this template on your machine.

def print_green(heredoc)
  puts set_color heredoc, :green
end

def do_commit
  git :init
  git add: "."
  Bundler.with_unbundled_env { git commit: " -m 'Add .gitattributes' " }
end

say "\nAdding .gitattributes..."
create_file ".gitattributes", "\n" unless File.exist? ".gitattributes"
append_file ".gitattributes" do 
  <<~EOF 

  # line endings
  * text=auto eol=lf
  *.{cmd,[cC][mM][dD]} text eol=crlf
  *.{bat,[bB][aA][tT]} text eol=crlf
  
  # Excludes documentation files from your project's language stats.
  doc/* linguist-documentation

  *.html      diff=html
  *.css       diff=css
  *.scss      diff=css
  *.md        diff=markdown
  *.rb        diff=ruby
  *.rake      diff=ruby
  *.gemspec   diff=ruby

  # Make your credentials diff readable
  config/credentials/*.yml.enc diff=rails_credentials
  config/credentials.yml.enc diff=rails_credentials
  EOF
end

do_commit

print_green "\nAdded .gitattributes successfully!"
Comments

Sign up or Login to leave a comment.