Skip to content

Commit

Permalink
Add output to git fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
jsl committed May 5, 2011
1 parent f4106dc commit 5b6e45a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions lib/propel/git_repository.rb
Expand Up @@ -2,6 +2,8 @@ module Propel
class GitRepository
Result = Struct.new(:result, :exitstatus)

attr_accessor :logger

def self.changed?
new.changed?
end
Expand Down Expand Up @@ -66,10 +68,14 @@ def current_branch
end

def fetch!
logger.report_operation "Retrieving remote objects"

git('fetch').tap do |result|
if result.exitstatus != 0
warn "Fetch of remote repository failed, exiting."
exit 1
else
logger.report_status("DONE", :green)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/propel/logger.rb
Expand Up @@ -27,6 +27,7 @@ def warn(message, color_sym = nil)

def report_operation(message)
Kernel.print("%-60s" % "#{message}:")
STDOUT.flush
end

def report_status(message, color_sym)
Expand Down
3 changes: 2 additions & 1 deletion lib/propel/runner.rb
Expand Up @@ -6,6 +6,8 @@ def initialize(args = [ ])
@repository = GitRepository.new
@options = Configuration.new(args, @repository).options
@logger = Logger.new(@options)

@repository.logger = @logger
end

def start
Expand Down Expand Up @@ -34,7 +36,6 @@ def start

def check_remote_build!
logger.report_operation "CI server status"
STDOUT.flush

waited_for_build = false
if @options[:wait]
Expand Down
2 changes: 2 additions & 0 deletions spec/propel/git_repository_spec.rb
Expand Up @@ -63,6 +63,8 @@

it "should exit with a not-0 status and warn the user if the fetch fails" do
git_repository = Propel::GitRepository.new
git_repository.logger = stub_logger

git_repository.should_receive(:git).with('fetch').and_return(Propel::GitRepository::Result.new('', 1))
git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* master\n testbranch", 0))

Expand Down
4 changes: 0 additions & 4 deletions spec/propel/runner_spec.rb
Expand Up @@ -8,10 +8,6 @@
end

describe ".start" do
def stub_logger
double('logger', :report_operation => true, :report_status => true, :puts => true, :warn => true)
end

it "should not call propel! if there is nothing to push" do
runner = Propel::Runner.new
runner.stub!(:logger).and_return(stub_logger)
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -3,4 +3,8 @@

$:.unshift(File.dirname(__FILE__) + '/../lib')

require 'propel'
require 'propel'

def stub_logger
double('logger', :report_operation => true, :report_status => true, :puts => true, :warn => true)
end

0 comments on commit 5b6e45a

Please sign in to comment.