diff --git a/lib/awestruct/deploy/github_pages_deploy.rb b/lib/awestruct/deploy/github_pages_deploy.rb index dec63c66..0a5e8a35 100644 --- a/lib/awestruct/deploy/github_pages_deploy.rb +++ b/lib/awestruct/deploy/github_pages_deploy.rb @@ -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 ) @@ -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 ) diff --git a/spec/github_pages_deploy_spec.rb b/spec/github_pages_deploy_spec.rb index 5c55639c..955abfdf 100644 --- a/spec/github_pages_deploy_spec.rb +++ b/spec/github_pages_deploy_spec.rb @@ -10,6 +10,10 @@ 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 @@ -17,18 +21,24 @@ 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