kch-git_remote_branch 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +32 -0
- data/LICENSE +18 -0
- data/README.rdoc +184 -0
- data/Rakefile +17 -0
- data/bin/grb +44 -0
- data/lib/constants.rb +5 -0
- data/lib/git_remote_branch.rb +164 -0
- data/lib/param_reader.rb +63 -0
- data/lib/state.rb +42 -0
- data/lib/version.rb +14 -0
- data/tasks/gem.rake +89 -0
- data/tasks/rdoc.rake +15 -0
- data/tasks/test.rake +18 -0
- data/test/functional/grb_test.rb +188 -0
- data/test/helpers/array_extensions.rb +14 -0
- data/test/helpers/constants.rb +15 -0
- data/test/helpers/extractable.rb +63 -0
- data/test/helpers/git_helper.rb +40 -0
- data/test/helpers/in_dir.rb +10 -0
- data/test/helpers/more_assertions.rb +16 -0
- data/test/helpers/shoulda_functional_helpers.rb +152 -0
- data/test/helpers/shoulda_unit_helpers.rb +88 -0
- data/test/helpers/temp_dir_helper.rb +38 -0
- data/test/test_helper.rb +36 -0
- data/test/unit/git_helper_test.rb +30 -0
- data/test/unit/git_remote_branch_test.rb +39 -0
- data/test/unit/param_reader_test.rb +215 -0
- data/test/unit/state_test.rb +56 -0
- data/vendor/capture_fu.rb +58 -0
- metadata +120 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class GitHelperTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@g = GitHelper.new
|
8
|
+
@directories = [@g.remote, @g.local1, @g.local2]
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@g.cleanup
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_init
|
16
|
+
@directories.each do |d|
|
17
|
+
assert File.exists?(@g.remote), 'Directory for repo must be created'
|
18
|
+
assert File.exists?( File.join(@g.remote, '.git') ), 'Repo must be created'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_cleanup
|
23
|
+
@g.cleanup
|
24
|
+
|
25
|
+
@directories.each do |d|
|
26
|
+
assert_false File.exists?(@g.remote), 'Each repo directory must be destroyed after cleanup'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class GitRemoteBranchTest < Test::Unit::TestCase
|
4
|
+
context 'help' do
|
5
|
+
should 'contain examples for all basic commands' do
|
6
|
+
GitRemoteBranch::COMMANDS.keys.each do |k|
|
7
|
+
assert_match "grb #{k} branch_name", grb.get_usage
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
should 'contain an example for explain' do
|
12
|
+
assert_match 'grb explain', grb.get_usage
|
13
|
+
end
|
14
|
+
|
15
|
+
should 'contain an enumeration of all aliases' do
|
16
|
+
GitRemoteBranch::COMMANDS.each_pair do |k,v|
|
17
|
+
assert_match "#{k}: #{v[:aliases].join(', ')}", grb.get_usage
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "the reverse mapping for aliases" do
|
23
|
+
GitRemoteBranch::COMMANDS.each_pair do |cmd, params|
|
24
|
+
params[:aliases].each do |alias_|
|
25
|
+
should "contain the alias #{alias_}" do
|
26
|
+
assert GitRemoteBranch::ALIAS_REVERSE_MAP[alias_]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "upon creation" do
|
32
|
+
should "raise an exception when there are duplicates" do
|
33
|
+
assert_raise(RuntimeError) do
|
34
|
+
GitRemoteBranch.get_reverse_map( GitRemoteBranch::COMMANDS.merge(:new_command => {:aliases => ['create']}) )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
require "#{TEST_DIR}/helpers/constants"
|
3
|
+
|
4
|
+
class ParamReaderTest < Test::Unit::TestCase
|
5
|
+
include ShouldaUnitHelpers
|
6
|
+
|
7
|
+
context 'read_params' do
|
8
|
+
context "when on a valid branch" do
|
9
|
+
setup do
|
10
|
+
grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
|
11
|
+
end
|
12
|
+
|
13
|
+
context "on a normal valid command without an origin" do
|
14
|
+
setup do
|
15
|
+
@p = grb.read_params %w{create the_branch}
|
16
|
+
end
|
17
|
+
|
18
|
+
should_set_action_to :create
|
19
|
+
should_set_branch_to 'the_branch'
|
20
|
+
should_set_origin_to 'origin'
|
21
|
+
should_set_current_branch_to 'stubbed_current_branch'
|
22
|
+
should_set_explain_to false
|
23
|
+
should_set_silent_to false
|
24
|
+
end
|
25
|
+
|
26
|
+
context "on a normal valid command" do
|
27
|
+
setup do
|
28
|
+
@p = grb.read_params %w{create the_branch the_origin}
|
29
|
+
end
|
30
|
+
|
31
|
+
should_set_action_to :create
|
32
|
+
should_set_branch_to 'the_branch'
|
33
|
+
should_set_origin_to 'the_origin'
|
34
|
+
should_set_current_branch_to 'stubbed_current_branch'
|
35
|
+
should_set_explain_to false
|
36
|
+
should_set_silent_to false
|
37
|
+
end
|
38
|
+
|
39
|
+
should_explain_with_current_branch 'stubbed_current_branch', "use real current branch"
|
40
|
+
|
41
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
42
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
43
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
44
|
+
|
45
|
+
context "understands the --silent parameter" do
|
46
|
+
context "at the beginning" do
|
47
|
+
setup do
|
48
|
+
@p = grb.read_params %w{--silent create some_branch some_origin}
|
49
|
+
end
|
50
|
+
should_set_silent_to true
|
51
|
+
should_set_action_to :create
|
52
|
+
should_set_branch_to 'some_branch'
|
53
|
+
should_set_origin_to 'some_origin'
|
54
|
+
end
|
55
|
+
|
56
|
+
context "at the end" do
|
57
|
+
setup do
|
58
|
+
@p = grb.read_params %w{create some_branch some_origin --silent}
|
59
|
+
end
|
60
|
+
should_set_silent_to true
|
61
|
+
should_set_action_to :create
|
62
|
+
should_set_branch_to 'some_branch'
|
63
|
+
should_set_origin_to 'some_origin'
|
64
|
+
end
|
65
|
+
|
66
|
+
context "in the freakin' middle" do
|
67
|
+
setup do
|
68
|
+
@p = grb.read_params %w{create --silent some_branch some_origin}
|
69
|
+
end
|
70
|
+
should_set_silent_to true
|
71
|
+
should_set_action_to :create
|
72
|
+
should_set_branch_to 'some_branch'
|
73
|
+
should_set_origin_to 'some_origin'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when on an invalid branch" do
|
79
|
+
setup do
|
80
|
+
grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
|
81
|
+
end
|
82
|
+
|
83
|
+
GitRemoteBranch::COMMANDS.each_key do |action|
|
84
|
+
context "running the '#{action}' command" do
|
85
|
+
setup do
|
86
|
+
@command = [action.to_s, 'branch_name']
|
87
|
+
end
|
88
|
+
|
89
|
+
context "raising an exception" do
|
90
|
+
setup do
|
91
|
+
begin
|
92
|
+
grb.read_params(@command)
|
93
|
+
rescue => @ex
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
should "raise an InvalidBranchError" do
|
98
|
+
assert_kind_of GitRemoteBranch::InvalidBranchError, @ex
|
99
|
+
end
|
100
|
+
|
101
|
+
should "give a clear error message" do
|
102
|
+
assert_match(/identify.*branch/, @ex.message)
|
103
|
+
end
|
104
|
+
|
105
|
+
should "display git's branch listing" do
|
106
|
+
assert_match(/\(no branch\)/, @ex.message)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
|
113
|
+
|
114
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
115
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
116
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when not on a git repository" do
|
120
|
+
setup do
|
121
|
+
grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
|
122
|
+
end
|
123
|
+
|
124
|
+
should_explain_with_current_branch 'current_branch', "use a dummy value for the current branch"
|
125
|
+
|
126
|
+
should_return_help_for_parameters %w(help), "on a 'help' command"
|
127
|
+
should_return_help_for_parameters %w(create), "on an incomplete command"
|
128
|
+
should_return_help_for_parameters %w(decombobulate something), "on an invalid command"
|
129
|
+
|
130
|
+
GitRemoteBranch::COMMANDS.each_key do |action|
|
131
|
+
context "running the '#{action}' command" do
|
132
|
+
setup do
|
133
|
+
@command = [action.to_s, 'branch_name']
|
134
|
+
end
|
135
|
+
|
136
|
+
context "raising an exception" do
|
137
|
+
setup do
|
138
|
+
begin
|
139
|
+
grb.read_params(@command)
|
140
|
+
rescue => @ex
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
should "raise an NotOnGitRepositoryError" do
|
145
|
+
assert_kind_of GitRemoteBranch::NotOnGitRepositoryError, @ex
|
146
|
+
end
|
147
|
+
|
148
|
+
should "give a clear error message" do
|
149
|
+
assert_match(/fatal/, @ex.message)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'explain_mode!' do
|
158
|
+
context "when it receives an array beginning with 'explain'" do
|
159
|
+
setup do
|
160
|
+
@array = ['explain', 'create', 'some_branch']
|
161
|
+
end
|
162
|
+
|
163
|
+
should "return true" do
|
164
|
+
assert grb.explain_mode!(@array)
|
165
|
+
end
|
166
|
+
|
167
|
+
should 'accept symbol arrays as well' do
|
168
|
+
assert grb.explain_mode!( @array.map{|e| e.to_sym} )
|
169
|
+
end
|
170
|
+
|
171
|
+
should "remove 'explain' from the argument array" do
|
172
|
+
grb.explain_mode!(@array)
|
173
|
+
assert_equal ['create', 'some_branch'], @array
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when it receives an array that doesn't begin with 'explain'" do
|
178
|
+
setup do
|
179
|
+
@array = ['create', 'some_branch']
|
180
|
+
end
|
181
|
+
|
182
|
+
should "return false" do
|
183
|
+
assert_false grb.explain_mode!(@array)
|
184
|
+
end
|
185
|
+
|
186
|
+
should "not modify the argument array" do
|
187
|
+
grb.explain_mode!(@array)
|
188
|
+
assert_equal ['create', 'some_branch'], @array
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
context 'get_action' do
|
194
|
+
GitRemoteBranch::COMMANDS.each_pair do |cmd, params|
|
195
|
+
should "recognize all #{cmd} aliases" do
|
196
|
+
params[:aliases].each do |alias_|
|
197
|
+
assert cmd, grb.get_action(alias_)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
should 'return nil on unknown aliases' do
|
202
|
+
assert_nil grb.get_action('please_dont_create_an_alias_named_like_this')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'get_origin' do
|
207
|
+
should "default to 'origin' when the param is nil" do
|
208
|
+
assert_equal 'origin', grb.get_origin(nil)
|
209
|
+
end
|
210
|
+
should "return the unchanged param if it's not nil" do
|
211
|
+
assert_equal 'someword', grb.get_origin('someword')
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
require "#{TEST_DIR}/helpers/constants"
|
3
|
+
|
4
|
+
class ParamReaderTest < Test::Unit::TestCase
|
5
|
+
include ShouldaUnitHelpers
|
6
|
+
|
7
|
+
def self.craps_out_in_invalid_situations
|
8
|
+
context "when not on a git repository" do
|
9
|
+
setup do
|
10
|
+
grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
|
11
|
+
end
|
12
|
+
|
13
|
+
should "raise an exception" do
|
14
|
+
assert_raise(GitRemoteBranch::NotOnGitRepositoryError) { grb.get_current_branch }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when on an invalid branch" do
|
19
|
+
setup do
|
20
|
+
grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
|
21
|
+
end
|
22
|
+
|
23
|
+
should "raise an exception" do
|
24
|
+
assert_raise(GitRemoteBranch::InvalidBranchError) { grb.get_current_branch }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'get_current_branch' do
|
30
|
+
craps_out_in_invalid_situations
|
31
|
+
|
32
|
+
context "when on a valid branch" do
|
33
|
+
setup do
|
34
|
+
grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
|
35
|
+
end
|
36
|
+
|
37
|
+
should "return the current branch name" do
|
38
|
+
assert_equal 'stubbed_current_branch', grb.get_current_branch
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'local_branches' do
|
44
|
+
craps_out_in_invalid_situations
|
45
|
+
|
46
|
+
context "when on a valid branch" do
|
47
|
+
setup do
|
48
|
+
grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
|
49
|
+
end
|
50
|
+
|
51
|
+
should "return all the local branch names" do
|
52
|
+
assert_array_content %w{stubbed_current_branch other_user/master rubyforge}, grb.local_branches
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
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
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kch-git_remote_branch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathieu Martin
|
8
|
+
- Carl Mercier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2008-11-13 21:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: colored
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "1.1"
|
25
|
+
version:
|
26
|
+
description: git_remote_branch is a learning tool to ease the interaction with remote branches in simple situations.
|
27
|
+
email: webmat@gmail.com
|
28
|
+
executables:
|
29
|
+
- grb
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- bin
|
36
|
+
- bin/grb
|
37
|
+
- CHANGELOG
|
38
|
+
- lib
|
39
|
+
- lib/constants.rb
|
40
|
+
- lib/git_remote_branch.rb
|
41
|
+
- lib/param_reader.rb
|
42
|
+
- lib/state.rb
|
43
|
+
- lib/string_ext.rb
|
44
|
+
- lib/version.rb
|
45
|
+
- LICENSE
|
46
|
+
- Rakefile
|
47
|
+
- README.rdoc
|
48
|
+
- tasks
|
49
|
+
- tasks/gem.rake
|
50
|
+
- tasks/rdoc.rake
|
51
|
+
- tasks/test.rake
|
52
|
+
- test
|
53
|
+
- test/functional
|
54
|
+
- test/functional/grb_test.rb
|
55
|
+
- test/helpers
|
56
|
+
- test/helpers/array_extensions.rb
|
57
|
+
- test/helpers/constants.rb
|
58
|
+
- test/helpers/extractable.rb
|
59
|
+
- test/helpers/git_helper.rb
|
60
|
+
- test/helpers/in_dir.rb
|
61
|
+
- test/helpers/more_assertions.rb
|
62
|
+
- test/helpers/shoulda_functional_helpers.rb
|
63
|
+
- test/helpers/shoulda_unit_helpers.rb
|
64
|
+
- test/helpers/temp_dir_helper.rb
|
65
|
+
- test/test_helper.rb
|
66
|
+
- test/unit
|
67
|
+
- test/unit/git_helper_test.rb
|
68
|
+
- test/unit/git_remote_branch_test.rb
|
69
|
+
- test/unit/param_reader_test.rb
|
70
|
+
- test/unit/state_test.rb
|
71
|
+
- vendor
|
72
|
+
- vendor/capture_fu.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/webmat/git_remote_branch
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.rdoc
|
79
|
+
- --exclude
|
80
|
+
- lib
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project: grb
|
98
|
+
rubygems_version: 1.2.0
|
99
|
+
signing_key:
|
100
|
+
specification_version: 2
|
101
|
+
summary: git_remote_branch eases the interaction with remote branches
|
102
|
+
test_files:
|
103
|
+
- test/functional
|
104
|
+
- test/functional/grb_test.rb
|
105
|
+
- test/helpers
|
106
|
+
- test/helpers/array_extensions.rb
|
107
|
+
- test/helpers/constants.rb
|
108
|
+
- test/helpers/extractable.rb
|
109
|
+
- test/helpers/git_helper.rb
|
110
|
+
- test/helpers/in_dir.rb
|
111
|
+
- test/helpers/more_assertions.rb
|
112
|
+
- test/helpers/shoulda_functional_helpers.rb
|
113
|
+
- test/helpers/shoulda_unit_helpers.rb
|
114
|
+
- test/helpers/temp_dir_helper.rb
|
115
|
+
- test/test_helper.rb
|
116
|
+
- test/unit
|
117
|
+
- test/unit/git_helper_test.rb
|
118
|
+
- test/unit/git_remote_branch_test.rb
|
119
|
+
- test/unit/param_reader_test.rb
|
120
|
+
- test/unit/state_test.rb
|