octopolo 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MDVhMDU0NWZiZDc1NmNkYTNjOWM3Y2I2MTM3ZmEzMjQwOGQ4YTUwZQ==
4
+ MDdlNGEyM2U2YzFhNWM3YzM3NDExN2M4MTQxNTJjNTVlODRmNjQ1OA==
5
5
  data.tar.gz: !binary |-
6
- YmEzOGViMTQ2ZDA0YjljZTFjZDM0YzEwOTNhM2UwYjBiMDdhYWE2Zg==
6
+ ZDEzZmY5ZWQ5MmYwZTQ2ZDE2MzU3M2ZlYzdjODE3YTc3MTY4YTA1ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- Nzc2OTI0NWEwYTIzYTBiOTRjZDk1MjI2MWUxNjY4OGJiNDI5NTg1MzFiMTI0
10
- MjJiNDI1YWIxNDRkNDJmNjgwMzI2ZTczNWZiNDczYjZlM2JhNjE3YTZjZmZm
11
- OTJjYzg2N2JkMzRmNWFmZDcwZTA2ZTRjOGJlMzQ5Y2MyOTVjZmY=
9
+ OTZiMjlkZGYyZjRlZWQ3YzVmZDcyNTZkMDhkM2YyZjRlMWFhZDEyNjY2MzUw
10
+ ZjhlMTliZGNkODJjZDkxMGVjZTlkNWMyZGRmMjEwYTg0YThmMDY4MTFiMzg2
11
+ MmVmMGVkNjc0NDRlNzM4NzAyYjNmYmEyN2MyMmNhZjFlMGQxMWI=
12
12
  data.tar.gz: !binary |-
13
- OTcxMWIwNDFkOWMwZDBkNTk4YjVlOWY2MmE1MmVjNTNmOWRmMWUwYzEyYjI3
14
- ODYxYmMyYjM5ZDdmMjkzOGZmOWJhNTYxZmZmMDVmNGIzNjYyODAyZDg2ODUy
15
- OTdmMzMyOGQ5NzdjNTM4YWFhMWU5NGVlNzY5YjUxZjgyODc0YTc=
13
+ NTExNGU4YTI5Mjc2NzRmOWM1OTc5NmZiMjVhNWIzNWQzN2RmYjgzMjRlNzQw
14
+ OThmNjhhODdkNjk2YTFkZTZhY2FiNzI4YjI4NDkxYmE5NzZhMmJlZDU2MDM1
15
+ M2QwOWQxOTJkMTMyYjUzZWRhMjYzNmQ0ZjExZmQ2MjA5Y2VlN2U=
data/CHANGELOG.markdown CHANGED
@@ -1,4 +1,17 @@
1
+ #### v0.3.4
2
+ * Adding delete flag to dated branch creation commands for non-interactive support
3
+
4
+ > Brian Bergstrom: Andy Fleener: https://github.com/sportngin/octopolo/pull/49
5
+
6
+ * Command Errors Should Not Be Rescued
7
+
8
+ > Brian Bergstrom: Andy Fleener: https://github.com/sportngin/octopolo/pull/47
9
+
1
10
  #### v0.3.3
11
+ * Errors from CLI commands should throw and exception
12
+
13
+ > Brian Bergstrom: Andy Fleener: https://github.com/sportngin/octopolo/pull/46
14
+
2
15
  #### v0.3.2
3
16
  * Add new autocomplete_commands toggle; fixes #34
4
17
 
data/lib/octopolo/cli.rb CHANGED
@@ -26,7 +26,7 @@ module Octopolo
26
26
  # and then perform it
27
27
  if Open3.respond_to?(:capture3)
28
28
  output, error, status = Open3.capture3(command)
29
- raise "exit_status=#{status.exitstatus}; stderr=#{error}" unless status.success?
29
+ raise "command=#{command}; exit_status=#{status.exitstatus}; stderr=#{error}" unless status.success?
30
30
  else
31
31
  # Only necessary as long as we use 1.8.7, which doesn't have Open3.capture3
32
32
  output = `#{command}`
@@ -36,8 +36,6 @@ module Octopolo
36
36
  say output if say_command
37
37
  # return the output of the command
38
38
  output
39
- rescue => e
40
- say "Unable to perform '#{command}': #{e.message}"
41
39
  end
42
40
 
43
41
  # Public: Perform the command, but do not print out the command
@@ -3,6 +3,11 @@ long_desc "Create a new deployable branch with today's date and remove the other
3
3
 
4
4
  Useful when we have changes in the current deployable branch that we wish to remove."
5
5
  command 'new-deployable' do |c|
