thegarage-gitx 2.5.0.beta2 → 2.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a11b17f13c6a98af5bbd1415580d1796c13c542
4
- data.tar.gz: 20029e4cac935a0c8779c62e7614b4be3c247549
3
+ metadata.gz: b23514b77454d12bf5c3f10fb8631e81c6549be7
4
+ data.tar.gz: 2d6ccdbb734236b9408376baf3a2c4d72c3aac48
5
5
  SHA512:
6
- metadata.gz: 3b86cc43dc22460ff06dcd817472b345448876ef403dc7ea715f566f5ed134e190470171d51a468aace18f7e9465d15aea22c5498f76673f9085bc857d7bab36
7
- data.tar.gz: 87ee27377d2f9fe9069561aafe61bbe0cf2502c9f6c9376b39548b163ba85b410b7dc4fced66326ac2ca341da298de61ccf9b5f22086bb9c735abf1876a07e19
6
+ metadata.gz: 7373518508bcba2cbbb5f4714230180f7788a13f6c137a6ef6d64aa423dd1330339ad7d28e6fdb60240f2cfd4f378615990e43289e5becec34748592d8c97881
7
+ data.tar.gz: 981c8c8264d3111b89298003e26dbbc0c4ba245dc33113d8df395b2cf759113bb446bcb45a9239dedaf00316e63da58cd7323852c92a95c61d295bc0e435c0c0
@@ -15,7 +15,7 @@ module Thegarage
15
15
  if options[:resume]
16
16
  resume
17
17
  else
18
- assert_integratable_branch!(branch, target_branch)
18
+ assert_aggregate_branch!(target_branch)
19
19
 
20
20
  UpdateCommand.new.update
21
21
 
@@ -24,7 +24,8 @@ module Thegarage
24
24
  say "into "
25
25
  say target_branch, :green
26
26
 
27
- refresh_branch_from_remote target_branch
27
+ create_remote_branch(target_branch) unless remote_branch_exists?(target_branch)
28
+ refresh_branch_from_remote(target_branch)
28
29
  merge_feature_branch branch
29
30
  run_cmd "git push origin HEAD"
30
31
  checkout_branch branch
@@ -33,15 +34,14 @@ module Thegarage
33
34
 
34
35
  private
35
36
 
36
- def assert_integratable_branch!(branch, target_branch)
37
- assert_not_protected_branch!(branch, 'integrate') unless aggregate_branch?(target_branch)
38
- raise "Only aggregate branches are allowed for integration: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(target_branch) || target_branch == Thegarage::Gitx::BASE_BRANCH
37
+ def assert_aggregate_branch!(target_branch)
38
+ fail "Invalid aggregate branch: #{target_branch} must be one of supported aggregate branches #{AGGREGATE_BRANCHES}" unless aggregate_branch?(target_branch)
39
39
  end
40
40
 
41
41
  # nuke local branch and pull fresh version from remote repo
42
42
  def refresh_branch_from_remote(target_branch)
43
- run_cmd "git branch -D #{target_branch}", :allow_failure => true
44
43
  run_cmd "git fetch origin"
44
+ run_cmd "git branch -D #{target_branch}", :allow_failure => true
45
45
  checkout_branch target_branch
46
46
  end
47
47
 
@@ -49,7 +49,7 @@ module Thegarage
49
49
  begin
50
50
  run_cmd "git merge #{branch}"
51
51
  rescue
52
- say "Merge Conflict Occurred. Please fix merge conflict and rerun command with --resume #{branch} flag"
52
+ say "Merge Conflict Occurred. Please fix merge conflict and rerun command with --resume #{branch} flag", :red
53
53
  exit
54
54
  end
55
55
  end
@@ -67,11 +67,20 @@ module Thegarage
67
67
  end
68
68
 
69
69
  def check_if_branch_exists?(branch)
70
- return true if local_branches.include?(branch)
70
+ local_branches.include?(branch)
71
71
  end
72
72
 
73
73
  def local_branches
74
- @local_branches ||= repo.branches.each_name(:local).to_a.map { |branch| branch }
74
+ @local_branches ||= repo.branches.each_name(:local).map { |branch| branch }
75
+ end
76
+
77
+ def remote_branch_exists?(target_branch)
78
+ repo.branches.each_name(:remote).include?("origin/#{target_branch}")
79
+ end
80
+
81
+ def create_remote_branch(target_branch)
82
+ repo.create_branch(target_branch, Thegarage::Gitx::BASE_BRANCH)
83
+ run_cmd "git push origin #{target_branch}:#{target_branch}"
75
84
  end
76
85
  end
77
86
  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.5.0.beta2'
3
+ VERSION = '2.5.0.beta3'
4
4
  end
5
5
  end
@@ -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
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,18 +82,18 @@ 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
  context 'when merge conflicts occur' do
91
+ let(:remote_branch_names) { ['origin/staging'] }
65
92
  before do
66
93
  expect(fake_update_command).to receive(:update)
67
94
 
68
- expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
69
95
  expect(cli).to receive(:run_cmd).with("git fetch origin").ordered
96
+ expect(cli).to receive(:run_cmd).with("git branch -D staging", allow_failure: true).ordered
70
97
  expect(cli).to receive(:run_cmd).with("git checkout staging").ordered
71
98
  expect(cli).to receive(:run_cmd).with("git merge feature-branch").and_raise('git merge feature-branch failed').ordered
72
99
  expect(cli).to receive(:exit).and_raise(SystemExit)
@@ -117,7 +144,6 @@ describe Thegarage::Gitx::Cli::IntegrateCommand do
117
144
  expect(cli).to receive(:run_cmd).with("git checkout my-feature-branch").ordered
118
145
 
119
146
  cli.integrate
120
- # expect { cli.integrate }
121
147
  end
122
148
  it 'raises error' do
123
149
  should meet_expectations
@@ -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.5.0.beta2
4
+ version: 2.5.0.beta3
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-19 00:00:00.000000000 Z
11
+ date: 2014-09-22 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