Skip to content
Robin Delaporte edited this page Apr 5, 2016 · 2 revisions

brew install imagemagick

[sudo] gem install lolcommits

In the git repo lolcommits --enable

Then, open ./git/post-commit and replace the code by the following :

#!/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
Clone this wiki locally