Skip to content

Commit

Permalink
Git: Add custom merge driver for Rails db/schema.rb
Browse files Browse the repository at this point in the history
The Rails schema file is notorious for causing merge conflicts, as the order
of some of the lines seems to change randomly. This custom merge driver will
be applied to only Rails schema files, and should prevent merge conflicts.

As suggested by https://nuclearsquid.com/writings/git-tricks-tips-workflows/.
  • Loading branch information
booch committed Aug 17, 2017
1 parent 1df6deb commit 185f9ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
db/schema.rb merge=railsschema
10 changes: 10 additions & 0 deletions gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
[merge]
tool = opendiff
summary = true
[merge "railsschema"]
name = newer Rails schema version
driver = "ruby -e '\n\
system %(git), %(merge-file), %(--marker-size=%L), %(%A), %(%O), %(%B)\n\
b = File.read(%(%A))\n\
b.sub!(/^<+ .*\\nActiveRecord::Schema\\.define.:version => (\\d+). do\\n=+\\nActiveRecord::Schema\\.define.:version => (\\d+). do\\n>+ .*/) do\n\
%(ActiveRecord::Schema.define(:version => #{[$1, $2].max}) do)\n\
end\n\
File.open(%(%A), %(w)) {|f| f.write(b)}\n\
exit 1 if b.include?(%(<)*%L)'"
[help]
autocorrect = 50 # Automatically correct misspelled git subcommands after 5 seconds.
[branch]
Expand Down
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ ln -sf config_files/jshintrc ~/.jshintrc

ln -sf config_files/gitconfig ~/.gitconfig
ln -sf config_files/gitignore ~/.gitignore
ln -sf config_files/gitattributes ~/.gitattributes

ln -sf config_files/inputrc ~/.inputrc

Expand Down

0 comments on commit 185f9ec

Please sign in to comment.