Created
January 20, 2013 17:10
-
-
Save Hunter-Dolan/4579913 to your computer and use it in GitHub Desktop.
"Post Commit" hook to append the lolcommits image to every commit.
This file contains 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 | |
commit = `git log -1 --oneline` | |
hash = commit.to_s.split(" ").first | |
message = commit.sub("#{hash} ", "") | |
unless(message.gsub("\n","").end_with?(".jpg")) | |
`lolcommits --capture` | |
repopath = `git rev-parse --show-toplevel`.gsub("\n", "") | |
repourl = `git config --get remote.origin.url`.gsub("\n", "") | |
reponame = "#{`basename #{repopath}`.to_s}".gsub("\n", "") | |
path = "#{File.expand_path('~')}/.lolcommits/#{reponame}/" | |
@filename = nil | |
Dir.open(path).each do |filename| | |
if filename.start_with?(hash) | |
image = path + filename | |
system("mkdir #{repopath}/lolcommits") | |
`cp #{image} #{repopath}/lolcommits/#{filename}` | |
@filename = filename | |
end | |
end | |
unless @filename == nil | |
githubstuff = repourl.gsub("[email protected]:","").gsub(".git","").gsub("https://github.com/","") | |
github_image_url = "https://github.com/#{githubstuff}/blob/master/lolcommits/#{@filename}" | |
`git add #{repopath}/lolcommits/#{@filename}` | |
`git commit --amend --no-verify -m "#{message} #{github_image_url}"` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment