thegarage-gitx 2.4.1 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b6f8520b6fa00eb4d8b5bd41b2d299e82391e2d
4
- data.tar.gz: a4ed62c3ae3a6fe20e01751690ceb441a9347a71
3
+ metadata.gz: d9b47697535d0f7b3870b35f25567e35dc9d5482
4
+ data.tar.gz: d9a3e772a5e8a83d62d70e5ca4903d86bc94a096
5
5
  SHA512:
6
- metadata.gz: 64bc132adcc7aa7ea0fd72a7d5b3070f74a53619f8b73bcc4e4f4697c6dab65b1410fef999d2f03bbb9dd355810576c6ea75e6e8d48f7c7989e24cba8f568644
7
- data.tar.gz: 73960b3ec6ad32a0435a3f2e5c3bc1656a9628c057fd7c5a2e583920785e991532832a4db03aa02c2b4cfc9d3781f97da91cb1721e6a668c946269c86f679f8a
6
+ metadata.gz: 4a6337e2103ad9072deb477849f675038b0b4e38bb0b79b9ac4eb5078f0b7b4d033eba9a73359d0860af65dcbb9ec4c81da7a3cdbbef893071bcc20a9db6530f
7
+ data.tar.gz: 39a72589d0870324530b0a7179c9740aa2f73eb825c046b18c71ed26de0e5486c176f37c5f07842a9d7ba1af74ef60d92ad39de5a6ac478c1baef76b1f3c3add
@@ -1,6 +1,6 @@
1
1
  require 'thegarage/gitx/version'
2
- require 'thegarage/gitx/string_extensions'
3
- require 'thegarage/gitx/thor_extensions'
2
+ require 'thegarage/gitx/extensions/string'
3
+ require 'thegarage/gitx/extensions/thor'
4
4
 
5
5
  module Thegarage
6
6
  module Gitx
@@ -10,7 +10,7 @@ module Thegarage
10
10
  desc 'integrate', 'integrate the current branch into one of the aggregate development branches (default = staging)'
11
11
  def integrate(target_branch = 'staging')
12
12
  branch = current_branch.name
13
- assert_integratable_branch!(branch, target_branch)
13
+ assert_aggregate_branch!(target_branch)
14
14
 
15
15
  UpdateCommand.new.update
16
16
 
@@ -19,7 +19,8 @@ module Thegarage
19
19
  say "into "
20
20
  say target_branch, :green
21
21
 
22
- refresh_branch_from_remote target_branch
22
+ create_remote_branch(target_branch) unless remote_branch_exists?(target_branch)
23
+ refresh_branch_from_remote(target_branch)
23
24
  run_cmd "git merge #{branch}"
24
25
  run_cmd "git push origin HEAD"
25
26
  checkout_branch branch
@@ -27,17 +28,25 @@ module Thegarage
27
28
 
28
29
  private
29
30
 
30
- def assert_integratable_branch!(branch, target_branch)
31
- assert_not_protected_branch!(branch, 'integrate') unless aggregate_branch?(target_branch)
32
- raise "Only aggregate branches are allowed for integration: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(target_branch) || target_branch == Thegarage::Gitx::BASE_BRANCH
31
+ def assert_aggregate_branch!(target_branch)
32
+ fail "Invalid aggregate branch: #{target_branch} must be one of supported aggregate branches #{AGGREGATE_BRANCHES}" unless aggregate_branch?(target_branch)
33
33
  end
34
34
 
35
35
  # nuke local branch and pull fresh version from remote repo
36
36
  def refresh_branch_from_remote(target_branch)
37
- run_cmd "git branch -D #{target_branch}", :allow_failure => true
38
37
  run_cmd "git fetch origin"
38
+ run_cmd "git branch -D #{target_branch}", :allow_failure => true
39
39
  checkout_branch target_branch
40
40
  end
41
+
42
+ def remote_branch_exists?(target_branch)
43
+ repo.branches.each_name(:remote).include?("origin/#{target_branch}")
44
+ end
45
+
46
+ def create_remote_branch(target_branch)
47
+ repo.create_branch(target_branch, Thegarage::Gitx::BASE_BRANCH)
48
+ run_cmd "git push origin #{target_branch}:#{target_branch}"
49
+ end
41
50
  end
42
51
  end
43
52
  end
@@ -17,7 +17,7 @@ module Thegarage
17
17
 
18
18
  checkout_branch Thegarage::Gitx::BASE_BRANCH
19
19
  run_cmd 'git pull'
