Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/thegarage/thegarage-gitx
Browse files Browse the repository at this point in the history
…into test-a

# By Ryan Sonnek
# Via Ryan Sonnek
* 'master' of https://github.com/thegarage/thegarage-gitx:
  update tests
  reorganize files into extensions directory
  remove thor extension from test coverage
  remove spec from test coverage
  skip coverage for support files
  add test coverage for oustanding database migrations
  remove unused variable
  Fix git integrate command to properly create aggregate branch on first run.
  • Loading branch information
cgullick committed Sep 19, 2014
2 parents 1d538ea + b487047 commit 8861198
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/thegarage/gitx.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'thegarage/gitx/version'
require 'thegarage/gitx/string_extensions'
require 'thegarage/gitx/thor_extensions'
require 'thegarage/gitx/extensions/string'
require 'thegarage/gitx/extensions/thor'

module Thegarage
module Gitx
Expand Down
14 changes: 12 additions & 2 deletions lib/thegarage/gitx/cli/integrate_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def integrate(target_branch = 'staging')
say "into "
say target_branch, :green

refresh_branch_from_remote target_branch
create_remote_branch(target_branch) unless remote_branch_exists?(target_branch)
refresh_branch_from_remote(target_branch)
run_cmd "git merge #{branch}"
run_cmd "git push origin HEAD"
checkout_branch branch
Expand All @@ -33,10 +34,19 @@ def assert_aggregate_branch!(target_branch)

# nuke local branch and pull fresh version from remote repo
def refresh_branch_from_remote(target_branch)
run_cmd "git branch -D #{target_branch}", :allow_failure => true
run_cmd "git fetch origin"
run_cmd "git branch -D #{target_branch}", :allow_failure => true
checkout_branch target_branch
end

def remote_branch_exists?(target_branch)
repo.branches.each_name(:remote).include?("origin/#{target_branch}")
end

def create_remote_branch(target_branch)
repo.create_branch(target_branch, Thegarage::Gitx::BASE_BRANCH)
run_cmd "git push origin #{target_branch}:#{target_branch}"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/thegarage/gitx/cli/start_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def start(branch_name = nil)

checkout_branch Thegarage::Gitx::BASE_BRANCH
run_cmd 'git pull'
repo.create_branch branch_name, 'master'
repo.create_branch branch_name, Thegarage::Gitx::BASE_BRANCH
checkout_branch branch_name
end

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/thegarage/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Thegarage
module Gitx
VERSION = '2.4.1'
VERSION = '2.4.2'
end
end
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
require 'coveralls'
Coveralls.wear!
Coveralls.wear! do
::SimpleCov.add_filter 'spec'
::SimpleCov.add_filter 'lib/thegarage/gitx/extensions'
end
require 'rubygems'
require 'bundler/setup'

Expand Down
37 changes: 31 additions & 6 deletions spec/thegarage/gitx/cli/integrate_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@
let(:cli) { Thegarage::Gitx::Cli::IntegrateCommand.new(args, options, config) }
let(:current_branch) { double('fake branch', name: 'feature-branch', head?: true) }
let(:repo) { cli.send(:repo) }
let(:branches) { [current_branch] }
let(:remote_branch_names) { [] }

before do
allow(repo).to receive(:branches).and_return(branches)
allow(cli).to receive(:current_branch).and_return(current_branch)
allow(repo).to receive(:branches).and_return(double(each_name: remote_branch_names))
end

describe '#integrate' do
let(:fake_update_command) { double('fake update command') }
before do
allow(Thegarage::Gitx::Cli::UpdateCommand).to receive(:new).and_return(fake_update_command)
end
context 'when target branch is ommitted' do
context 'when target branch is ommitted and remote branch exists' do
let(:remote_branch_names) { ['origin/staging'] }
before do
expect(fake_update_command).to receive(:update)

expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git checkout staging").ordered
expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
Expand All @@ -40,12 +42,35 @@
should meet_expectations
end
end
context 'when target branch == prototype' do
context 'when staging branch does not exist remotely' do
let(:remote_branch_names) { [] }
before do
expect(fake_update_command).to receive(:update)

expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
expect(repo).to receive(:create_branch).with('staging', 'master')

expect(cli).to receive(:run_cmd).with('git push origin staging:staging').ordered

expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git checkout staging").ordered
expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered

cli.integrate
end
it 'creates remote aggregate branch' do
should meet_expectations
end
end
context 'when target branch == prototype and remote branch exists' do
let(:remote_branch_names) { ['origin/prototype'] }
before do
expect(fake_update_command).to receive(:update)

expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git checkout prototype").ordered
expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
Expand Down
60 changes: 60 additions & 0 deletions spec/thegarage/gitx/cli/nuke_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,65 @@
expect { cli.nuke('prototype') }.to raise_error(/No known good tag found for branch/)
end
end
context 'when database migrations exist and user cancels operation' do
let(:buildtag) { 'build-master-2013-10-01-01' }
let(:good_branch) { 'master' }
let(:bad_branch) { 'prototype' }
let(:migrations) do
%w( db/migrate/20140715194946_create_users.rb db/migrate/20140730063034_update_user_account.rb ).join("\n")
end
before do
FileUtils.mkdir_p('db/migrate')

expect(cli).to receive(:current_build_tag).with(good_branch).and_return(buildtag)

expect(cli).to receive(:ask).and_return(good_branch)
expect(cli).to receive(:yes?).with('Reset prototype to build-master-2013-10-01-01? (y/n)', :green).and_return(true)
expect(cli).to receive(:run_cmd).with("git diff build-master-2013-10-01-01...prototype --name-only db/migrate").and_return(migrations)
expect(cli).to receive(:yes?).with('Are you sure you want to nuke prototype? (y/n) ', :green).and_return(false)

cli.nuke 'prototype'
end
after do
FileUtils.rm_rf('db/migrate')
end
it 'prompts for nuke confirmation' do
should meet_expectations
end
end
context 'when database migrations exist and user approves operation' do
let(:buildtag) { 'build-master-2013-10-01-01' }
let(:good_branch) { 'master' }
let(:bad_branch) { 'prototype' }
let(:migrations) do
%w( db/migrate/20140715194946_create_users.rb db/migrate/20140730063034_update_user_account.rb ).join("\n")
end
before do
FileUtils.mkdir_p('db/migrate')

expect(cli).to receive(:current_build_tag).with(good_branch).and_return(buildtag)

expect(cli).to receive(:ask).and_return(good_branch)
expect(cli).to receive(:yes?).with('Reset prototype to build-master-2013-10-01-01? (y/n)', :green).and_return(true)
expect(cli).to receive(:run_cmd).with("git diff build-master-2013-10-01-01...prototype --name-only db/migrate").and_return(migrations)
expect(cli).to receive(:yes?).with('Are you sure you want to nuke prototype? (y/n) ', :green).and_return(true)

expect(cli).to receive(:run_cmd).with("git checkout master").ordered
expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git push origin --delete prototype", allow_failure: true).ordered
expect(cli).to receive(:run_cmd).with("git checkout -b prototype build-master-2013-10-01-01").ordered
expect(cli).to receive(:run_cmd).with("git push origin prototype").ordered
expect(cli).to receive(:run_cmd).with("git branch --set-upstream-to origin/prototype").ordered
expect(cli).to receive(:run_cmd).with("git checkout master").ordered

cli.nuke 'prototype'
end
after do
FileUtils.rm_rf('db/migrate')
end
it 'prompts for nuke confirmation' do
should meet_expectations
end
end
end
end

0 comments on commit 8861198

Please sign in to comment.