Created
October 29, 2017 21:26
-
-
Save felipesere/129f53a3221e8fb504ec9aa30fb74b8d to your computer and use it in GitHub Desktop.
A script that prepends elm or ex depending on what gets commited
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'set' | |
message = ARGV[0] # the file that contains the message (change this!) | |
source = ARGV[1] # can be template, merge, squash, commit | |
commit_id = ARGV[2] | |
if ["merge","squash"].include?(source) | |
return 1 # do nothing | |
end | |
files = `git diff --cached --name-only`.split("\n") | |
config = { | |
"assets/elm" => "elm", | |
"lib" => "ex" | |
} | |
tags = Set.new | |
files.each do |f| | |
config.each do |pattern, prefix| | |
if f.match?(pattern) | |
tags.add(prefix) | |
end | |
end | |
end | |
if tags.to_a.any? | |
old_lines = ["[#{tags.to_a.join(",")}] "] + File.readlines(message) | |
File.open(message, 'w') do |fo| | |
old_lines.each do |line| | |
fo.puts line | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment