git_remote_branch 0.2.4 → 0.2.6
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.
- data/CHANGELOG +17 -0
- data/COPYING +18 -0
- data/README +39 -13
- data/Rakefile +2 -41
- data/TODO +8 -12
- data/bin/grb +10 -3
- data/lib/git_remote_branch.rb +62 -24
- data/lib/param_reader.rb +54 -22
- data/lib/version.rb +14 -0
- data/tasks/gem.rake +73 -0
- data/tasks/test.rake +21 -0
- data/test/functional/grb_test.rb +154 -0
- data/test/helpers/array_extensions.rb +14 -0
- data/test/helpers/dir_stack.rb +25 -0
- data/test/helpers/extractable.rb +63 -0
- data/test/helpers/git_helper.rb +33 -0
- data/test/helpers/more_assertions.rb +16 -0
- data/test/helpers/shoulda_functional_helpers.rb +106 -0
- data/test/helpers/shoulda_unit_helpers.rb +88 -0
- data/test/helpers/temp_dir_helper.rb +38 -0
- data/test/test_helper.rb +16 -8
- data/test/unit/git_remote_branch_test.rb +39 -0
- data/test/unit/param_reader_test.rb +261 -0
- data/vendor/capture_fu.rb +58 -0
- metadata +45 -8
- data/test/git_helper.rb +0 -57
@@ -0,0 +1,261 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
REGULAR_BRANCH_LISTING = <<-STR
|
4
|
+
other_user/master
|
5
|
+
* stubbed_current_branch
|
6
|
+
rubyforge
|
7
|
+
STR
|
8
|
+
|
9
|
+
BRANCH_LISTING_WHEN_NOT_ON_BRANCH = <<-STR
|
10
|
+
* (no branch)
|
11
|
+
other_user/master
|
12
|
+
master
|
13
|
+
rubyforge
|
14
|
+
STR
|
15
|
+
|
16
|
+
WHEN_NOT_ON_GIT_REPOSITORY = "fatal: Not a git repository\n"
|
17
|
+
|
18
|
+
class ParamReaderTest < Test::Unit::TestCase
|
19
|
+
include ShouldaUnitHelpers
|
20
|
+
|
21
|
+
context 'read_params' do
|
22
|
+
context "when on a valid branch" do
|
23
|
+
setup do
|
24
|
+
grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on a normal valid command without an origin" do
|
28
|
+
setup do
|
29
|
+
@p = grb.read_params %w{create the_branch}
|
30
|
+
end
|
31
|
+
|
32
|
+
should_set_action_to :create
|
33
|
+
should_set_branch_to 'the_branch'
|
34
|
+
should_set_origin_to 'origin'
|
35
|
+
should_set_current_branch_to 'stubbed_current_branch'
|
36
|
+
should_set_explain_to false
|
37
|
+
should_set_silent_to false
|
38
|
+
end
|
39
|
+
|
40
|
+
context "on a normal valid command" do
|
41
|
+
setup do
|
42
|
+
@p = grb.read_params %w{create the_branch the_origin}
|
43
|
+
end
|
44
|
+
|
45
|
+
should_set_action_to :create
|
46
|
+
should_set_branch_to 'the_branch'
|
47
|
+
should_set_origin_to 'the_origin'
|
48
|
+
should_set_current_branch_to 'stubbed_current_branch'
|
49
|
+
should_set_explain_to false
|
50
|
+
should_set_silent_to false
|
51
|
+
end
|
52
|
+
|
53
|
+
should_explain_with_current_branch 'stubbed_current_branch', "use real current branch"
|
54
|
+
|
55
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
56
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
57
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
58
|
+
|
59
|
+
context "understands the --silent parameter" do
|
60
|
+
context "at the beginning" do
|
61
|
+
setup do
|
62
|
+
@p = grb.read_params %w{--silent create some_branch some_origin}
|
63
|
+
end
|
64
|
+
should_set_silent_to true
|
65
|
+
should_set_action_to :create
|
66
|
+
should_set_branch_to 'some_branch'
|
67
|
+
should_set_origin_to 'some_origin'
|
68
|
+
end
|
69
|
+
|
70
|
+
context "at the end" do
|
71
|
+
setup do
|
72
|
+
@p = grb.read_params %w{create some_branch some_origin --silent}
|
73
|
+
end
|
74
|
+
should_set_silent_to true
|
75
|
+
should_set_action_to :create
|
76
|
+
should_set_branch_to 'some_branch'
|
77
|
+
should_set_origin_to 'some_origin'
|
78
|
+
end
|
79
|
+
|
80
|
+
context "in the freakin' middle" do
|
81
|
+
setup do
|
82
|
+
@p = grb.read_params %w{create --silent some_branch some_origin}
|
83
|
+
end
|
84
|
+
should_set_silent_to true
|
85
|
+
should_set_action_to :create
|
86
|
+
should_set_branch_to 'some_branch'
|
87
|
+
should_set_origin_to 'some_origin'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when on an invalid branch" do
|
93
|
+
setup do
|
94
|
+
grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
|
95
|
+
end
|
96
|
+
|
97
|
+
GitRemoteBranch::COMMANDS.each_key do |action|
|
98
|
+
context "running the '#{action}' command" do
|
99
|
+
setup do
|
100
|
+
@command = [action.to_s, 'branch_name']
|
101
|
+
end
|
102
|
+
|
103
|
+
context "raising an exception" do
|
104
|
+
setup do
|
105
|
+
begin
|
106
|
+
grb.read_params(@command)
|
107
|
+
rescue => @ex
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
should "raise an InvalidBranchError" do
|
112
|
+
assert_kind_of GitRemoteBranch::InvalidBranchError, @ex
|
113
|
+
end
|
114
|
+
|
115
|
+
should "give a clear error message" do
|
116
|
+
assert_match(/identify.*branch/, @ex.message)
|
117
|
+
end
|
118
|
+
|
119
|
+
should "display git's branch listing" do
|
120
|
+
assert_match(/\(no branch\)/, @ex.message)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
|
127
|
+
|
128
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
129
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
130
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when not on a git repository" do
|
134
|
+
setup do
|
135
|
+
grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
|
136
|
+
end
|
137
|
+
|
138
|
+
should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
|
139
|
+
|
140
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
141
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
142
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
143
|
+
|
144
|
+
GitRemoteBranch::COMMANDS.each_key do |action|
|
145
|
+
context "running the '#{action}' command" do
|
146
|
+
setup do
|
147
|
+
@command = [action.to_s, 'branch_name']
|
148
|
+
end
|
149
|
+
|
150
|
+
context "raising an exception" do
|
151
|
+
setup do
|
152
|
+
begin
|
153
|
+
grb.read_params(@command)
|
154
|
+
rescue => @ex
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
should "raise an NotOnGitRepositoryError" do
|
159
|
+
assert_kind_of GitRemoteBranch::NotOnGitRepositoryError, @ex
|
160
|
+
end
|
161
|
+
|
162
|
+
should "give a clear error message" do
|
163
|
+
assert_match(/fatal/, @ex.message)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'get_current_branch' do
|
172
|
+
context "when not on a git repository" do
|
173
|
+
setup do
|
174
|
+
grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
|
175
|
+
end
|
176
|
+
|
177
|
+
should "raise an exception" do
|
178
|
+
assert_raise(GitRemoteBranch::NotOnGitRepositoryError) { grb.get_current_branch }
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
context "when on an invalid branch" do
|
183
|
+
setup do
|
184
|
+
grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
|
185
|
+
end
|
186
|
+
|
187
|
+
should "raise an exception" do
|
188
|
+
assert_raise(GitRemoteBranch::InvalidBranchError) { grb.get_current_branch }
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when on a valid branch" do
|
193
|
+
setup do
|
194
|
+
grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
|
195
|
+
end
|
196
|
+
|
197
|
+
should "return the current branch name" do
|
198
|
+
assert_equal 'stubbed_current_branch', grb.get_current_branch
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'explain_mode!' do
|
204
|
+
context "when it receives an array beginning with 'explain'" do
|
205
|
+
setup do
|
206
|
+
@array = ['explain', 'create', 'some_branch']
|
207
|
+
end
|
208
|
+
|
209
|
+
should "return true" do
|
210
|
+
assert grb.explain_mode!(@array)
|
211
|
+
end
|
212
|
+
|
213
|
+
should 'accept symbol arrays as well' do
|
214
|
+
assert grb.explain_mode!( @array.map{|e| e.to_sym} )
|
215
|
+
end
|
216
|
+
|
217
|
+
should "remove 'explain' from the argument array" do
|
218
|
+
grb.explain_mode!(@array)
|
219
|
+
assert_equal ['create', 'some_branch'], @array
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "when it receives an array that doesn't begin with 'explain'" do
|
224
|
+
setup do
|
225
|
+
@array = ['create', 'some_branch']
|
226
|
+
end
|
227
|
+
|
228
|
+
should "return false" do
|
229
|
+
assert_false grb.explain_mode!(@array)
|
230
|
+
end
|
231
|
+
|
232
|
+
should "not modify the argument array" do
|
233
|
+
grb.explain_mode!(@array)
|
234
|
+
assert_equal ['create', 'some_branch'], @array
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'get_action' do
|
240
|
+
GitRemoteBranch::COMMANDS.each_pair do |cmd, params|
|
241
|
+
should "recognize all #{cmd} aliases" do
|
242
|
+
params[:aliases].each do |alias_|
|
243
|
+
assert cmd, grb.get_action(alias_)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
should 'return nil on unknown aliases' do
|
248
|
+
assert_nil grb.get_action('please_dont_create_an_alias_named_like_this')
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context 'get_origin' do
|
253
|
+
should "default to 'origin' when the param is nil" do
|
254
|
+
assert_equal 'origin', grb.get_origin(nil)
|
255
|
+
end
|
256
|
+
should "return the unchanged param if it's not nil" do
|
257
|
+
assert_equal 'someword', grb.get_origin('someword')
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module CaptureFu
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
|
4
|
+
def capture_output(&block)
|
5
|
+
real_out, real_err = $stdout, $stderr
|
6
|
+
result = fake_out = fake_err = nil
|
7
|
+
begin
|
8
|
+
fake_out, fake_err = Helpers::PipeStealer.new, Helpers::PipeStealer.new
|
9
|
+
$stdout, $stderr = fake_out, fake_err
|
10
|
+
result = yield
|
11
|
+
ensure
|
12
|
+
$stdout, $stderr = real_out, real_err
|
13
|
+
end
|
14
|
+
return result, fake_out.captured, fake_err.captured
|
15
|
+
end
|
16
|
+
|
17
|
+
# This first implementation is only intended for batch executions.
|
18
|
+
# You can't pipe stuff programmatically to the child process.
|
19
|
+
def capture_process_output(command)
|
20
|
+
|
21
|
+
#capture stderr in the same stream
|
22
|
+
command << ' 2>&1' unless Helpers.stderr_already_redirected(command)
|
23
|
+
|
24
|
+
out = `#{command}`
|
25
|
+
return $?.exitstatus, out
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
module Helpers
|
32
|
+
|
33
|
+
def self.stderr_already_redirected(command)
|
34
|
+
#Already redirected to stdout (valid for Windows)
|
35
|
+
return true if command =~ /2>&1\s*\Z/
|
36
|
+
|
37
|
+
#Redirected to /dev/null (this is clearly POSIX-dependent)
|
38
|
+
return true if command =~ /2>\/dev\/null\s*\Z/
|
39
|
+
|
40
|
+
return false
|
41
|
+
end
|
42
|
+
|
43
|
+
class PipeStealer < File
|
44
|
+
attr_reader :captured
|
45
|
+
def initialize
|
46
|
+
@captured = ''
|
47
|
+
end
|
48
|
+
def write(s)
|
49
|
+
@captured << s
|
50
|
+
end
|
51
|
+
def captured
|
52
|
+
return nil if @captured.empty?
|
53
|
+
@captured.dup
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end #Helper module
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_remote_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathieu Martin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2008-
|
13
|
+
date: 2008-08-06 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -32,15 +32,39 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
|
34
34
|
files:
|
35
|
-
-
|
36
|
-
- README
|
37
|
-
- TODO
|
35
|
+
- bin
|
38
36
|
- bin/grb
|
37
|
+
- CHANGELOG
|
38
|
+
- COPYING
|
39
|
+
- lib
|
39
40
|
- lib/git_remote_branch.rb
|
40
41
|
- lib/param_reader.rb
|
41
|
-
-
|
42
|
+
- lib/version.rb
|
43
|
+
- Rakefile
|
44
|
+
- README
|
45
|
+
- tasks
|
46
|
+
- tasks/gem.rake
|
47
|
+
- tasks/test.rake
|
48
|
+
- test
|
49
|
+
- test/functional
|
50
|
+
- test/functional/grb_test.rb
|
51
|
+
- test/helpers
|
52
|
+
- test/helpers/array_extensions.rb
|
53
|
+
- test/helpers/dir_stack.rb
|
54
|
+
- test/helpers/extractable.rb
|
55
|
+
- test/helpers/git_helper.rb
|
56
|
+
- test/helpers/more_assertions.rb
|
57
|
+
- test/helpers/shoulda_functional_helpers.rb
|
58
|
+
- test/helpers/shoulda_unit_helpers.rb
|
59
|
+
- test/helpers/temp_dir_helper.rb
|
42
60
|
- test/test_helper.rb
|
61
|
+
- test/unit
|
43
62
|
- test/unit/git_helper_test.rb
|
63
|
+
- test/unit/git_remote_branch_test.rb
|
64
|
+
- test/unit/param_reader_test.rb
|
65
|
+
- TODO
|
66
|
+
- vendor
|
67
|
+
- vendor/capture_fu.rb
|
44
68
|
has_rdoc: false
|
45
69
|
homepage: http://github.com/webmat/git_remote_branch
|
46
70
|
post_install_message:
|
@@ -62,12 +86,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
86
|
version:
|
63
87
|
requirements: []
|
64
88
|
|
65
|
-
rubyforge_project:
|
89
|
+
rubyforge_project: grb
|
66
90
|
rubygems_version: 1.2.0
|
67
91
|
signing_key:
|
68
92
|
specification_version: 2
|
69
93
|
summary: git_remote_branch eases the interaction with remote branches
|
70
94
|
test_files:
|
71
|
-
- test/
|
95
|
+
- test/functional
|
96
|
+
- test/functional/grb_test.rb
|
97
|
+
- test/helpers
|
98
|
+
- test/helpers/array_extensions.rb
|
99
|
+
- test/helpers/dir_stack.rb
|
100
|
+
- test/helpers/extractable.rb
|
101
|
+
- test/helpers/git_helper.rb
|
102
|
+
- test/helpers/more_assertions.rb
|
103
|
+
- test/helpers/shoulda_functional_helpers.rb
|
104
|
+
- test/helpers/shoulda_unit_helpers.rb
|
105
|
+
- test/helpers/temp_dir_helper.rb
|
72
106
|
- test/test_helper.rb
|
107
|
+
- test/unit
|
73
108
|
- test/unit/git_helper_test.rb
|
109
|
+
- test/unit/git_remote_branch_test.rb
|
110
|
+
- test/unit/param_reader_test.rb
|
data/test/git_helper.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'tmpdir'
|
3
|
-
|
4
|
-
# Instantiating a GitHelper object creates a temp directory containing 3 repos.
|
5
|
-
# 1 that's considered the remote repo and 2 peer local repos (local1 and local2).
|
6
|
-
# All 3 are synchronized with the same data (they contain a few dummy files).
|
7
|
-
# Once instantiated you can access the 3 full repo locations through attribute readers
|
8
|
-
# remote, local1 and local2.
|
9
|
-
class GitHelper
|
10
|
-
include FileUtils
|
11
|
-
|
12
|
-
@@WORK_DIR = 'repo_test'
|
13
|
-
|
14
|
-
attr_reader :remote, :local1, :local2
|
15
|
-
|
16
|
-
def initialize
|
17
|
-
@wd = get_temp_dir
|
18
|
-
|
19
|
-
@remote = init_repo(@wd, 'remote')
|
20
|
-
@local1 = clone_repo(@remote, @wd, 'local1')
|
21
|
-
@local2 = clone_repo(@remote, @wd, 'local2')
|
22
|
-
end
|
23
|
-
|
24
|
-
def cleanup
|
25
|
-
rm_rf @wd
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
def get_temp_dir
|
30
|
-
#Note: it's NOT a good idea to do this stuff un a subdirectory of the
|
31
|
-
#git_remote_branch repo. Trust me :-)
|
32
|
-
wd = File.expand_path( File.join( Dir::tmpdir, @@WORK_DIR) )
|
33
|
-
Dir.mkdir wd unless File.exists? wd
|
34
|
-
|
35
|
-
#Create new subdir with a random name
|
36
|
-
new_dir=''
|
37
|
-
begin
|
38
|
-
new_dir = File.join( wd, "#{rand(10000)}" )
|
39
|
-
Dir.mkdir new_dir
|
40
|
-
rescue
|
41
|
-
retry
|
42
|
-
end
|
43
|
-
|
44
|
-
new_dir
|
45
|
-
end
|
46
|
-
|
47
|
-
def init_repo(path, name)
|
48
|
-
repo_dir = File.join(path, name)
|
49
|
-
`mkdir #{repo_dir}; cd $_; git init; touch file.txt; git add .; git commit -a -m "dummy file"`
|
50
|
-
repo_dir
|
51
|
-
end
|
52
|
-
|
53
|
-
def clone_repo(origin_path, clone_path, name)
|
54
|
-
`cd #{clone_path}; git clone #{File.join(origin_path, '.git')} #{name}`
|
55
|
-
return File.join(clone_path, name)
|
56
|
-
end
|
57
|
-
end
|