Skip to content

Commit

Permalink
use CommandRunner in Checkout#head
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jul 26, 2010
1 parent eaff9cd commit a24c833
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions lib/integrity/checkout.rb
Expand Up @@ -2,7 +2,7 @@ module Integrity
class Checkout
def initialize(repo, commit, directory, logger)
@repo = repo
@commit = commit == "HEAD" ? head : commit
@commit = commit
@directory = directory
@logger = logger
end
Expand All @@ -13,7 +13,7 @@ def run
in_dir do |c|
c.run! "git fetch origin"
c.run! "git checkout origin/#{@repo.branch}"
c.run! "git reset --hard #{@commit}"
c.run! "git reset --hard #{sha1}"
end
end

Expand All @@ -22,13 +22,16 @@ def metadata
"<%ae>%nmessage: >-%n %s%ncommitted_at: %ci%n"

dump = YAML.load(`cd #{@directory} && git show -s \
--pretty=format:"#{format}" #{@commit}`)
--pretty=format:"#{format}" #{sha1}`)

dump.update("committed_at" => Time.parse(dump["committed_at"]))
end

def head
`git ls-remote --heads #{@repo.uri} #{@repo.branch} | cut -f1`.chomp
runner.run!(
"git ls-remote --heads #{@repo.uri} #{@repo.branch} " \
"| cut -f1"
)
end

def run_in_dir(command)
Expand All @@ -42,5 +45,9 @@ def in_dir(&block)
def runner
@runner ||= CommandRunner.new(@logger)
end

def sha1
@sha1 ||= @commit == "HEAD" ? head : @commit
end
end
end
4 changes: 3 additions & 1 deletion lib/integrity/command_runner.rb
Expand Up @@ -21,7 +21,7 @@ def run(command)
output = ""
IO.popen(cmd, "r") { |io| output = io.read }

[$?.success?, output]
[$?.success?, output.chomp]
end

def run!(command)
Expand All @@ -31,6 +31,8 @@ def run!(command)
@logger.error(output.inspect)
raise Error, "Failed to run '#{command}'"
end

output
end

def normalize(cmd)
Expand Down
1 change: 0 additions & 1 deletion test/acceptance/campfire_notification_test.rb
Expand Up @@ -81,7 +81,6 @@ def build
Commit Author: #{build_commit["author"]["name"]}
Running tests...
EOM

paste_payload = {
Expand Down

0 comments on commit a24c833

Please sign in to comment.