Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #85 from socialcast/fix-track-branch
Browse files Browse the repository at this point in the history
Fix track branch
  • Loading branch information
seanwalbran committed Jun 22, 2015
2 parents 1fba324 + e24a527 commit 9d7be30
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
1 change: 1 addition & 0 deletions lib/socialcast-git-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Gitx

# execute a shell command and raise an error if non-zero exit code is returned
def run_cmd(cmd)
raise "Unstubbed git command #{cmd}" if ENV['SCGITX_TEST'] == 'true'
say "\n$ "
say cmd.gsub("'", ''), :red
raise "#{cmd} failed" unless system cmd
Expand Down
2 changes: 1 addition & 1 deletion lib/socialcast-git-extensions/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def share_branch(branch)
end

def track_branch(branch)
run_cmd "git branch -u #{branch} origin/#{branch}"
run_cmd "git branch --track origin/#{branch}"
end

# integrate a branch into a destination aggregate branch
Expand Down
2 changes: 1 addition & 1 deletion lib/socialcast-git-extensions/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Socialcast
module Gitx
VERSION = "3.1.30"
VERSION = "3.1.31"
end
end
2 changes: 1 addition & 1 deletion socialcast-git-extensions.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'rest-client', '~> 1.7'
s.add_runtime_dependency 'thor', '~> 0.19.1'
s.add_runtime_dependency 'rake', '~> 10.3'
s.add_development_dependency 'rspec', '~> 3.0.0'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'pry', '~> 0.9.12.6'
s.add_development_dependency 'webmock', '~> 1.21'

Expand Down
67 changes: 31 additions & 36 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
require 'spec_helper'

describe Socialcast::Gitx::CLI do
# stub methods on cli
class Socialcast::Gitx::CLI
class << self
attr_accessor :stubbed_executed_commands
end
private
# stub out command execution and record commands for test inspection
def run_cmd(cmd)
self.class.stubbed_executed_commands << cmd
end
end
let(:stubbed_executed_commands) { [] }

def stub_message(message_body, params = {})
expect(Socialcast::CommandLine::Message).to receive(:create).with(params.merge(:body => message_body)).and_return(double(:permalink_url => 'https://community.socialcast.com/messages/1234'))
Expand All @@ -21,8 +11,13 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.instance_eval do # to supress warning from stubbing ldap_config
@no_tasks = @no_commands = true
end

Socialcast::Gitx::CLI.stubbed_executed_commands = []
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:run_cmd) do |_instance, cmd|
stubbed_executed_commands << cmd
end
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:'`') do |_instance, cmd|
raise "Unstubbed backticks detected"
end
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:current_repo).and_return('socialcast/socialcast-git-extensions')
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:say)
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:current_branch).and_return('FOO')
allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:current_user).and_return('wireframe')
Expand All @@ -36,7 +31,7 @@ def stub_message(message_body, params = {})
end
it 'should not post message to socialcast' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
'git pull origin FOO',
'git pull origin master',
'git push origin HEAD'
Expand All @@ -53,7 +48,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should default to prototype' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand All @@ -77,7 +72,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should default to prototype' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand All @@ -99,7 +94,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand All @@ -121,7 +116,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should also integrate into prototype and run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand Down Expand Up @@ -163,7 +158,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['release']
end
it 'does not try and release the branch' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq(["git branch -D last_known_good_staging", "git fetch origin", "git checkout last_known_good_staging", "git checkout FOO"])
expect(stubbed_executed_commands).to eq(["git branch -D last_known_good_staging", "git fetch origin", "git checkout last_known_good_staging", "git checkout FOO"])
end
end
context 'when user confirms release' do
Expand All @@ -176,7 +171,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git branch -D last_known_good_staging",
"git fetch origin",
"git checkout last_known_good_staging",
Expand Down Expand Up @@ -219,7 +214,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['release']
end
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand Down Expand Up @@ -266,7 +261,7 @@ def stub_message(message_body, params = {})
expect(Socialcast::Gitx::CLI.new.send(:reserved_branches)).to include 'special-master'
end
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git branch -D last_known_good_staging",
"git fetch origin",
"git checkout last_known_good_staging",
Expand Down Expand Up @@ -306,7 +301,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git branch -D last_known_good_staging",
"git fetch origin",
"git checkout last_known_good_staging",
Expand Down Expand Up @@ -347,7 +342,7 @@ def stub_message(message_body, params = {})
end
it 'should post message to socialcast' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git branch -D last_known_good_staging",
"git fetch origin",
"git checkout last_known_good_staging",
Expand All @@ -371,14 +366,14 @@ def stub_message(message_body, params = {})
end

describe '#nuke' do
before { allow_any_instance_of(Socialcast::Gitx::CLI).to receive(:branches).and_return([]) }
context 'when target branch == staging and --destination == last_known_good_staging' do
before do
stub_message "#worklog resetting staging branch to last_known_good_staging in socialcast/socialcast-git-extensions #scgitx\n/cc @SocialcastDevelopers"

Socialcast::Gitx::CLI.start ['nuke', 'staging', '--destination', 'last_known_good_staging']
end
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git checkout master",
"git branch -D last_known_good_staging",
"git fetch origin",
Expand All @@ -387,7 +382,7 @@ def stub_message(message_body, params = {})
"git push origin --delete staging",
"git checkout -b staging",
"git push origin staging",
"git branch -u staging origin/staging",
"git branch --track origin/staging",
"git checkout master"
])
end
Expand All @@ -400,7 +395,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['nuke', 'qa']
end
it 'defaults to last_known_good_qa and should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git checkout master",
"git branch -D last_known_good_qa",
"git fetch origin",
Expand All @@ -409,7 +404,7 @@ def stub_message(message_body, params = {})
"git push origin --delete qa",
"git checkout -b qa",
"git push origin qa",
"git branch -u qa origin/qa",
"git branch --track origin/qa",
"git checkout master"
])
end
Expand All @@ -422,7 +417,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['nuke', 'qa']
end
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git checkout master",
"git branch -D last_known_good_master",
"git fetch origin",
Expand All @@ -431,7 +426,7 @@ def stub_message(message_body, params = {})
"git push origin --delete qa",
"git checkout -b qa",
"git push origin qa",
"git branch -u qa origin/qa",
"git branch --track origin/qa",
"git checkout master",
"git checkout master",
"git branch -D last_known_good_master",
Expand All @@ -441,7 +436,7 @@ def stub_message(message_body, params = {})
"git push origin --delete last_known_good_qa",
"git checkout -b last_known_good_qa",
"git push origin last_known_good_qa",
"git branch -u last_known_good_qa origin/last_known_good_qa",
"git branch --track origin/last_known_good_qa",
"git checkout master"
])
end
Expand Down Expand Up @@ -931,7 +926,7 @@ def stub_message(message_body, params = {})
it 'should create github pull request' do end # see expectations
it 'should post socialcast message' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD"
Expand All @@ -957,7 +952,7 @@ def stub_message(message_body, params = {})
it 'should create github pull request' do end # see expectations
it 'should post socialcast message' do end # see expectations
it 'should run expected commands' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD"
Expand Down Expand Up @@ -993,7 +988,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['promote']
end
it 'should integrate into staging' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git pull origin FOO",
"git pull origin master",
"git push origin HEAD",
Expand Down Expand Up @@ -1021,7 +1016,7 @@ def stub_message(message_body, params = {})
Socialcast::Gitx::CLI.start ['cleanup']
end
it 'should only cleanup non-reserved branches' do
expect(Socialcast::Gitx::CLI.stubbed_executed_commands).to eq([
expect(stubbed_executed_commands).to eq([
"git checkout master",
"git pull",
"git remote prune origin",
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

require 'socialcast-git-extensions/cli'

ENV['SCGITX_TEST'] = 'true'

RSpec.configure do |config|
config.mock_with :rspec

Expand Down

0 comments on commit 9d7be30

Please sign in to comment.