Skip to content

Commit

Permalink
[Issue #126] Checkout and restore the current branch when publishing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lance committed Jul 27, 2012
1 parent 138a1aa commit f0708b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
16 changes: 4 additions & 12 deletions lib/awestruct/deploy/github_pages_deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ def git
end

def publish_site
current_branch = git.branch
checkout_pages_branch
add_and_commit_site @site_path
push_and_restore current_branch
end

def checkout_pages_branch
current_branch = git.current_branch
git.branch( @branch ).checkout
add_and_commit_site @site_path
git.push( 'origin', @branch )
git.checkout( current_branch )
end

def add_and_commit_site( path )
Expand All @@ -39,12 +36,7 @@ def add_and_commit_site( path )
$stderr.puts "Can't commit. #{e}."
end
end
end

def push_and_restore( original_branch )
git.reset_hard
git.push( 'origin', @branch )
git.checkout( original_branch )
end

def message_for( key )
Expand Down
22 changes: 16 additions & 6 deletions spec/github_pages_deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,35 @@
deploy_config = mock
deploy_config.stub(:[]).with('branch').and_return('the-branch')
@deployer = Awestruct::Deploy::GitHubPagesDeploy.new( site_config, deploy_config )

@git = mock
@git.stub_chain(:status, :changed, :empty?).and_return true
::Git.stub(:open).with('.').and_return @git
end

it "should be auto-registered" do
Awestruct::Deployers.instance[ :github_pages ].should == Awestruct::Deploy::GitHubPagesDeploy
end

it "should publish the site if there have been changes to the git repo" do
git = mock
git.stub_chain(:status, :changed, :empty?).and_return true
::Git.should_receive(:open).with('.').and_return git
::Git.should_receive(:open).with('.').and_return @git
@deployer.should_receive(:publish_site)
@deployer.run
end

it "should warn and noop if no changes have been committed" do
git = mock
git.stub_chain(:status, :changed, :empty?).and_return false
::Git.should_receive(:open).with('.').and_return git
@git.stub_chain(:status, :changed, :empty?).and_return false
@deployer.should_receive(:message_for).with(:existing_changes)
@deployer.run
end

it "should save and restore the current branch when publishing" do
@git.should_receive(:current_branch).and_return( 'bacon' )
@git.stub_chain(:branch, :checkout)
@git.should_receive(:push).with('origin', 'the-branch')
@git.should_receive(:checkout).with( 'bacon' )

@deployer.stub(:add_and_commit_site)
@deployer.run
end
end

0 comments on commit f0708b1

Please sign in to comment.