Skip to content

Commit

Permalink
Added init command
Browse files Browse the repository at this point in the history
  • Loading branch information
scttnlsn committed Nov 18, 2014
1 parent a308ab0 commit ac16024
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/dandelion/cli.rb
Expand Up @@ -4,7 +4,7 @@ module Dandelion
class CLI
def initialize(args)
@args = args

@options = {}
@options[:help] = true if @args.length == 0

Expand Down Expand Up @@ -48,6 +48,10 @@ def command_class
def execute!
parse!(@parser)

if @args.length == 0
@options[:help] = true
end

if @options[:help]
display_help
exit
Expand Down Expand Up @@ -127,4 +131,4 @@ def log
Dandelion.logger
end
end
end
end
3 changes: 2 additions & 1 deletion lib/dandelion/command.rb
Expand Up @@ -83,4 +83,5 @@ def log
end

require 'dandelion/command/deploy'
require 'dandelion/command/status'
require 'dandelion/command/init'
require 'dandelion/command/status'
28 changes: 28 additions & 0 deletions lib/dandelion/command/init.rb
@@ -0,0 +1,28 @@
module Dandelion
module Command
class Init < Command::Base
command :init

def self.parser(options)
OptionParser.new do |opts|
opts.banner = 'Usage: dandelion init <revision>'
end
end

def setup(args)
@revision = args.shift
end

def execute!
raise RevisionError.new('must specify revision') if @revision.nil?
log.info("Connecting to #{adapter.to_s}")

workspace.remote_commit = workspace.lookup(@revision)
remote_commit = workspace.remote_commit

log.info("Remote revision: #{remote_commit ? remote_commit.oid : '---'}")
log.info("Local HEAD revision: #{workspace.local_commit.oid}")
end
end
end
end
4 changes: 2 additions & 2 deletions lib/dandelion/workspace.rb
Expand Up @@ -38,8 +38,6 @@ def remote_commit=(commit)
self.remote_sha = commit.oid
end

private

def lookup(val)
result = lookup_sha(val) ||
lookup_ref(val) ||
Expand All @@ -52,6 +50,8 @@ def lookup(val)
result
end

private

def lookup_sha(val)
@repo.lookup(val)
rescue Rugged::OdbError, Rugged::InvalidError
Expand Down
18 changes: 18 additions & 0 deletions spec/dandelion/command/init_spec.rb
@@ -0,0 +1,18 @@
require 'spec_helper'

describe Dandelion::Command::Init do
let(:revision) { 'e289ff1e2729839759dbd6fe99b6e35880910c7c' }

describe '#execute!' do
let(:adapter) { Dandelion::Adapter::NoOpAdapter.new({}) }
let(:workspace) { Dandelion::Workspace.new(test_repo, adapter) }
let(:command) { described_class.new(workspace, {}, {}) }

before { command.setup([revision]) }

it 'sets remote revision to specified revision' do
workspace.should_receive(:remote_commit=).with(workspace.lookup(revision))
command.execute!
end
end
end

0 comments on commit ac16024

Please sign in to comment.