socialcast-git-extensions 3.0.7 → 3.0.8

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.
@@ -128,15 +128,16 @@ module Socialcast
128
128
  good_branch = options[:destination] || ask("What branch do you want to reset #{bad_branch} to? (default: #{default_good_branch})")
129
129
  good_branch = default_good_branch if good_branch.length == 0
130
130
  good_branch = "last_known_good_#{good_branch}" unless good_branch.starts_with?('last_known_good_')
131
+
131
132
  removed_branches = reset_branch(bad_branch, good_branch)
132
- reset_branch("last_known_good_#{bad_branch}", good_branch) unless "last_known_good_#{bad_branch}" == good_branch
133
+ reset_branch("last_known_good_#{bad_branch}", good_branch)
133
134
 
134
135
  message_parts = []
135
136
  message_parts << "#worklog resetting #{bad_branch} branch to #{good_branch} #scgitx"
136
137
  if removed_branches.any?
137
138
  message_parts << ""
138
139
  message_parts << "the following branches were affected:"
139
- messgae_parts += removed_branches.map{|b| '* ' + b}
140
+ message_parts += removed_branches.map{|b| ['*', b].join(' ')}
140
141
  end
141
142
  post message_parts.join("\n")
142
143
  end
@@ -149,8 +150,8 @@ module Socialcast
149
150
  return unless yes?("Release #{branch} to production? (y/n)", :green)
150
151
 
151
152
  update
152
- run_cmd 'git checkout master'
153
- run_cmd 'git pull origin master'
153
+ run_cmd "git checkout #{Socialcast::Gitx::BASE_BRANCH}"
154
+ run_cmd "git pull origin #{Socialcast::Gitx::BASE_BRANCH}"
154
155
  run_cmd "git pull . #{branch}"
155
156
  run_cmd "git push origin HEAD"
156
157
  integrate_branch('master', 'staging')
@@ -40,23 +40,24 @@ module Socialcast
40
40
  end
41
41
 
42
42
  # reset the specified branch to the same set of commits as the destination branch
43
- # used to revert commits on aggregate branches back to a known good state
43
+ # reverts commits on aggregate branches back to a known good state
44
+ # returns list of branches that were removed
44
45
  def reset_branch(branch, head_branch)
45
- raise "Can not reset #{branch} to #{head_branch}" if branch == head_branch
46
+ return [] if branch == head_branch
46
47
  raise "Only aggregate branches are allowed to be reset: #{AGGREGATE_BRANCHES}" unless aggregate_branch?(branch)
47
48
  say "Resetting "
48
49
  say "#{branch} ", :green
49
50
  say "branch to "
50
51
  say head_branch, :green
51
52
 
52
- run_cmd "git checkout #{head_branch}"
53
- run_cmd "git pull"
53
+ run_cmd "git checkout #{Socialcast::Gitx::BASE_BRANCH}"
54
+ refresh_branch_from_remote head_branch
54
55
  removed_branches = branches(:remote => true, :merged => "origin/#{branch}") - branches(:remote => true, :merged => "origin/#{head_branch}")
55
56
  run_cmd "git branch -D #{branch}" rescue nil
56
57
  run_cmd "git push origin --delete #{branch}" rescue nil
57
58
  run_cmd "git checkout -b #{branch}"
58
59
  run_cmd "grb publish #{branch}"
59
- run_cmd "git checkout #{head_branch}"
60
+ run_cmd "git checkout #{Socialcast::Gitx::BASE_BRANCH}"
60
61
 
61
62
  removed_branches
62
63
  end
@@ -71,14 +72,19 @@ module Socialcast
71
72
  say "into "
72
73
  say destination_branch, :green
73
74
 
74
- run_cmd "git branch -D #{destination_branch}"
75
- run_cmd "git checkout #{destination_branch}"
76
- run_cmd "git pull origin #{destination_branch}"
75
+ refresh_branch_from_remote destination_branch
77
76
  run_cmd "git pull . #{branch}"
78
77
  run_cmd "git push origin HEAD"
79
78
  run_cmd "git checkout #{branch}"
80
79
  end
81
80
 
81
+ # nuke local branch and pull fresh version from remote repo
82
+ def refresh_branch_from_remote(destination_branch)
83
+ run_cmd "git branch -D #{destination_branch}" rescue nil
84
+ run_cmd "git checkout #{destination_branch}"
85
+ run_cmd "git pull origin #{destination_branch}"
86
+ end
87
+
82
88
  def aggregate_branch?(branch)
83
89
  AGGREGATE_BRANCHES.include?(branch) || branch.starts_with?('last_known_good')
84
90
  end
@@ -6,6 +6,6 @@ class String
6
6
  alias :dedent :undent
7
7
 
8
8
  def starts_with?(characters)
