Skip to content

Commit

Permalink
WIP: Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/lolcommits/configuration.rb
	lolcommits.gemspec
  • Loading branch information
mrclmrvn committed Dec 4, 2013
2 parents 3b16af7 + 5c0de5c commit cf3e853
Show file tree
Hide file tree
Showing 21 changed files with 557 additions and 374 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage
*.gem
.bundle
Gemfile.lock
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0.x.x (in development)
* TODO: figure out problems with GUI clients

0.5.1 (10 November 2013)
0.5.1 (13 November 2013)
* Fix JSON gem issue #163 (@matthutchinson, #171)
* Enable image capture under Cygwin (@cwc, #105)
* Add Ruby PATH to post-commit hook (@matthutchinson, #155)
Expand Down
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ By default, the lolimages are stored by a Github style short SHA in a `~/.lolcom
[![Gem Version](https://badge.fury.io/rb/lolcommits.png)](http://badge.fury.io/rb/lolcommits)
[![Build Status](https://secure.travis-ci.org/mroth/lolcommits.png?branch=master)](http://travis-ci.org/mroth/lolcommits)
[![Dependency Status](https://gemnasium.com/mroth/lolcommits.png)](https://gemnasium.com/mroth/lolcommits)
[![Coverage Status](https://coveralls.io/repos/mroth/lolcommits/badge.png)](https://coveralls.io/r/mroth/lolcommits)

## Sample images
<img src="http://blog.mroth.info/images/postcontent/yearinsideprojects/lolcommits_users2.jpg" />
Expand Down Expand Up @@ -47,22 +48,34 @@ From within any git repository, simply do a `lolcommits --enable`. From that poi
Don't worry about it too much, half the fun of lolcommits is forgetting it's installed!

### Other commands
Ok, if you insist... Since you know about `--enable`, common sense suggest there is also a repository specific `--disable`, hopefully you can guess what that does. Other handy common commands include `--last`, which will open for display your most recent lolcommit image, or `--browse`, which pops open the directory containing all the lolcommit images for your current repository. You can always do `--help` for a full list of available commands.

### Configuration variables
lolcommits has some options for additional lulz. You can enable via
environment variables.

* Set webcam device on mac - set `LOLCOMMITS_DEVICE` environment variable.
* Set delay persistently (for slow to warmup webcams) - set
`LOLCOMMITS_DELAY` var to time in seconds.
* Set font file location - set `LOLCOMMITS_FONT` environment variable.
* Animated gifs - set `LOLCOMMITS_ANIMATE=3` (currently Mac/OSX only and requires `ffmpeg`).
* Fork lolcommits runner - set `LOLCOMMITS_FORK` environment variable
(causes capturing command to fork to a new process, speedily returning you to your terminal).
* Disable the notification at commit time - set `LOLCOMMITS_STEALTH` environment variable.

Read the [available environment variables](https://github.com/mroth/lolcommits/wiki/Available-Environment-Variables) for more information.
Ok, if you insist... Since you know about `--enable`, common sense suggests there is also a repository specific `--disable`, hopefully you can guess what that does. Other handy common commands include `--last`, which will open for display your most recent lolcommit image, or `--browse`, which pops open the directory containing all the lolcommit images for your current repository. You can always do `--help` for a full list of available commands.

**NOTE**: Any extra arguments you pass with the --enable command are auto-appended to the git-commit capture command. For example;

lolcommits --enable --delay=5 --animate=4 --fork

Will configure capturing of an animated gif (4 secs) after a 5 sec delay in a forked process. See the section below for more capture configuration variables.

### Capture configuration variables
lolcommits has some capture options for additional lulz. You can enable these via environment variables like so;

* `LOLCOMMITS_DEVICE` set a webcam device - **mac and linux only**
* `LOLCOMMITS_ANIMATE` (in seconds) set time for capturing an animated gif - **mac only & requires ffmpeg**
* `LOLCOMMITS_DELAY` (in seconds) set delay persistently (for slow webcams to warmup)
* `LOLCOMMITS_FONT` set font file location for lolcommit text
* `LOLCOMMITS_FORK` fork lolcommit runner (capture command forks to a new process, speedily returning you to your terminal)
* `LOLCOMMITS_STEALTH` disable notification messages at commit time

Or they can be set via the following arguments in the capture command (located in your repository's `.git/hooks/post-commit` file).

* `--device=DEVICE` or `-d DEVICE`
* `--animate=SECONDS` or `-a SECONDS`
* `--delay=SECONDS` or `-w SECONDS`
* `--font=FONT_PATH` or `-f FONT_PATH`
* `--fork`
* `--stealth`

Read how to [configure commit capturing](https://github.com/mroth/lolcommits/wiki/Configure-Commit-Capturing) for more details.

### Animated Gif Capturing
Animated gifs (Mac/OSX only) can take a while to generate (depending on the number of seconds you capture and the capabilities of your machine). `ffmpeg` is required and can be installed with brew like so;
Expand Down
83 changes: 68 additions & 15 deletions bin/lolcommits
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ def die_if_not_git_repo!
end
end

def good_shebang?
File.read(HOOK_PATH).lines.first =~ /^\#\!\/bin\/.*sh/
end

def lolcommits_hook?
File.exists?(HOOK_PATH) &&
File.read(HOOK_PATH).to_s =~ /lolcommits.*\(begin\)(.*\n)*.*lolcommits.*\(end\)/
end

def remove_existing_hook
hook = File.read(HOOK_PATH)
out = File.open(HOOK_PATH, 'w')
skip = false

hook.lines.each do |line|
if !skip && (line =~ /lolcommits.*\(begin\)/)
skip = true
end

out << line unless skip

if skip && (line =~ /lolcommits.*\(end\)/)
skip = false
end
end

out.close
end

#
# NO ARGUMENTS SPECIFIED, HELP THE USER OUT
#
Expand Down Expand Up @@ -89,34 +118,58 @@ def do_enable
Dir.mkdir(HOOK_DIR)
end

if File.exists? HOOK_PATH
fatal "A post-commit hook already exists for this project."
#TODO: disambiguate between OUR post-commit hook and something else
exit 1
# clear away any existing lolcommits hook
if hook_exists = File.exists?(HOOK_PATH)
remove_existing_hook

# check for a good shebang line in the existing hook
unless good_shebang?
warn "the existing hook (at #{HOOK_PATH}) doesn't start with with a good shebang; like #!/bin/sh"
exit 1
end
end

File.open(HOOK_PATH, hook_exists ? 'a' : 'w') do |f|
f.write(hook_script(!hook_exists))
end

ruby_path = Lolcommits::Configuration.command_which('ruby')
hook_export = "export PATH=\"#{ruby_path}:$PATH\"\n" if ruby_path
doc = "#!/bin/sh\n#{hook_export}lolcommits --capture\n"
File.open(HOOK_PATH, 'w') {|f| f.write(doc) }
FileUtils.chmod 0755, HOOK_PATH
info "installed lolcommmit hook as:"

info "installed lolcommmit hook to:"
info " -> #{File.expand_path(HOOK_PATH)}"
info "(to remove later, you can use: lolcommits --disable)"
# we dont symlink, but rather install a small stub that calls the one from path
# that way, as gem version changes, script updates even if new file thus breaking symlink
end

def hook_script(add_shebang = true)
shebang = add_shebang ? "#!/bin/sh\n\n" : ''
ruby_path = Lolcommits::Configuration.command_which('ruby')
hook_export = "export PATH=\"#{ruby_path}:$PATH\"\n" if ruby_path
capture_cmd = 'lolcommits --capture'
capture_args = " #{ARGV[1..-1].join(' ')}" if ARGV.length > 1

<<-EOS
#{shebang}### lolcommits hook (begin) ###
#{hook_export}#{capture_cmd}#{capture_args}
### lolcommits hook (end) ###
EOS
end

#
# IF --DISABLE, DO DISABLE
#
def do_disable
if File.exists? HOOK_PATH
#TODO: check if hook file has been modified before removing
FileUtils.rm HOOK_PATH
info "removed #{HOOK_PATH}"
if lolcommits_hook?
remove_existing_hook
info "uninstalled lolcommits hook (from #{HOOK_PATH})"
elsif File.exists?(HOOK_PATH)
info "couldn't find an lolcommits hook (at #{HOOK_PATH})"
if File.read(HOOK_PATH) =~ /lolcommit/
info "warning: an older-style lolcommit hook may still exist, edit #{HOOK_PATH} to remove it manually"
end
else
info "lolcommits is not enabled for this directory, so there is nothing to uninstall."
info "no post commit hook found (at #{HOOK_PATH}), so there is nothing to uninstall"
end
end

Expand Down Expand Up @@ -387,7 +440,7 @@ if not (Choice.choices[:enable] || Choice.choices[:disable])
elsif Choice.choices[:configure]
do_configure()
elsif Choice.choices[:show_config]
puts configuration.user_configuration.to_yaml
puts configuration
elsif Choice.choices[:plugins]
configuration.puts_plugins()
elsif Choice.choices[:last]
Expand Down
46 changes: 40 additions & 6 deletions features/lolcommits.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,50 @@ Feature: Basic UI functionality
Given a git repository named "loltest" with no "post-commit" hook
When I cd to "loltest"
And I successfully run `lolcommits --enable`
Then the output should contain "installed lolcommmit hook as:"
Then the output should contain "installed lolcommmit hook to:"
And the output should contain "(to remove later, you can use: lolcommits --disable)"
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain "lolcommits --capture"
And the exit status should be 0

Scenario: Enable in a git repository that already has a post-commit hook
Given a git repository named "loltest" with a "post-commit" hook
And the "loltest" repository "post-commit" hook has content "#!/bin/sh\n\n/my/own/script"
When I cd to "loltest"
And I successfully run `lolcommits --enable`
Then the output should contain "installed lolcommmit hook to:"
And the output should contain "(to remove later, you can use: lolcommits --disable)"
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain "#!/bin/sh"
And the file ".git/hooks/post-commit" should contain "/my/own/script"
And the file ".git/hooks/post-commit" should contain "lolcommits --capture"
And the exit status should be 0

Scenario: Enable in a git repository that already has post-commit hook with a bad shebang
Given a git repository named "loltest" with a "post-commit" hook
And the "loltest" repository "post-commit" hook has content "#!/bin/ruby"
When I cd to "loltest"
And I run `lolcommits --enable`
Then the output should contain "doesn't start with with a good shebang"
And the file ".git/hooks/post-commit" should not contain "lolcommits --capture"
And the exit status should be 1

Scenario: Enable in a git repository passing capture arguments
Given a git repository named "loltest" with no "post-commit" hook
When I cd to "loltest"
And I successfully run `lolcommits --enable -w 5 --fork`
Then the output should contain "installed lolcommmit hook to:"
And the output should contain "(to remove later, you can use: lolcommits --disable)"
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain "lolcommits --capture -w 5 --fork"
And the exit status should be 0

Scenario: Disable in a enabled git repository
Given I am in a git repository named "lolenabled" with lolcommits enabled
When I successfully run `lolcommits --disable`
Then the output should contain "removed"
And a file named ".git/hooks/post-commit" should not exist
Then the output should contain "uninstalled"
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should not contain "lolcommits --capture"
And the exit status should be 0

Scenario: Trying to enable while not in a git repo fails
Expand Down Expand Up @@ -100,7 +134,7 @@ Feature: Basic UI functionality
Then the output should contain a list of plugins
And the output should contain "Name of plugin to configure:"
Then the output should contain "enabled:"
Then the output should contain "Successfully Configured"
Then the output should contain "Successfully configured plugin: loltext"
And a file named "../.lolcommits/config-test/config.yml" should exist
When I successfully run `lolcommits --show-config`
Then the output should contain "loltext:"
Expand All @@ -112,7 +146,7 @@ Feature: Basic UI functionality
And I run `lolcommits --config` and wait for output
When I enter "loltext" for "Name of plugin to configure"
And I enter "true" for "enabled"
Then I should be presented "Successfully Configured"
Then I should be presented "Successfully configured plugin: loltext"
And a file named "../.lolcommits/config-test/config.yml" should exist
When I successfully run `lolcommits --show-config`
Then the output should contain "loltext:"
Expand All @@ -124,7 +158,7 @@ Feature: Basic UI functionality
And I run `lolcommits --config --test` and wait for output
And I enter "loltext" for "Name of plugin to configure"
And I enter "true" for "enabled"
Then I should be presented "Successfully Configured"
Then I should be presented "Successfully configured plugin: loltext"
And a file named "../.lolcommits/test/config.yml" should exist
When I successfully run `lolcommits --test --show-config`
Then the output should contain "loltext:"
Expand Down
8 changes: 4 additions & 4 deletions features/plugins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Plugins Work
And I enter "b2a70ac0b64e012fa61522000a8c42dc" for "api_key"
And I enter "b2a720b0b64e012fa61522000a8c42dc" for "api_secret"
And I enter "c4aed530b64e012fa61522000a8c42dc" for "repo_id"
Then I should be presented "Successfully Configured"
Then I should be presented "Successfully configured plugin: dot_com"
When I do a git commit
Then the output should contain "*** Preserving this moment in history."
And there should be exactly 1 jpg in "../.lolcommits/dot_com"
Expand All @@ -19,7 +19,7 @@ Feature: Plugins Work
And I run `lolcommits --config` and wait for output
And I enter "loltext" for "Plugin Name"
And I enter "false" for "enabled"
Then I should be presented "Successfully Configured"
Then I should be presented "Successfully configured plugin: loltext"
When I do a git commit
Then the output should contain "*** Preserving this moment in history."
And there should be exactly 1 jpg in "../.lolcommits/loltext"
Expand All @@ -30,8 +30,8 @@ Feature: Plugins Work
And I enter "lolsrv" for "Plugin Name"
And I enter "true" for "enabled"
And I enter "http://localhost" for "server"
Then I should be presented "Successfully Configured"
Then I should be presented "Successfully configured plugin: lolsrv"
When I do a git commit
Then the output should contain "*** Preserving this moment in history."
And there should be exactly 1 jpg in "../.lolcommits/lolsrv"

6 changes: 6 additions & 0 deletions features/step_definitions/lolcommits_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
touch(hook_file) if not File.exists? hook_file
end

Given /^the "(.*?)" repository "(.*?)" hook has content "(.*?)"$/ do |repo_name, hook_name, hook_content|
step %{the git repository named "#{repo_name}" has a "#{hook_name}" hook}
hook_file = File.join current_dir, repo_name, ".git", "hooks", hook_name
File.open(hook_file, 'w') { |f| f.write(hook_content) }
end

Given /^a git repository named "(.*?)" with (a|no) "(.*?)" hook$/ do |repo_name, yesno_modifier, hook_name|
step %{a git repository named "#{repo_name}"}
step %{the git repository named "#{repo_name}" has #{yesno_modifier} "#{hook_name}" hook}
Expand Down
Loading

0 comments on commit cf3e853

Please sign in to comment.