20
- repo.create_branch branch_name, 'master'
20
+ repo.create_branch branch_name, Thegarage::Gitx::BASE_BRANCH
21
21
  checkout_branch branch_name
22
22
  end
23
23
 
@@ -1,5 +1,5 @@
1
1
  module Thegarage
2
2
  module Gitx
3
- VERSION = '2.4.1'
3
+ VERSION = '2.4.2'
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
2
+ Coveralls.wear! do
3
+ ::SimpleCov.add_filter 'spec'
4
+ ::SimpleCov.add_filter 'lib/thegarage/gitx/extensions'
5
+ end
3
6
  require 'rubygems'
4
7
  require 'bundler/setup'
5
8
 
@@ -10,10 +10,13 @@ describe Thegarage::Gitx::Cli::IntegrateCommand do
10
10
  }
11
11
  end
12
12
  let(:cli) { Thegarage::Gitx::Cli::IntegrateCommand.new(args, options, config) }
13
- let(:branch) { double('fake branch', name: 'feature-branch') }
13
+ let(:current_branch) { double('fake branch', name: 'feature-branch', head?: true) }
14
+ let(:repo) { cli.send(:repo) }
15
+ let(:remote_branch_names) { [] }
14
16
 
15
17
  before do
16
- allow(cli).to receive(:current_branch).and_return(branch)
18
+ allow(cli).to receive(:current_branch).and_return(current_branch)
19
+ allow(repo).to receive(:branches).and_return(double(each_name: remote_branch_names))
17
20
  end
18
21
 
19
22
  describe '#integrate' do
@@ -21,12 +24,13 @@ describe Thegarage::Gitx::Cli::IntegrateCommand do
21
24
  before do
22
25
  allow(Thegarage::Gitx::Cli::UpdateCommand).to receive(:new).and_return(fake_update_command)
23
26
  end
24
- context 'when target branch is ommitted' do
27
+ context 'when target branch is ommitted and remote branch exists' do
28
+ let(:remote_branch_names) { ['origin/staging'] }
25
29
  before do
26
30
  expect(fake_update_command).to receive(:update)
27
31
 
28
- expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
29
32
  expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
33
+ expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
30
34
  expect(cli).to receive(:run_cmd).with("git checkout staging").ordered
31
35
  expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
32
36
  expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
@@ -38,12 +42,35 @@ describe Thegarage::Gitx::Cli::IntegrateCommand do
38
42
  should meet_expectations
39
43
  end
40
44
  end
41
- context 'when target branch == prototype' do
45
+ context 'when staging branch does not exist remotely' do
46
+ let(:remote_branch_names) { [] }
47
+ before do
48
+ expect(fake_update_command).to receive(:update)
49
+
50
+ expect(repo).to receive(:create_branch).with('staging', 'master')
51
+
52
+ expect(cli).to receive(:run_cmd).with('git push origin staging:staging').ordered
53
+
54
+ expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
55
+ expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
56
+ expect(cli).to receive(:run_cmd).with("git checkout staging").ordered
57
+ expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
58
+ expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
59
+ expect(cli).to receive(:run_cmd).with("git checkout feature-branch").ordered
60
+
61
+ cli.integrate
62
+ end
63
+ it 'creates remote aggregate branch' do
64
+ should meet_expectations
65
+ end
66
+ end
67
+ context 'when target branch == prototype and remote branch exists' do
68
+ let(:remote_branch_names) { ['origin/prototype'] }
42
69
  before do
43
70
  expect(fake_update_command).to receive(:update)
44
71
 
45
- expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
46
72
  expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
73
+ expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
47
74
  expect(cli).to receive(:run_cmd).with("git checkout prototype").ordered
48
75
  expect(cli).to receive(:run_cmd).with("git merge feature-branch").ordered
49
76
  expect(cli).to receive(:run_cmd).with("git push origin HEAD").ordered
@@ -55,10 +82,9 @@ describe Thegarage::Gitx::Cli::IntegrateCommand do
55
82
  should meet_expectations
56
83
  end
57
84
  end
58
- context 'when target branch != staging || prototype' do
85
+ context 'when target branch is not an aggregate branch' do
59
86
  it 'raises an error' do
60
-
61
- expect { cli.integrate('some-other-branch') }.to raise_error(/Only aggregate branches are allowed for integration/)
87
+ expect { cli.integrate('some-other-branch') }.to raise_error(/Invalid aggregate branch: some-other-branch must be one of supported aggregate branches/)
62
88
  end
63
89
  end
64
90
  end