6
- require_relative '../scripts/new_deployable'
7
- c.action { Octopolo::Scripts::NewDeployable.new.execute }
6
+ c.switch :delete_old_branches, :default_value => false, :desc => "Should old deployable branches be deleted?", :negatable => false
7
+
8
+ c.action do |global_options, options, args|
9
+ require_relative '../scripts/new_deployable'
10
+ options = global_options.merge(options)
11
+ Octopolo::Scripts::NewDeployable.new.execute(options)
12
+ end
8
13
  end
@@ -3,6 +3,11 @@ long_desc "Create a new staging branch with today's date and remove the others.
3
3
 
4
4
  Useful when we have changes in the current staging branch that we wish to remove."
5
5
  command 'new-staging' do |c|
6
- require_relative '../scripts/new_staging'
7
- c.action { Octopolo::Scripts::NewStaging.new.execute }
6
+ c.switch :delete_old_branches, :default_value => false, :desc => "Should old staging branches be deleted?", :negatable => false
7
+
8
+ c.action do |global_options, options, args|
9
+ require_relative '../scripts/new_staging'
10
+ options = global_options.merge(options)
11
+ Octopolo::Scripts::NewStaging.new.execute(options)
12
+ end
8
13
  end
@@ -9,20 +9,24 @@ module Octopolo
9
9
  include GitWrapper
10
10
 
11
11
  attr_accessor :branch_type
12
+ attr_accessor :should_delete_old_branches
12
13
 
13
14
  # Public: Initialize a new instance of DatedBranchCreator
14
15
  #
15
16
  # branch_type - Name of the type of branch (e.g., staging or deployable)
16
- def initialize(branch_type)
17
+ # should_delete_old_branches - Flag to delete old branches of the given type.
18
+ def initialize(branch_type, should_delete_old_branches=false)
17
19
  self.branch_type = branch_type
20
+ self.should_delete_old_branches = should_delete_old_branches
18
21
  end
19
22
 
20
23
  # Public: Create a new branch of the given type for today's date
21
24
  #
22
25
  # branch_type - Name of the type of branch (e.g., staging or deployable)
26
+ # should_delete_old_branches - Flag to delete old branches of the given type.
23
27
  #
24
28
  # Returns a DatedBranchCreator
25
- def self.perform(branch_type)
29
+ def self.perform(branch_type, should_delete_old_branches=false)
26
30
  new(branch_type).tap do |creator|
27
31
  creator.perform
28
32
  end
@@ -56,7 +60,10 @@ module Octopolo
56
60
 
57
61
  # Public: If necessary, and if user opts to, delete old branches of its type
58
62
  def delete_old_branches
59
- if extra_branches.any? && cli.ask_boolean("Do you want to delete the old #{branch_type} branch(es)? (#{extra_branches.join(", ")})")
63
+ return unless extra_branches.any?
64
+ should_delete = should_delete_old_branches || cli.ask_boolean("Do you want to delete the old #{branch_type} branch(es)? (#{extra_branches.join(", ")})")
65
+
66
+ if should_delete
60
67
  extra_branches.each do |extra|
61
68
  Git.delete_branch(extra)
62
69
  end
data/lib/octopolo/git.rb CHANGED
@@ -67,10 +67,11 @@ module Octopolo
67
67
  # Public: Check out the given branch name
68
68
  #
69
69
  # branch_name - The name of the branch to check out
70
- def self.check_out branch_name
70
+ # do_after_pull - Should a pull be done after checkout?
71
+ def self.check_out(branch_name, do_after_pull=true)
71
72
  fetch
72
73
  perform "checkout #{branch_name}"
73
- pull
74
+ pull if do_after_pull
74
75
  unless current_branch == branch_name
75
76
  raise CheckoutFailed, "Failed to check out '#{branch_name}'"
76
77
  end
@@ -87,7 +88,7 @@ module Octopolo
87
88
  def self.new_branch(new_branch_name, source_branch_name)
88
89
  fetch
89
90
  perform("branch --no-track #{new_branch_name} origin/#{source_branch_name}")
90
- check_out new_branch_name
91
+ check_out(new_branch_name, false)
91
92
  perform("push --set-upstream origin #{new_branch_name}")
92
93
  end
93
94
 
@@ -5,8 +5,8 @@ module Octopolo
5
5
  module Scripts
6
6
  class NewDeployable
7
7
 
8
- def execute
9
- DatedBranchCreator.perform Git::DEPLOYABLE_PREFIX
8
+ def execute(options={:delete_old_branches => false})
9
+ DatedBranchCreator.perform(Git::DEPLOYABLE_PREFIX, options[:delete_old_branches])
10
10
  end
11
11
  end
12
12
  end
@@ -6,8 +6,8 @@ module Octopolo
6
6
  class NewStaging
7
7
  include CLIWrapper
8
8
 
9
- def execute
10
- DatedBranchCreator.perform Git::STAGING_PREFIX
9
+ def execute(options={:delete_old_branches => false})
10
+ DatedBranchCreator.perform(Git::STAGING_PREFIX, options[:delete_old_branches])
11
11
  end
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module Octopolo
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
@@ -28,18 +28,17 @@ module Octopolo
28
28
  subject.perform(command).should == result
