twig 1.3 → 1.4
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/HISTORY.md +17 -1
- data/README.md +91 -20
- data/bin/twig +2 -0
- data/bin/twig-diff +38 -0
- data/bin/twig-gh-open +8 -1
- data/bin/twig-gh-open-issue +7 -1
- data/bin/twig-gh-update +9 -3
- data/bin/twig-help +1 -0
- data/bin/twig-init-completion +4 -2
- data/bin/twig-init-completion-bash +24 -5
- data/bin/twig-rebase +43 -0
- data/lib/twig/branch.rb +46 -13
- data/lib/twig/cli.rb +31 -4
- data/lib/twig/display.rb +17 -11
- data/lib/twig/github.rb +5 -1
- data/lib/twig/options.rb +32 -13
- data/lib/twig/version.rb +1 -1
- data/spec/twig/branch_spec.rb +89 -32
- data/spec/twig/cli_spec.rb +25 -7
- data/spec/twig/display_spec.rb +32 -33
- data/spec/twig/options_spec.rb +60 -12
- metadata +8 -4
data/spec/twig/cli_spec.rb
CHANGED
@@ -191,13 +191,13 @@ describe Twig::Cli do
|
|
191
191
|
end
|
192
192
|
|
193
193
|
it 'recognizes `--only-<property>` and sets a `:property_only` option' do
|
194
|
-
Twig::Branch.stub(:
|
194
|
+
Twig::Branch.stub(:all_property_names) { %w[foo] }
|
195
195
|
@twig.read_cli_options!(%w[--only-foo test])
|
196
196
|
@twig.options[:property_only].should == { :foo => /test/ }
|
197
197
|
end
|
198
198
|
|
199
199
|
it 'recognizes `--only-branch` and `--only-<property>` together' do
|
200
|
-
Twig::Branch.stub(:
|
200
|
+
Twig::Branch.stub(:all_property_names) { %w[foo] }
|
201
201
|
|
202
202
|
@twig.read_cli_options!(%w[--only-branch test --only-foo bar])
|
203
203
|
|
@@ -209,7 +209,7 @@ describe Twig::Cli do
|
|
209
209
|
|
210
210
|
it 'does not recognize `--only-<property>` for a missing property' do
|
211
211
|
property_name = 'foo'
|
212
|
-
Twig::Branch.
|
212
|
+
Twig::Branch.all_property_names.should_not include(property_name) # Precondition
|
213
213
|
@twig.stub(:puts)
|
214
214
|
|
215
215
|
begin
|
@@ -230,13 +230,13 @@ describe Twig::Cli do
|
|
230
230
|
end
|
231
231
|
|
232
232
|
it 'recognizes `--except-<property>` and sets a `:property_except` option' do
|
233
|
-
Twig::Branch.stub(:
|
233
|
+
Twig::Branch.stub(:all_property_names) { %w[foo] }
|
234
234
|
@twig.read_cli_options!(%w[--except-foo test])
|
235
235
|
@twig.options[:property_except].should == { :foo => /test/ }
|
236
236
|
end
|
237
237
|
|
238
238
|
it 'recognizes `--except-branch` and `--except-<property>` together' do
|
239
|
-
Twig::Branch.stub(:
|
239
|
+
Twig::Branch.stub(:all_property_names) { %w[foo] }
|
240
240
|
|
241
241
|
@twig.read_cli_options!(%w[--except-branch test --except-foo bar])
|
242
242
|
|
@@ -248,7 +248,7 @@ describe Twig::Cli do
|
|
248
248
|
|
249
249
|
it 'does not recognize `--except-<property>` for a missing property' do
|
250
250
|
property_name = 'foo'
|
251
|
-
Twig::Branch.
|
251
|
+
Twig::Branch.all_property_names.should_not include(property_name) # Precondition
|
252
252
|
@twig.stub(:puts)
|
253
253
|
|
254
254
|
begin
|
@@ -283,7 +283,7 @@ describe Twig::Cli do
|
|
283
283
|
end
|
284
284
|
|
285
285
|
it 'recognizes `--<property>-width`' do
|
286
|
-
Twig::Branch.stub(:
|
286
|
+
Twig::Branch.stub(:all_property_names) { %w[foo] }
|
287
287
|
@twig.options[:property_width].should be_nil
|
288
288
|
@twig.should_receive(:set_option).with(:property_width, :foo => '10')
|
289
289
|
|
@@ -304,6 +304,24 @@ describe Twig::Cli do
|
|
304
304
|
@twig.options[:reverse].should be_true
|
305
305
|
end
|
306
306
|
|
307
|
+
it 'recognizes `--github-api-uri-prefix`' do
|
308
|
+
@twig.options[:github_api_uri_prefix].should be_nil
|
309
|
+
prefix = 'https://github-enterprise.example.com/api/v3'
|
310
|
+
|
311
|
+
@twig.read_cli_options!(['--github-api-uri-prefix', prefix])
|
312
|
+
|
313
|
+
@twig.options[:github_api_uri_prefix].should == prefix
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'recognizes `--github-uri-prefix`' do
|
317
|
+
@twig.options[:github_uri_prefix].should be_nil
|
318
|
+
prefix = 'https://github-enterprise.example.com'
|
319
|
+
|
320
|
+
@twig.read_cli_options!(['--github-uri-prefix', prefix])
|
321
|
+
|
322
|
+
@twig.options[:github_uri_prefix].should == prefix
|
323
|
+
end
|
324
|
+
|
307
325
|
it 'handles invalid options' do
|
308
326
|
@twig.should_receive(:abort_for_option_exception) do |exception|
|
309
327
|
exception.should be_a(OptionParser::InvalidOption)
|
data/spec/twig/display_spec.rb
CHANGED
@@ -74,7 +74,7 @@ describe Twig::Display do
|
|
74
74
|
|
75
75
|
describe '#branch_list_headers' do
|
76
76
|
before :each do
|
77
|
-
Twig::Branch.stub(:
|
77
|
+
Twig::Branch.stub(:all_property_names => %w[foo quux])
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'returns a string of branch properties and underlines' do
|
@@ -146,23 +146,28 @@ describe Twig::Display do
|
|
146
146
|
|
147
147
|
describe '#branch_list_line' do
|
148
148
|
before :each do
|
149
|
-
@
|
150
|
-
Twig::Branch.
|
151
|
-
@twig.should_receive(:
|
152
|
-
|
153
|
-
@
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
@
|
158
|
-
|
149
|
+
@current_branch = Twig::Branch.new('my-branch')
|
150
|
+
@other_branch = Twig::Branch.new('other-branch')
|
151
|
+
@twig.should_receive(:current_branch_name).and_return(@current_branch.name)
|
152
|
+
Twig::Branch.stub(:all_property_names => %w[foo bar])
|
153
|
+
@current_branch.stub(:get_properties => {
|
154
|
+
'foo' => 'foo!',
|
155
|
+
'bar' => 'bar!'
|
156
|
+
})
|
157
|
+
@other_branch.stub(:get_properties => {
|
158
|
+
'foo' => 'foo!',
|
159
|
+
'bar' => 'bar!'
|
160
|
+
})
|
161
|
+
commit_time = Twig::CommitTime.new(Time.now, '')
|
162
|
+
commit_time.should_receive(:to_s).and_return('2000-01-01')
|
163
|
+
@current_branch.stub(:last_commit_time => commit_time)
|
164
|
+
@other_branch.stub(:last_commit_time => commit_time)
|
159
165
|
end
|
160
166
|
|
161
167
|
it 'returns a line for the current branch' do
|
162
168
|
indicator = Twig::Display::CURRENT_BRANCH_INDICATOR
|
163
|
-
branch =
|
169
|
+
branch = @current_branch
|
164
170
|
branch_regexp = /#{Regexp.escape(indicator)}#{Regexp.escape(branch.name)}/
|
165
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
166
171
|
|
167
172
|
result = @twig.branch_list_line(branch)
|
168
173
|
|
@@ -170,20 +175,14 @@ describe Twig::Display do
|
|
170
175
|
end
|
171
176
|
|
172
177
|
it 'returns a line for a branch other than the current branch' do
|
173
|
-
branch =
|
174
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
175
|
-
|
178
|
+
branch = @other_branch
|
176
179
|
result = @twig.branch_list_line(branch)
|
177
|
-
|
178
180
|
result.should =~ /2000-01-01\s+foo!\s+bar!\s+#{Regexp.escape(branch.name)}/
|
179
181
|
end
|
180
182
|
|
181
183
|
it 'returns a line containing an empty branch property' do
|
182
|
-
Twig::Branch.
|
183
|
-
@
|
184
|
-
with(anything, 'baz').and_return(nil)
|
185
|
-
branch = Twig::Branch.new('other-branch')
|
186
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
184
|
+
Twig::Branch.should_receive(:all_property_names).and_return(%w[foo bar baz])
|
185
|
+
branch = @other_branch
|
187
186
|
|
188
187
|
result = @twig.branch_list_line(branch)
|
189
188
|
|
@@ -192,11 +191,14 @@ describe Twig::Display do
|
|
192
191
|
end
|
193
192
|
|
194
193
|
it 'changes line break characters to spaces' do
|
195
|
-
branch =
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
branch = @current_branch
|
195
|
+
property_names = %w[foo bar linebreaks]
|
196
|
+
branch.should_receive(:get_properties).with(property_names).and_return(
|
197
|
+
'foo' => 'foo!',
|
198
|
+
'bar' => 'bar!',
|
199
|
+
'linebreaks' => "line\r\nbreaks!"
|
200
|
+
)
|
201
|
+
Twig::Branch.should_receive(:all_property_names).and_return(property_names)
|
200
202
|
|
201
203
|
result = @twig.branch_list_line(branch)
|
202
204
|
|
@@ -204,8 +206,7 @@ describe Twig::Display do
|
|
204
206
|
end
|
205
207
|
|
206
208
|
it 'returns a line with custom column widths' do
|
207
|
-
branch =
|
208
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
209
|
+
branch = @other_branch
|
209
210
|
@twig.set_option(:property_width, :foo => 5)
|
210
211
|
|
211
212
|
result = @twig.branch_list_line(branch)
|
@@ -225,9 +226,8 @@ describe Twig::Display do
|
|
225
226
|
|
226
227
|
it 'returns a line for the current branch' do
|
227
228
|
indicator = Twig::Display::CURRENT_BRANCH_INDICATOR
|
228
|
-
branch =
|
229
|
+
branch = @current_branch
|
229
230
|
branch_regexp = /#{Regexp.escape(indicator)}#{Regexp.escape(branch.name)}/
|
230
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
231
231
|
|
232
232
|
result = @twig.branch_list_line(branch)
|
233
233
|
unformatted_result = @twig.unformat_string(result)
|
@@ -241,8 +241,7 @@ describe Twig::Display do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
it 'returns a line for a branch other than the current branch' do
|
244
|
-
branch =
|
245
|
-
branch.should_receive(:last_commit_time).and_return(@commit_time)
|
244
|
+
branch = @other_branch
|
246
245
|
|
247
246
|
result = @twig.branch_list_line(branch)
|
248
247
|
|
data/spec/twig/options_spec.rb
CHANGED
@@ -7,15 +7,15 @@ describe Twig::Options do
|
|
7
7
|
|
8
8
|
describe '#read_config_file!' do
|
9
9
|
before :each do
|
10
|
-
File.should_receive(:expand_path).with(Twig::
|
11
|
-
and_return(Twig::
|
10
|
+
File.should_receive(:expand_path).with(Twig::CONFIG_PATH).
|
11
|
+
and_return(Twig::CONFIG_PATH)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'reads and sets a single option' do
|
15
15
|
@twig.stub(:all_branch_names => ['test'])
|
16
16
|
file = double('file')
|
17
|
-
File.should_receive(:readable?).with(Twig::
|
18
|
-
File.should_receive(:open).with(Twig::
|
17
|
+
File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
|
18
|
+
File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
|
19
19
|
file.should_receive(:read).and_return('branch: test')
|
20
20
|
@twig.options[:branch].should be_nil # Precondition
|
21
21
|
|
@@ -24,11 +24,32 @@ describe Twig::Options do
|
|
24
24
|
@twig.options[:branch].should == 'test'
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'reads an option if only the deprecated config file exists' do
|
28
|
+
@twig.stub(:all_branch_names => ['test'])
|
29
|
+
file = double('file')
|
30
|
+
path = Twig::CONFIG_PATH
|
31
|
+
deprecated_path = Twig::DEPRECATED_CONFIG_PATH
|
32
|
+
File.should_receive(:readable?).with(path).and_return(false)
|
33
|
+
File.should_receive(:readable?).with(deprecated_path).and_return(true)
|
34
|
+
File.should_receive(:expand_path).with(deprecated_path).
|
35
|
+
and_return(deprecated_path)
|
36
|
+
File.should_receive(:open).with(deprecated_path).and_yield(file)
|
37
|
+
file.should_receive(:read).and_return('branch: test')
|
38
|
+
$stderr.should_receive(:puts) do |message|
|
39
|
+
message.should =~ /^DEPRECATED:/
|
40
|
+
end
|
41
|
+
@twig.options[:branch].should be_nil
|
42
|
+
|
43
|
+
@twig.read_config_file!
|
44
|
+
|
45
|
+
@twig.options[:branch].should == 'test'
|
46
|
+
end
|
47
|
+
|
27
48
|
it 'reads and sets multiple options' do
|
28
49
|
@twig.stub(:all_branch_names => ['test'])
|
29
50
|
file = double('file')
|
30
|
-
File.should_receive(:readable?).with(Twig::
|
31
|
-
File.should_receive(:open).with(Twig::
|
51
|
+
File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
|
52
|
+
File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
|
32
53
|
file.should_receive(:read).and_return([
|
33
54
|
# Filtering branches:
|
34
55
|
'branch: test',
|
@@ -41,11 +62,17 @@ describe Twig::Options do
|
|
41
62
|
# Displaying branches:
|
42
63
|
'header-style: green bold',
|
43
64
|
'reverse: true',
|
44
|
-
'foo-width: 4'
|
65
|
+
'foo-width: 4',
|
66
|
+
|
67
|
+
# GitHub integration:
|
68
|
+
'github-api-uri-prefix: https://github-enterprise.example.com/api/v3',
|
69
|
+
'github-uri-prefix: https://github-enterprise.example.com'
|
45
70
|
].join("\n"))
|
46
71
|
|
47
72
|
# Check preconditions
|
48
73
|
@twig.options[:branch].should be_nil
|
74
|
+
@twig.options[:github_api_uri_prefix].should be_nil
|
75
|
+
@twig.options[:github_uri_prefix].should be_nil
|
49
76
|
@twig.options[:header_color].should == Twig::DEFAULT_HEADER_COLOR
|
50
77
|
@twig.options[:header_weight].should be_nil
|
51
78
|
@twig.options[:max_days_old].should be_nil
|
@@ -57,6 +84,10 @@ describe Twig::Options do
|
|
57
84
|
@twig.read_config_file!
|
58
85
|
|
59
86
|
@twig.options[:branch].should == 'test'
|
87
|
+
@twig.options[:github_api_uri_prefix].
|
88
|
+
should == 'https://github-enterprise.example.com/api/v3'
|
89
|
+
@twig.options[:github_uri_prefix].
|
90
|
+
should == 'https://github-enterprise.example.com'
|
60
91
|
@twig.options[:header_color].should == :green
|
61
92
|
@twig.options[:header_weight].should == :bold
|
62
93
|
@twig.options[:max_days_old].should == 30.5
|
@@ -74,8 +105,8 @@ describe Twig::Options do
|
|
74
105
|
|
75
106
|
it 'skips comments' do
|
76
107
|
file = double('file')
|
77
|
-
File.should_receive(:readable?).with(Twig::
|
78
|
-
File.should_receive(:open).with(Twig::
|
108
|
+
File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
|
109
|
+
File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
|
79
110
|
file.should_receive(:read).and_return([
|
80
111
|
'# max-days-old: 40',
|
81
112
|
'max-days-old: 30',
|
@@ -91,8 +122,8 @@ describe Twig::Options do
|
|
91
122
|
|
92
123
|
it 'skips line breaks' do
|
93
124
|
file = double('file')
|
94
|
-
File.should_receive(:readable?).with(Twig::
|
95
|
-
File.should_receive(:open).with(Twig::
|
125
|
+
File.should_receive(:readable?).with(Twig::CONFIG_PATH).and_return(true)
|
126
|
+
File.should_receive(:open).with(Twig::CONFIG_PATH).and_yield(file)
|
96
127
|
file.should_receive(:read).and_return([
|
97
128
|
'except-branch: test-except',
|
98
129
|
'',
|
@@ -110,7 +141,12 @@ describe Twig::Options do
|
|
110
141
|
end
|
111
142
|
|
112
143
|
it 'fails gracefully if the config file is not readable' do
|
113
|
-
|
144
|
+
path = Twig::CONFIG_PATH
|
145
|
+
deprecated_path = Twig::DEPRECATED_CONFIG_PATH
|
146
|
+
File.should_receive(:readable?).with(path).and_return(false)
|
147
|
+
File.should_receive(:readable?).with(deprecated_path).and_return(false)
|
148
|
+
File.should_receive(:expand_path).with(deprecated_path).
|
149
|
+
and_return(deprecated_path)
|
114
150
|
lambda { @twig.read_config_file! }.should_not raise_exception
|
115
151
|
end
|
116
152
|
end
|
@@ -143,6 +179,18 @@ describe Twig::Options do
|
|
143
179
|
end
|
144
180
|
end
|
145
181
|
|
182
|
+
it 'sets a :github_api_uri_prefix option' do
|
183
|
+
prefix = 'https://github-enterprise.example.com/api/v3'
|
184
|
+
@twig.set_option(:github_api_uri_prefix, prefix)
|
185
|
+
@twig.options[:github_api_uri_prefix].should == prefix
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'sets a :github_uri_prefix option' do
|
189
|
+
prefix = 'https://github-enterprise.example.com'
|
190
|
+
@twig.set_option(:github_uri_prefix, prefix)
|
191
|
+
@twig.options[:github_uri_prefix].should == prefix
|
192
|
+
end
|
193
|
+
|
146
194
|
it 'sets a :header_style option' do
|
147
195
|
style = 'red bold'
|
148
196
|
@twig.should_receive(:set_header_style_option).with(style)
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: "1.
|
8
|
+
- 4
|
9
|
+
version: "1.4"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ron DeVera
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2013-
|
17
|
+
date: 2013-08-07 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -86,12 +86,14 @@ email:
|
|
86
86
|
- hello@rondevera.com
|
87
87
|
executables:
|
88
88
|
- twig
|
89
|
+
- twig-diff
|
89
90
|
- twig-gh-open
|
90
91
|
- twig-gh-open-issue
|
91
92
|
- twig-gh-update
|
92
93
|
- twig-help
|
93
94
|
- twig-init-completion
|
94
95
|
- twig-init-completion-bash
|
96
|
+
- twig-rebase
|
95
97
|
extensions: []
|
96
98
|
|
97
99
|
extra_rdoc_files: []
|
@@ -106,12 +108,14 @@ files:
|
|
106
108
|
- README.md
|
107
109
|
- Rakefile
|
108
110
|
- bin/twig
|
111
|
+
- bin/twig-diff
|
109
112
|
- bin/twig-gh-open
|
110
113
|
- bin/twig-gh-open-issue
|
111
114
|
- bin/twig-gh-update
|
112
115
|
- bin/twig-help
|
113
116
|
- bin/twig-init-completion
|
114
117
|
- bin/twig-init-completion-bash
|
118
|
+
- bin/twig-rebase
|
115
119
|
- lib/twig.rb
|
116
120
|
- lib/twig/branch.rb
|
117
121
|
- lib/twig/cli.rb
|