@@ -101,5 +101,65 @@ describe Thegarage::Gitx::Cli::NukeCommand do
101
101
  expect { cli.nuke('prototype') }.to raise_error(/No known good tag found for branch/)
102
102
  end
103
103
  end
104
+ context 'when database migrations exist and user cancels operation' do
105
+ let(:buildtag) { 'build-master-2013-10-01-01' }
106
+ let(:good_branch) { 'master' }
107
+ let(:bad_branch) { 'prototype' }
108
+ let(:migrations) do
109
+ %w( db/migrate/20140715194946_create_users.rb db/migrate/20140730063034_update_user_account.rb ).join("\n")
110
+ end
111
+ before do
112
+ FileUtils.mkdir_p('db/migrate')
113
+
114
+ expect(cli).to receive(:current_build_tag).with(good_branch).and_return(buildtag)
115
+
116
+ expect(cli).to receive(:ask).and_return(good_branch)
117
+ expect(cli).to receive(:yes?).with('Reset prototype to build-master-2013-10-01-01? (y/n)', :green).and_return(true)
118
+ expect(cli).to receive(:run_cmd).with("git diff build-master-2013-10-01-01...prototype --name-only db/migrate").and_return(migrations)
119
+ expect(cli).to receive(:yes?).with('Are you sure you want to nuke prototype? (y/n) ', :green).and_return(false)
120
+
121
+ cli.nuke 'prototype'
122
+ end
123
+ after do
124
+ FileUtils.rm_rf('db/migrate')
125
+ end
126
+ it 'prompts for nuke confirmation' do
127
+ should meet_expectations
128
+ end
129
+ end
130
+ context 'when database migrations exist and user approves operation' do
131
+ let(:buildtag) { 'build-master-2013-10-01-01' }
132
+ let(:good_branch) { 'master' }
133
+ let(:bad_branch) { 'prototype' }
134
+ let(:migrations) do
135
+ %w( db/migrate/20140715194946_create_users.rb db/migrate/20140730063034_update_user_account.rb ).join("\n")
136
+ end
137
+ before do
138
+ FileUtils.mkdir_p('db/migrate')
139
+
140
+ expect(cli).to receive(:current_build_tag).with(good_branch).and_return(buildtag)
141
+
142
+ expect(cli).to receive(:ask).and_return(good_branch)
143
+ expect(cli).to receive(:yes?).with('Reset prototype to build-master-2013-10-01-01? (y/n)', :green).and_return(true)
144
+ expect(cli).to receive(:run_cmd).with("git diff build-master-2013-10-01-01...prototype --name-only db/migrate").and_return(migrations)
145
+ expect(cli).to receive(:yes?).with('Are you sure you want to nuke prototype? (y/n) ', :green).and_return(true)
146
+
147
+ expect(cli).to receive(:run_cmd).with("git checkout master").ordered
148
+ expect(cli).to receive(:run_cmd).with("git branch -D prototype", allow_failure: true).ordered
149
+ expect(cli).to receive(:run_cmd).with("git push origin --delete prototype", allow_failure: true).ordered
150
+ expect(cli).to receive(:run_cmd).with("git checkout -b prototype build-master-2013-10-01-01").ordered
151
+ expect(cli).to receive(:run_cmd).with("git push origin prototype").ordered
152
+ expect(cli).to receive(:run_cmd).with("git branch --set-upstream-to origin/prototype").ordered
153
+ expect(cli).to receive(:run_cmd).with("git checkout master").ordered
154
+
155
+ cli.nuke 'prototype'
156
+ end
157
+ after do
158
+ FileUtils.rm_rf('db/migrate')
159
+ end
160
+ it 'prompts for nuke confirmation' do
161
+ should meet_expectations
162
+ end
163
+ end
104
164
  end
105
165
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thegarage-gitx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-18 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -271,8 +271,8 @@ files:
271
271
  - lib/thegarage/gitx/cli/start_command.rb
272
272
  - lib/thegarage/gitx/cli/track_command.rb
273
273
  - lib/thegarage/gitx/cli/update_command.rb
274
- - lib/thegarage/gitx/string_extensions.rb
275
- - lib/thegarage/gitx/thor_extensions.rb
274
+ - lib/thegarage/gitx/extensions/string.rb
275
+ - lib/thegarage/gitx/extensions/thor.rb
276
276
  - lib/thegarage/gitx/version.rb
277
277
  - spec/fixtures/vcr_cassettes/pull_request_does_exist.yml
278
278
  - spec/fixtures/vcr_cassettes/pull_request_does_not_exist.yml