Skip to content

Instantly share code, notes, and snippets.

@Hunter-Dolan
Created January 20, 2013 17:10
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hunter-Dolan/4579913 to your computer and use it in GitHub Desktop.
Save Hunter-Dolan/4579913 to your computer and use it in GitHub Desktop.
"Post Commit" hook to append the lolcommits image to every commit.
#!/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("git@github.com:","").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