29
29
  end
30
30
 
31
- it "should handle exception gracefully" do
31
+ it "should raise exception" do
32
32
  subject.should_receive(:say).with(command)
33
33
  Open3.should_receive(:capture3).with(command).and_raise(exception_message)
34
- subject.should_receive(:say).with("Unable to perform '#{command}': #{exception_message}")
35
- subject.perform(command).should be_nil
34
+ expect { subject.perform(command) }.to raise_error(RuntimeError, exception_message)
36
35
  end
37
36
 
38
- it "should handle errors gracefully" do
37
+ it "should raise errors from command" do
39
38
  subject.should_receive(:say).with(command)
40
39
  Open3.should_receive(:capture3).with(command).and_return([result, "kaboom", status_error])
41
- subject.should_receive(:say).with("Unable to perform '#{command}': exit_status=1; stderr=kaboom")
42
- subject.perform(command).should be_nil
40
+ expect { subject.perform(command) }
41
+ .to raise_error(RuntimeError, "command=#{command}; exit_status=1; stderr=kaboom")
43
42
  end
44
43
 
45
44
  it "should not speak the command if told not to" do
@@ -112,6 +112,21 @@ module Octopolo
112
112
  cli.should_not_receive(:perform)
113
113
  subject.delete_old_branches
114
114
  end
115
+
116
+ context "delete flag" do
117
+ before do
118
+ subject.stub(extra_branches: extras)
119
+ subject.should_delete_old_branches = true
120
+ end
121
+
122
+ it "deletes these branches non-interactively" do
123
+ cli.should_not_receive(:ask_boolean).with(message)
124
+ extras.each do |extra|
125
+ Git.should_receive(:delete_branch).with(extra)
126
+ end
127
+ subject.delete_old_branches
128
+ end
129
+ end
115
130
  end
116
131
  end
117
132
 
@@ -79,6 +79,14 @@ module Octopolo
79
79
  Git.check_out name
80
80
  end
81
81
 
82
+ it "checks out the given branch name without after pull" do
83
+ Git.should_receive(:fetch)
84
+ Git.should_receive(:perform).with("checkout #{name}")
85
+ Git.should_not_receive(:pull)
86
+ Git.should_receive(:current_branch) { name }
87
+ Git.check_out(name, false)
88
+ end
89
+
82
90
  it "raises an exception if the current branch is not the requested branch afterward" do
83
91
  Git.should_receive(:fetch)
84
92
  Git.should_receive(:perform)
@@ -345,7 +353,7 @@ module Octopolo
345
353
  it "creates and pushes a new branch from the source branch" do
346
354
  Git.should_receive(:fetch)
347
355
  Git.should_receive(:perform).with("branch --no-track #{new_branch_name} origin/#{source_branch_name}")
348
- Git.should_receive(:check_out).with(new_branch_name)
356
+ Git.should_receive(:check_out).with(new_branch_name, false)
349
357
  Git.should_receive(:perform).with("push --set-upstream origin #{new_branch_name}")
350
358
 
351
359
  Git.new_branch(new_branch_name, source_branch_name)
@@ -7,10 +7,14 @@ module Octopolo
7
7
  subject { NewDeployable.new }
8
8
 
9
9
  context "#execute" do
10
- it "delegates the work to DatedBranchCreator" do
11
- DatedBranchCreator.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX)
10
+ it "delegates the work to DatedBranchCreator with default delete flag" do
11
+ DatedBranchCreator.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, false)
12
12
  subject.execute
13
13
  end
14
+ it "delegates the work to DatedBranchCreator with delete flag" do
15
+ DatedBranchCreator.should_receive(:perform).with(Git::DEPLOYABLE_PREFIX, true)
16
+ subject.execute(:delete_old_branches => true)
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -7,10 +7,14 @@ module Octopolo
7
7
  subject { NewStaging.new }
8
8
 
9
9
  context "#execute" do
10
- it "delegates to DatedBranchCreator to create the branch" do
11
- DatedBranchCreator.should_receive(:perform).with(Git::STAGING_PREFIX)
10
+ it "delegates to DatedBranchCreator to create the branch with default delete flag" do
11
+ DatedBranchCreator.should_receive(:perform).with(Git::STAGING_PREFIX, false)
12
12
  subject.execute
13
13
  end
14
+ it "delegates to DatedBranchCreator to create the branch with delete flag" do
15
+ DatedBranchCreator.should_receive(:perform).with(Git::STAGING_PREFIX, true)
16
+ subject.execute(:delete_old_branches => true)
17
+ end
14
18
  end
15
19
  end
16
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopolo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-23 00:00:00.000000000 Z
12
+ date: 2015-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake