Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Mar 31, 2012
1 parent 4d75ede commit 368c48e
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 18 deletions.
6 changes: 5 additions & 1 deletion lib/space/helpers.rb
Expand Up @@ -19,7 +19,11 @@ def repo_selected?
end

def git_status
"Git: #{format_boolean(git.clean?)}"
"Git: #{format_boolean(git.clean?)}#{git_ahead if git.ahead?}"
end

def git_ahead
" #{git.ahead} commits ahead".ansi(:cyan)
end

def bundle_status
Expand Down
8 changes: 4 additions & 4 deletions lib/space/models/bundle.rb
Expand Up @@ -4,7 +4,7 @@ class Bundle

COMMANDS = {
:check => 'bundle check',
:list => 'bundle list',
:list => 'bundle list | grep %<name>s',
:config => 'bundle config'
}

Expand All @@ -21,9 +21,9 @@ def info
end

def deps
result(:list).split("\n").map do |dep|
dep =~ /(#{App.name}.*) \(\d\.\d\.\d (.+)\)/
Dependency.new($1, $2) if Repos.names.include?($1)
result(:list, :name => App.name).split("\n").map do |dep|
matches = dep.strip.match /^\* (?<name>[\S]+) \(\d+\.\d+\.\d+(?: (?<ref>.+))?\)/
Dependency.new(matches[:name], matches[:ref])
end.compact
end

Expand Down
4 changes: 2 additions & 2 deletions lib/space/models/command.rb
Expand Up @@ -9,8 +9,8 @@ def initialize(path, command)
@command = command
end

def result
@result ||= chdir { strip_ansi(`#{command}`) }
def result(args = {})
@result ||= chdir { strip_ansi(`#{command % args}`) }
end

def reset
Expand Down
4 changes: 2 additions & 2 deletions lib/space/models/commands.rb
Expand Up @@ -6,8 +6,8 @@ def initialize(path)
@path = path
end

def result(command)
commands[command].result
def result(command, args = {})
commands[command].result(args)
end

def commands
Expand Down
31 changes: 26 additions & 5 deletions lib/space/models/git.rb
@@ -1,23 +1,44 @@
# On branch master
# # Your branch is ahead of 'origin/master' by 1 commit.
# #
# nothing to commit (working directory clean)

module Space
class Git
include Commands

COMMANDS = {
:status => 'git status -s',
:status => 'git status',
:branch => 'git branch --no-color',
:commit => 'git log -1 head'
}

def clean?
result(:status).empty?
end

def branch
result(:branch) =~ /^\* (.+)/ && $1.strip
end

def commit
result(:commit) =~ /^commit (\S{7})/ && $1
end

def status
dirty? ? :dirty : (ahead? ? :ahead : :clean)
end

def ahead?
ahead > 0
end

def ahead
result(:status) =~ /Your branch is ahead of .* by (\d+) commits?\./ ? $1.to_i : 0
end

def dirty?
!clean?
end

def clean?
result(:status).include?('nothing to commit (working directory clean)')
end
end
end
5 changes: 3 additions & 2 deletions spec/models/bundle_spec.rb
Expand Up @@ -3,10 +3,11 @@
describe Bundle do
let(:app) { stub('app', :name => 'travis') }
let(:repo) { stub('repo', :name => 'travis-ci') }
let(:bundle) { Bundle.new(app, 'path/to/repo') }
let(:bundle) { Bundle.new('path/to/repo') }

before :each do
app.stubs(:repos).returns([repo])
App.stubs(:name).returns('travis')
end

describe 'clean?' do
Expand All @@ -30,7 +31,7 @@

describe 'deps' do
it 'returns dependencies listend in `bundle list` that match the app name' do
bundle.stubs(:result).with(:list).returns(" * ansi (1.4.2)\n * travis-ci (0.0.1 123456)")
bundle.stubs(:result).with(:list, :name => 'travis').returns(" * travis-ci (0.0.1 123456)")
dep = bundle.deps.first
[dep.name, dep.ref].should == ['travis-ci', '123456']
end
Expand Down
46 changes: 44 additions & 2 deletions spec/models/git_spec.rb
@@ -1,9 +1,51 @@
require 'spec_helper'

describe Git do
let(:git) { Git.new('path/to/somewhere') }

describe 'ahead?' do
it 'returns true if ahead is greater than 0' do
git.stubs(:ahead).returns(1)
git.ahead?.should be_true
end

it 'returns false if ahead equals 0' do
git.stubs(:ahead).returns(0)
git.ahead?.should be_false
end
end

describe 'ahead' do
it "returns 2 if `git status` contains: ahead of '...' by 2 commits." do
git.stubs(:result).with(:status).returns %(Your branch is ahead of 'origin/master' by 2 commits.\n\nnothing to commit (working directory clean))
git.ahead.should == 2
end

it "returns 1 if `git status` contains: ahead of '...' by 1 commit." do
git.stubs(:result).with(:status).returns %(Your branch is ahead of 'origin/master' by 1 commit.\n\nnothing to commit (working directory clean))
git.ahead.should == 1
end

it "returns 0 if `git status` does not contain a line about commits ahead of a remote branch." do
git.stubs(:result).with(:status).returns %(Your branch is nothing to commit (working directory clean))
git.ahead.should == 0
end
end

describe 'status' do

end

describe 'clean?' do
it 'returns true if `git status -s` is empty'
it 'returns false if `git status -s` is not empty'
it 'returns true if `git status` contains: nothing to commit' do
git.stubs(:result).with(:status).returns 'nothing to commit (working directory clean)'
git.clean?.should be_true
end

it 'returns false if `git status` does not contain: nothing to commit' do
git.stubs(:result).with(:status).returns 'Changes not staged for commit:'
git.clean?.should be_false
end
end

describe 'branch' do
Expand Down

0 comments on commit 368c48e

Please sign in to comment.