Skip to content

Commit

Permalink
Handle non-git dirs
Browse files Browse the repository at this point in the history
Nails #10
  • Loading branch information
pikesley committed Jan 29, 2014
1 parent 8642b8d commit cd72dbc
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
19 changes: 18 additions & 1 deletion features/badger.feature
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@ Feature: Badge Robot
"""
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)
"""
"""

Scenario: handle a non-git-repo gracefully
When I run `badger badge /tmp`
Then the output should contain:
"""
Run this from inside a git repo
"""
And the exit status should be 1

@no-remote
Scenario: handle a git repo without a github remote
When I run `badger badge /tmp/not_wow`
Then the output should contain:
"""
This repo does not appear to have a github remote
"""
And the exit status should be 2
8 changes: 8 additions & 0 deletions features/support/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@
f.close
end

Before '@no-remote' do
Git.init '/tmp/not_wow'
end

After '@no-remote' do
# FileUtils.remove_dir '/tmp/not_wow', :force => true
end

15 changes: 14 additions & 1 deletion lib/badger/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ class CLI < Thor
option :also, desc: 'Include this extra service (currently only \'mit\')'

def badge dir = '.'
@badger = Badger.new Git.open(dir).remote.url
begin
@g = Git.open(dir)
rescue ArgumentError
puts 'Run this from inside a git repo'
exit 1
end

@r = @g.remote.url
if @r.nil?
puts 'This repo does not appear to have a github remote'
exit 2
end
@badger = Badger.new @r

@badger.remove options[:not].split(',') if options[:not]
@badger.only options[:only].split(',') if options[:only]
@badger.also options[:also].split(',') if options[:also]
Expand Down

0 comments on commit cd72dbc

Please sign in to comment.