9
- self.match(/^#{characters}/) ? true : false
9
+ !!self.match(/^#{characters}/)
10
10
  end
11
11
  end
@@ -1,5 +1,5 @@
1
1
  module Socialcast
2
2
  module Gitx
3
- VERSION = "3.0.7"
3
+ VERSION = "3.0.8"
4
4
  end
5
5
  end
@@ -156,26 +156,33 @@ describe Socialcast::Gitx::CLI do
156
156
  describe '#nuke' do
157
157
  context 'when target branch == prototype and --destination == master' do
158
158
  before do
159
- Socialcast::Gitx::CLI.any_instance.should_receive(:post).with("#worklog resetting prototype branch to last_known_good_master #scgitx")
159
+ prototype_branches = %w( dev-foo dev-bar )
160
+ master_branches = %w( dev-foo )
161
+ Socialcast::Gitx::CLI.any_instance.should_receive(:branches).and_return(prototype_branches, master_branches, prototype_branches, master_branches)
162
+ Socialcast::Gitx::CLI.any_instance.should_receive(:post).with("#worklog resetting prototype branch to last_known_good_master #scgitx\n\nthe following branches were affected:\n* dev-bar")
160
163
  Socialcast::Gitx::CLI.start ['nuke', 'prototype', '--destination', 'master']
161
164
  end
162
165
  it 'should publish message into socialcast' do end # see expectations
163
166
  it 'should run expected commands' do
164
167
  Socialcast::Gitx::CLI.stubbed_executed_commands.should == [
168
+ "git checkout master",
169
+ "git branch -D last_known_good_master",
165
170
  "git checkout last_known_good_master",
166
- "git pull",
171
+ "git pull origin last_known_good_master",
167
172
  "git branch -D prototype",
168
173
  "git push origin --delete prototype",
169
174
  "git checkout -b prototype",
170
175
  "grb publish prototype",
176
+ "git checkout master",
177
+ "git checkout master",
178
+ "git branch -D last_known_good_master",
171
179
  "git checkout last_known_good_master",
172
- "git checkout last_known_good_master",
173
- "git pull",
180
+ "git pull origin last_known_good_master",
174
181
  "git branch -D last_known_good_prototype",
175
182
  "git push origin --delete last_known_good_prototype",
176
183
  "git checkout -b last_known_good_prototype",
177
184
  "grb publish last_known_good_prototype",
178
- "git checkout last_known_good_master"
185
+ "git checkout master"
179
186
  ]
180
187
  end
181
188
  end
@@ -185,13 +192,15 @@ describe Socialcast::Gitx::CLI do
185
192
  end
186
193
  it 'should run expected commands' do
187
194
  Socialcast::Gitx::CLI.stubbed_executed_commands.should == [
195
+ "git checkout master",
196
+ "git branch -D last_known_good_staging",
188
197
  "git checkout last_known_good_staging",
189
- "git pull",
198
+ "git pull origin last_known_good_staging",
190
199
  "git branch -D staging",
191
200
  "git push origin --delete staging",
192
201
  "git checkout -b staging",
193
202
  "grb publish staging",
194
- "git checkout last_known_good_staging"
203
+ "git checkout master"
195
204
  ]
196
205
  end
197
206
  end
@@ -202,13 +211,15 @@ describe Socialcast::Gitx::CLI do
202
211
  end
203
212
  it 'defaults to last_known_good_prototype and should run expected commands' do
204
213
  Socialcast::Gitx::CLI.stubbed_executed_commands.should == [
214
+ "git checkout master",
215
+ "git branch -D last_known_good_prototype",
205
216
  "git checkout last_known_good_prototype",
206
- "git pull",
217
+ "git pull origin last_known_good_prototype",
207
218
  "git branch -D prototype",
208
219
  "git push origin --delete prototype",
209
220
  "git checkout -b prototype",
210
221
  "grb publish prototype",
211
- "git checkout last_known_good_prototype"
222
+ "git checkout master"
212
223
  ]
213
224
  end
214
225
  end
@@ -219,20 +230,24 @@ describe Socialcast::Gitx::CLI do
219
230
  end
220
231
  it 'should run expected commands' do
221
232
  Socialcast::Gitx::CLI.stubbed_executed_commands.should == [
233
+ "git checkout master",
234
+ "git branch -D last_known_good_master",
222
235
  "git checkout last_known_good_master",
223
- "git pull",
236
+ "git pull origin last_known_good_master",
224
237
  "git branch -D prototype",
225
238
  "git push origin --delete prototype",
226
239
  "git checkout -b prototype",
227
240
  "grb publish prototype",
241
+ "git checkout master",
242
+ "git checkout master",
243
+ "git branch -D last_known_good_master",
228
244
  "git checkout last_known_good_master",
229
- "git checkout last_known_good_master",
230
- "git pull",
245
+ "git pull origin last_known_good_master",
231
246
  "git branch -D last_known_good_prototype",
232
247
  "git push origin --delete last_known_good_prototype",
233
248
  "git checkout -b last_known_good_prototype",
234
249
  "grb publish last_known_good_prototype",
235
- "git checkout last_known_good_master"
250
+ "git checkout master"
236
251
  ]
237
252
  end
238
253
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast-git-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -230,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
230
  version: '0'
231
231
  segments:
232
232
  - 0
233
- hash: -1512186750897379892
233
+ hash: 874256379826639527
234
234
  required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  none: false
236
236
  requirements:
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  segments:
241
241
  - 0
242
- hash: -1512186750897379892
242
+ hash: 874256379826639527
243
243
  requirements: []
244
244
  rubyforge_project: socialcast-git-extensions
245
245
  rubygems_version: 1.8.24