hglib 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 609e12ea2bd06f9e02b74b8f9c44502ebfe9bf8eb3d76cde39229719f25296be
4
- data.tar.gz: e2100c0d719f3ae437e8d44120b881bc561f488b81ba84ba77745a2fde8db020
3
+ metadata.gz: b890e1ab00998d1042bb8d586771adfcfe352679da65905af0efd0953368b66b
4
+ data.tar.gz: 0710da264e90e0fc3a4be8815ad313b5eff34523c7e070db3ecb1014dcf25efa
5
5
  SHA512:
6
- metadata.gz: df2e978345babfd706e31e90214042bf79cb4ec0f2a945117e23466f15a56ed6cb2a1fccd3b0cad4e4722a43b6060e15f83cb8e8a2a688855acf9894195ff75d
7
- data.tar.gz: 9fc6c4485ec905578ae2928a83f61e6e30a9e9ec80ef1a81e4abd1fbd5067d24471cb69c4493a362ba2aad8a22b69465573e835014e1324c976b7891fe212b76
6
+ metadata.gz: 40377af3d802f96c7256e77aca8d6bce7d255aa2cc84e050166079649f16c3454bb5e6c8de2ad3f2086c5ccbf873634db9a071b3f6acf5eb0af9f5629349a0ff
7
+ data.tar.gz: e923e390dec969cfa4a5831d242fa0169458d64aafe1b365ab0422f1f85d135e58907cdbedc983391b5d06d55a801396ff9d3a6c35c60d0e93e0814dcf3ec45b
checksums.yaml.gz.sig CHANGED
@@ -1,4 +1,2 @@
1
- ~�i>bEbh秎�A��(G(�_�
2
- ��S\�X��?��/7�޸-�;/�\��xN�u]km��;�)��LW����l^�uE
3
- S|n��-��@ y pj�Ҭ���}a��S���&ME狒6�@� N�
4
- _>R��Ьu;�V����W���E������5�iT;+���m5Y�I��1lb�. ;�Vb��_�jeH�37�J
1
+ m��=&���i�S 2
2
+ ���uA$�㊔p�P�6���]^J�9�t��dG\#ٺC��.���ֹ�~��$tbƬ�xђ��P�0~�sb7HՕ�2�b�J(p%�L�D�O"d��+�J�eoRy�u�w���,a��j3B#h��\2�bc,}-&��ǯ�O��Ϥ�D=9�T[���M�������Š��+�^����ŁBN��*��P�� �H ���Ș *��T�t���1��(C_�/�Yz@)�<��pبJʈÉ���/���*�2�D��J˽Y���pt��j4)�n�������d��5���GY<�D�@U�׫��]����i���K%&;zق ���i��=Kځ��SPB�ž2)-�(]��B����}��
data/History.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## v0.4.0 [2019-10-12] Michael Granger <ged@FaerieMUD.org>
6
+
7
+ Changes:
8
+
9
+ - Move the #version methods up into the base module
10
+
11
+ Improvements:
12
+
13
+ - Add Hglib.extension_enabled?
14
+
15
+
5
16
  ## v0.3.0 [2019-10-02] Michael Granger <ged@FaerieMUD.org>
6
17
 
7
18
  Changes:
data/LICENSE.txt CHANGED
@@ -1,20 +1,27 @@
1
- Copyright (c) 2018 Michael Granger
1
+ Copyright (c) 2018, Michael Granger
2
+ All rights reserved.
2
3
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
10
6
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
13
9
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the author/s, nor the names of the project's
15
+ contributors may be used to endorse or promote products derived from this
16
+ software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/lib/hglib/repo/id.rb CHANGED
@@ -49,7 +49,7 @@ class Hglib::Repo::Id
49
49
  attr_reader :branch
50
50
 
51
51
  ##
52
- # The ID of the current
52
+ # The ID of the current changeset node
53
53
  attr_reader :node
54
54
 
55
55
  ##
@@ -71,6 +71,12 @@ class Hglib::Repo::Id
71
71
  attr_reader :bookmarks
72
72
 
73
73
 
74
+ ### Return the short form of the global ID.
75
+ def short_id
76
+ return self.id[ 0, 12 ]
77
+ end
78
+
79
+
74
80
  ### Return the ID as a String in the form used by the command line.
75
81
  def to_s
76
82
  str = self.global.dup
@@ -91,5 +97,11 @@ class Hglib::Repo::Id
91
97
  self.global == other
92
98
  end
93
99
 
100
+
101
+ ### Returns +true+ if the Id's revision ID is the DEFAULT_ID
102
+ def default?
103
+ return self.id == DEFAULT_ID
104
+ end
105
+
94
106
  end # class Hglib::Repo::Id
95
107
 
data/lib/hglib/repo.rb CHANGED
@@ -65,7 +65,8 @@ class Hglib::Repo
65
65
  data = response.first
66
66
  return Hglib::Repo::Id.new( **data )
67
67
  end
68
- alias_method :id, :identify
68
+ alias_method :identity, :identify
69
+ alias_method :id, :identity
69
70
 
70
71
 
71
72
  ### Return an Array of Hglib::Repo::LogEntry objects that describes the revision
@@ -246,27 +247,68 @@ class Hglib::Repo
246
247
  end
247
248
 
248
249
 
249
- ### Fetch a Hash of version information about the Mercurial that is being used.
250
- def versions
251
- response = self.server.run_with_json_template( :version )
252
- self.logger.debug "Got a VERSION response: %p" % [ response ]
250
+ ### Set or show the current phase name for a +revset+.
251
+ ###
252
+ ### With no +revset+, operates on the current changeset.
253
+ ###
254
+ ### You can set the phase of the specified revisions by passing one of the
255
+ ### following +options+:
256
+ ###
257
+ ### - p: true / public: true
258
+ ### - d: true / draft: true
259
+ ### - s: true / secret: true
260
+ ###
261
+ ### Returns a Hash of <local revision number> => <phase as a Symbol>. Setting
262
+ ### the phase returns an empty Hash on success, and raises if there was a problem
263
+ ### setting the phase.
264
+ def phase( revset=nil, **options )
265
+ response = self.server.run( :phase, revset, **options )
266
+ self.logger.debug "Got a PHASE response: %p" % [ response ]
267
+
268
+ return {} if response.empty?
269
+
270
+ return response.lines.each_with_object({}) do |line, hash|
271
+ m = line.match( /^(?<revnum>\d+): (?<phase>\w+)/ ) or
272
+ raise "Couldn't parse phase response %p" % [ line ]
273
+ hash[ m[:revnum].to_i ] = m[:phase].to_sym
274
+ end
275
+ end
276
+
277
+
278
+ #
279
+ # Shortcut predicates
280
+ #
253
281
 
254
- return response.first
282
+ ### Returns +true+ if the repo has outstanding changes.
283
+ def dirty?
284
+ return self.identify.dirty?
255
285
  end
256
286
 
257
287
 
258
- ### Fetch the version of Mercurial that's being used as a String.
259
- def version
260
- return self.versions[ :ver ]
288
+ ### Returns +true+ if the repo has no outstanding changes.
289
+ def clean?
290
+ return !self.dirty?
261
291
  end
262
292
 
263
293
 
264
- ### Fetch the version of the Mercurial extensions that're being used as a Hash.
265
- def extension_versions
266
- ext_info = self.versions[ :extensions ]
267
- return ext_info.each_with_object({}) do |ext, hash|
268
- hash[ ext.delete(:name).to_sym ] = ext
269
- end
294
+ ### Returns +true+ if all of the changesets in the specified +revset+ (or the
295
+ ### current changeset if no +revset+ is given) are in the public phase.
296
+ def public?( revset=nil )
297
+ return self.phase( revset ).values.all?( :public )
298
+ end
299
+
300
+
301
+ ### Returns +true+ if all of the changesets in the specified +revset+ (or the
302
+ ### current changeset if no +revset+ is given) are in the draft phase.
303
+ def draft?( revset=nil )
304
+ return self.phase( revset ).values.all?( :draft )
305
+ end
306
+
307
+
308
+ ### Returns +true+ if all of the changesets in the specified +revset+ (or the
309
+ ### current changeset if no +revset+ is given) are in the secret phase.
310
+ def secret?( revset=nil )
311
+ return self.phase( revset ).values.all?( :secret )
270
312
  end
271
313
 
272
314
 
data/lib/hglib/server.rb CHANGED
@@ -37,21 +37,30 @@ class Hglib::Server
37
37
  prefix = name.length > 1 ? '--' : '-'
38
38
  optname = "%s%s" % [ prefix, name.to_s.gsub(/_/, '-') ]
39
39
 
40
- case val
41
- when TrueClass
42
- [ optname ]
43
- when FalseClass, NilClass
44
- [ optname.sub(/\A--/, '--no-') ] if optname.start_with?( '--' )
45
- when String, Numeric
46
- if optname.start_with?( '--' )
47
- [ "#{optname}=#{val}" ]
48
- else
49
- [ optname, val ]
50
- end
40
+ self.make_command_option( optname, val )
41
+ end.compact
42
+ end
43
+
44
+
45
+ ### Form one or more command line options given an +optname+ and +value+ and
46
+ ### return them as an Array.
47
+ def self::make_command_option( optname, value )
48
+ case value
49
+ when TrueClass
50
+ return [ optname ]
51
+ when FalseClass, NilClass
52
+ return [ optname.sub(/\A--/, '--no-') ] if optname.start_with?( '--' )
53
+ when String, Numeric
54
+ if optname.start_with?( '--' )
55
+ return [ "#{optname}=#{value}" ]
51
56
  else
52
- raise ArgumentError, "can't handle command option: %p" % [{ name => val }]
57
+ return [ optname, value ]
53
58
  end
54
- end.compact
59
+ when Array
60
+ return value.map {|v| self.make_command_option(optname, v) }
61
+ else
62
+ raise ArgumentError, "can't handle command option: %p" % [{ name => value }]
63
+ end
55
64
  end
56
65
 
57
66
 
data/lib/hglib.rb CHANGED
@@ -12,7 +12,7 @@ module Hglib
12
12
  Exception2MessageMapper
13
13
 
14
14
  # Package version
15
- VERSION = '0.3.0'
15
+ VERSION = '0.4.0'
16
16
 
17
17
  # Version control revision
18
18
  REVISION = %q$Revision$
@@ -58,7 +58,7 @@ module Hglib
58
58
  def message
59
59
  msg = String.new( encoding: 'utf-8' )
60
60
 
61
- msg << "`%s`: " % [ self.command ]
61
+ msg << "`%s`:" % [ self.command ]
62
62
 
63
63
  if self.multiple?
64
64
  self.messages.each do |errmsg|
@@ -66,7 +66,7 @@ module Hglib
66
66
  end
67
67
  msg << "\n"
68
68
  else
69
- msg << self.messages.first
69
+ msg << ' ' << self.messages.first
70
70
  end
71
71
 
72
72
  return msg
@@ -97,11 +97,18 @@ module Hglib
97
97
  autoload :Repo, 'hglib/repo'
98
98
 
99
99
 
100
- ### Return an Hglib::Server set to use the current ::hg_path, creating one if
101
- ### necessary.
102
- def self::server( repo='.' )
103
- @hg_servers ||= {}
104
- return @hg_servers[ repo ] ||= Hglib::Server.new( repo )
100
+ ### Return an Hglib::Server started with no repository.
101
+ def self::server
102
+ return @hg_server ||= Hglib::Server.new( nil )
103
+ end
104
+
105
+
106
+ ### Shut down and remove the ::server if one exists. Mostly used for testing.
107
+ def self::reset_server
108
+ if ( server = @hg_server )
109
+ @hg_server = nil
110
+ server.stop
111
+ end
105
112
  end
106
113
 
107
114
 
@@ -124,7 +131,7 @@ module Hglib
124
131
  ### directory with the basename of the +source_repo+ in the current working
125
132
  ### directory.
126
133
  def self::clone( source_repo, local_dir=nil, **options )
127
- output = self.server( nil ).run( :clone, source_repo, local_dir, **options )
134
+ output = self.server.run( :clone, source_repo, local_dir, **options )
128
135
  self.log.debug "Clone output: %s" % [ output ]
129
136
 
130
137
  local_dir ||= Pathname.pwd + File.basename( source_repo )
@@ -135,11 +142,43 @@ module Hglib
135
142
  ### Initialize a repository in the given +dir+ and return a Hglib::Repo
136
143
  ### for it.
137
144
  def self::init( dir, **options )
138
- output = self.server( nil ).run( :init, dir, **options )
145
+ output = self.server.run( :init, dir, **options )
139
146
  self.log.debug "Init output: %s" % [ output ]
140
147
 
141
148
  return self.repo( dir )
142
149
  end
143
150
 
151
+
152
+ ### Fetch a Hash of version information about the Mercurial that is being used.
153
+ def self::versions
154
+ response = self.server.run_with_json_template( :version )
155
+ self.logger.debug "Got a VERSION response: %p" % [ response ]
156
+
157
+ return response.first
158
+ end
159
+
160
+
161
+ ### Fetch the version of Mercurial that's being used as a String.
162
+ def self::version
163
+ return self.versions[ :ver ]
164
+ end
165
+
166
+
167
+ ### Fetch the version of the Mercurial extensions that're being used as a Hash.
168
+ def self::extension_versions
169
+ ext_info = self.versions[ :extensions ]
170
+ return ext_info.each_with_object({}) do |ext, hash|
171
+ ext = ext.dup
172
+ hash[ ext.delete(:name).to_sym ] = ext
173
+ end
174
+ end
175
+
176
+
177
+ ### Returns +true+ if the extension with the given +name+ is enabled in the
178
+ ### current (global) configuration.
179
+ def self::extension_enabled?( name )
180
+ return self.extension_versions.key?( name.to_sym )
181
+ end
182
+
144
183
  end # module Hglib
145
184
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative '../../spec_helper'
4
4
 
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative '../../spec_helper'
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
@@ -92,6 +92,46 @@ RSpec.describe Hglib::Repo do
92
92
  end
93
93
 
94
94
 
95
+ it "knows if there are uncommitted changes" do
96
+ repo = described_class.new( repo_dir )
97
+
98
+ expect( server ).to receive( :run_with_json_template ).
99
+ with( :identify, nil, {} ).
100
+ and_return( [{
101
+ bookmarks: ["v1.1", "live", "master"],
102
+ branch: "default",
103
+ dirty: "+",
104
+ id: "720c115412188539039b87baf57931fb5415a0bf+",
105
+ node: "ffffffffffffffffffffffffffffffffffffffff",
106
+ parents: ["720c115412188539039b87baf57931fb5415a0bf"],
107
+ tags: ["tip"]
108
+ }] ).twice
109
+
110
+ expect( repo ).to be_dirty
111
+ expect( repo ).to_not be_clean
112
+ end
113
+
114
+
115
+ it "knows if there aren't any uncommitted changes" do
116
+ repo = described_class.new( repo_dir )
117
+
118
+ expect( server ).to receive( :run_with_json_template ).
119
+ with( :identify, nil, {} ).
120
+ and_return( [{
121
+ bookmarks: ["v1.1", "live", "master"],
122
+ branch: "default",
123
+ dirty: false,
124
+ id: "720c115412188539039b87baf57931fb5415a0bf+",
125
+ node: "ffffffffffffffffffffffffffffffffffffffff",
126
+ parents: ["720c115412188539039b87baf57931fb5415a0bf"],
127
+ tags: ["tip"]
128
+ }] ).twice
129
+
130
+ expect( repo ).to_not be_dirty
131
+ expect( repo ).to be_clean
132
+ end
133
+
134
+
95
135
  it "can fetch the log of the repository" do
96
136
  repo = described_class.new( repo_dir )
97
137
 
@@ -234,64 +274,137 @@ RSpec.describe Hglib::Repo do
234
274
  expect( result ).to eq( "signing 47:66d4e21b7018" )
235
275
  end
236
276
 
237
- describe "version info" do
238
-
239
- let( :version_info ) {[{
240
- extensions: [
241
- {bundled: true, name: "churn", ver: nil},
242
- {bundled: true, name: "convert", ver: nil},
243
- {bundled: false, name: "evolve", ver: "9.2.0"},
244
- {bundled: true, name: "extdiff", ver: nil},
245
- {bundled: true, name: "gpg", ver: nil},
246
- {bundled: false, name: "hggit", ver: "0.8.12 (dulwich 0.19.10)"},
247
- {bundled: true, name: "strip", ver: nil},
248
- {bundled: true, name: "mq", ver: nil},
249
- {bundled: false, name: "prompt", ver: nil},
250
- {bundled: true, name: "purge", ver: nil},
251
- {bundled: true, name: "rebase", ver: nil},
252
- {bundled: false, name: "topic", ver: "0.17.0"},
253
- {bundled: true, name: "histedit", ver: nil}
254
- ],
255
- ver: "5.1.1"
256
- }]}
257
-
258
- before( :each ) do
259
- expect( server ).to receive( :run_with_json_template ).
260
- with( :version ).
261
- and_return( version_info )
277
+
278
+ describe "phases" do
279
+
280
+ it "can test the phase of the current revision" do
281
+ repo = described_class.new( repo_dir )
282
+
283
+ expect( server ).to receive( :run ).
284
+ with( :phase, nil, {} ).
285
+ and_return( "18: draft\n" )
286
+
287
+ result = repo.phase
288
+
289
+ expect( result ).to eq( {18 => :draft} )
262
290
  end
263
291
 
264
292
 
265
- it "can fetch the versions of Mercurial and loaded extensions" do
293
+ it "can test the phase of an arbitrary revision" do
266
294
  repo = described_class.new( repo_dir )
267
295
 
268
- result = repo.versions
296
+ expect( server ).to receive( :run ).
297
+ with( :phase, '41c796d06fa398573ecec464238b827bfe75c7cd', {} ).
298
+ and_return( "12: draft\n" )
299
+
300
+ result = repo.phase( '41c796d06fa398573ecec464238b827bfe75c7cd' )
269
301
 
270
- expect( result ).to eq( version_info.first )
302
+ expect( result ).to eq( {12 => :draft} )
271
303
  end
272
304
 
273
305
 
274
- it "can fetch the simple version of Mercurial" do
306
+ it "can test the phase of an arbitrary revision with the rev option" do
275
307
  repo = described_class.new( repo_dir )
276
308
 
277
- result = repo.version
309
+ expect( server ).to receive( :run ).
310
+ with( :phase, nil, rev: '41c796d06fa398573ecec464238b827bfe75c7cd' ).
311
+ and_return( "12: draft\n" )
312
+
313
+ result = repo.phase( rev: '41c796d06fa398573ecec464238b827bfe75c7cd' )
314
+
315
+ expect( result ).to eq( {12 => :draft} )
316
+ end
317
+
318
+
319
+ it "can test the phase of an arbitrary revset" do
320
+ repo = described_class.new( repo_dir )
321
+
322
+ expect( server ).to receive( :run ).
323
+ with( :phase, '13:10', {} ).
324
+ and_return( "13: secret\n12: draft\n11: public\n10: public\n" )
325
+
326
+ result = repo.phase( '13:10' )
327
+
328
+ expect( result ).to eq( {13 => :secret, 12 => :draft, 11 => :public, 10 => :public} )
329
+ end
330
+
331
+
332
+ it "can change the phase of the current revision to `public`" do
333
+ repo = described_class.new( repo_dir )
334
+
335
+ expect( server ).to receive( :run ).
336
+ with( :phase, nil, public: true ).
337
+ and_return( '' )
338
+
339
+ result = repo.phase( public: true )
340
+
341
+ expect( result ).to eq( {} )
342
+ end
343
+
344
+
345
+ it "can change the phase of the current revision to `draft`" do
346
+ repo = described_class.new( repo_dir )
347
+
348
+ expect( server ).to receive( :run ).
349
+ with( :phase, nil, draft: true ).
350
+ and_return( '' )
351
+
352
+ result = repo.phase( draft: true )
353
+
354
+ expect( result ).to eq( {} )
355
+ end
356
+
357
+
358
+ it "can change the phase of the current revision to `secret`" do
359
+ repo = described_class.new( repo_dir )
360
+
361
+ expect( server ).to receive( :run ).
362
+ with( :phase, nil, secret: true ).
363
+ and_return( '' )
364
+
365
+ result = repo.phase( secret: true )
366
+
367
+ expect( result ).to eq( {} )
368
+ end
369
+
370
+
371
+ it "can change the phase of the current revision by force" do
372
+ repo = described_class.new( repo_dir )
373
+
374
+ expect( server ).to receive( :run ).
375
+ with( :phase, nil, draft: true, force: true ).
376
+ and_return( '' )
377
+
378
+ result = repo.phase( draft: true, force: true )
379
+
380
+ expect( result ).to eq( {} )
381
+ end
382
+
383
+
384
+ it "can change the phase of an arbitrary revision" do
385
+ repo = described_class.new( repo_dir )
386
+
387
+ expect( server ).to receive( :run ).
388
+ with( :phase, '41c796d06fa398573ecec464238b827bfe75c7cd', public: true ).
389
+ and_return( '' )
390
+
391
+ result = repo.phase( '41c796d06fa398573ecec464238b827bfe75c7cd', public: true )
278
392
 
279
- expect( result ).to eq( version_info.first[:ver] )
393
+ expect( result ).to eq( {} )
280
394
  end
281
395
 
282
396
 
283
- it "can fetch the versions of all loaded Mercurial extensions" do
397
+ it "can test the phase of the current revision" do
284
398
  repo = described_class.new( repo_dir )
285
399
 
286
- result = repo.extension_versions
400
+ expect( server ).to receive( :run ).
401
+ with( :phase, nil, {} ).
402
+ and_return( "18: draft\n" ).
403
+ at_least( :once )
287
404
 
288
- expect( result ).to be_a( Hash )
289
- expect( result ).to include(
290
- churn: {bundled: true, ver: nil},
291
- evolve: {bundled: false, ver: '9.2.0'},
292
- topic: {bundled: false, ver: '0.17.0'},
293
- hggit: {bundled: false, ver: "0.8.12 (dulwich 0.19.10)"}
294
- )
405
+ expect( repo ).to_not be_public
406
+ expect( repo ).to be_draft
407
+ expect( repo ).to_not be_secret
295
408
  end
296
409
 
297
410
  end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative '../spec_helper'
4
4
 
data/spec/hglib_spec.rb CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env rspec -cfd
1
+ #!/usr/bin/env ruby -S rspec -cfd
2
2
 
3
3
  require_relative 'spec_helper'
4
4
 
@@ -40,10 +40,10 @@ RSpec.describe Hglib do
40
40
 
41
41
  describe "server" do
42
42
 
43
- it "can create a server object" do
43
+ it "can create a server object with no repository" do
44
44
  expect( described_class.server ).to be_a( Hglib::Server )
45
45
  expect( described_class.server ).to equal( described_class.server )
46
- expect( described_class.server.repo ).to eq( Pathname('.') )
46
+ expect( described_class.server.repo ).to be_nil
47
47
  end
48
48
 
49
49
  end
@@ -106,7 +106,7 @@ RSpec.describe Hglib do
106
106
 
107
107
  expect( exception ).to be_multiple
108
108
  expect( exception.message ).to eq( <<~ERROR_MESSAGE )
109
- `status`:
109
+ `status`:
110
110
  - no_status: No such file or directory
111
111
  - unknown: No such file or directory
112
112
  ERROR_MESSAGE
@@ -114,5 +114,78 @@ RSpec.describe Hglib do
114
114
 
115
115
  end
116
116
 
117
+
118
+
119
+ describe "version info" do
120
+
121
+ let( :version_info ) {[{
122
+ extensions: [
123
+ {bundled: true, name: "churn", ver: nil},
124
+ {bundled: true, name: "convert", ver: nil},
125
+ {bundled: false, name: "evolve", ver: "9.2.0"},
126
+ {bundled: true, name: "extdiff", ver: nil},
127
+ {bundled: true, name: "gpg", ver: nil},
128
+ {bundled: false, name: "hggit", ver: "0.8.12 (dulwich 0.19.10)"},
129
+ {bundled: true, name: "strip", ver: nil},
130
+ {bundled: true, name: "mq", ver: nil},
131
+ {bundled: false, name: "prompt", ver: nil},
132
+ {bundled: true, name: "purge", ver: nil},
133
+ {bundled: true, name: "rebase", ver: nil},
134
+ {bundled: false, name: "topic", ver: "0.17.0"},
135
+ {bundled: true, name: "histedit", ver: nil}
136
+ ],
137
+ ver: "5.1.1"
138
+ }]}
139
+
140
+ let( :server ) { instance_double(Hglib::Server, stop: nil) }
141
+
142
+
143
+ before( :each ) do
144
+ described_class.reset_server
145
+ allow( Hglib::Server ).to receive( :new ).and_return( server )
146
+ expect( server ).to receive( :run_with_json_template ).
147
+ with( :version ).
148
+ and_return( version_info ).
149
+ at_least( :once )
150
+ end
151
+ after( :each ) do
152
+ described_class.reset_server
153
+ end
154
+
155
+
156
+ it "can fetch the versions of Mercurial and loaded extensions" do
157
+ result = described_class.versions
158
+
159
+ expect( result ).to eq( version_info.first )
160
+ end
161
+
162
+
163
+ it "can fetch the simple version of Mercurial" do
164
+ result = described_class.version
165
+
166
+ expect( result ).to eq( version_info.first[:ver] )
167
+ end
168
+
169
+
170
+ it "can fetch the versions of all loaded Mercurial extensions" do
171
+ result = described_class.extension_versions
172
+
173
+ expect( result ).to be_a( Hash )
174
+ expect( result ).to include(
175
+ churn: {bundled: true, ver: nil},
176
+ evolve: {bundled: false, ver: '9.2.0'},
177
+ topic: {bundled: false, ver: '0.17.0'},
178
+ hggit: {bundled: false, ver: "0.8.12 (dulwich 0.19.10)"}
179
+ )
180
+ end
181
+
182
+
183
+ it "knows if a given extension is enabled" do
184
+ expect( described_class.extension_enabled?('topic') ).to be_truthy
185
+ expect( described_class.extension_enabled?('keyword') ).to be_falsey
186
+ end
187
+
188
+ end
189
+
117
190
  end
118
191
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hglib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -11,8 +11,8 @@ cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIENDCCApygAwIBAgIBATANBgkqhkiG9w0BAQsFADAiMSAwHgYDVQQDDBdnZWQv
14
- REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xODExMjAxODI5NTlaFw0xOTExMjAxODI5
15
- NTlaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
14
+ REM9RmFlcmllTVVEL0RDPW9yZzAeFw0xOTEwMDkwMDM2NTdaFw0yMDEwMDgwMDM2
15
+ NTdaMCIxIDAeBgNVBAMMF2dlZC9EQz1GYWVyaWVNVUQvREM9b3JnMIIBojANBgkq
16
16
  hkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAvyVhkRzvlEs0fe7145BYLfN6njX9ih5H
17
17
  L60U0p0euIurpv84op9CNKF9tx+1WKwyQvQP7qFGuZxkSUuWcP/sFhDXL1lWUuIl
18
18
  M4uHbGCRmOshDrF4dgnBeOvkHr1fIhPlJm5FO+Vew8tSQmlDsosxLUx+VB7DrVFO
@@ -24,15 +24,15 @@ cert_chain:
24
24
  N2I4L/ZOIe2DIVuYH7aLHfjZDQv/mNgpAgMBAAGjdTBzMAkGA1UdEwQCMAAwCwYD
25
25
  VR0PBAQDAgSwMB0GA1UdDgQWBBRyjf55EbrHagiRLqt5YAd3yb8k4DAcBgNVHREE
26
26
  FTATgRFnZWRARmFlcmllTVVELm9yZzAcBgNVHRIEFTATgRFnZWRARmFlcmllTVVE
27
- Lm9yZzANBgkqhkiG9w0BAQsFAAOCAYEAP9Ffkvg4e8CjIWi8SykQ8oJSS8jbmbgF
28
- abke3vXWLG6V9kFiObuJd5wZRBluJANu7bEtjgc3fFaGVP2XxVdCpVjNbmMDg4Qp
29
- ovvczP53X6pQP2RSZgxF6Lblvy8y11RziUTVRG/Z2aJHsElo6gI7vQznE/OSDrhC
30
- gEhr8uaIUt7D+HZWRbU0+MkKPpL5uMqaFuJbqXEvSwPTuUuYkDfNfsjQO7ruWBac
31
- bxHCrvpZ6Tijc0nrlyXi6gPOCLeaqhau2xFnlvKgELwsGYSoKBJyDwqtQ5kwrOlU
32
- tkSyLrfZ+RZcH535Hyvif7ZxB0v5OxXXoec+N2vrUsEUMRDL9dg4/WFdN8hIOixF
33
- 3IPKpZ1ho0Ya5q7yhygtBK9/NBFHw+nbJjcltfPDBXleRe8u73gnQo8AZIhStYSP
34
- v4qqqa27Bs468d6SoPxjSm8a2mM9HZ4OdWhq4tFsbTeXDVquCfi64OTEaTt2xQdR
35
- JnC4lpJfCP6aCXa5h2XAQfPSH636cQap
27
+ Lm9yZzANBgkqhkiG9w0BAQsFAAOCAYEAFqsr6o0SvQRgjQVmhbQvExRnCMCoW1yb
28
+ FJiN7A5RA2Iy2E61OG1Ul5nGmaDmx/PNB/6JIbIV3B9Uq8aTZx4uOjK7r8vMl1/t
29
+ ZfY7r6HejJfXlcO2m6JDMbpdyEVv916LncBkzZRz6vnnNCx+31f15FKddxujpAFd
30
+ qpn3JRQY+oj7ZkoccL/IUiDpxQWeS3oOoz9qr2kVTp8R50InZimt79FqCl/1m66W
31
+ kdOuf+wM3DDx7Rt4IVNHrhGlyfMr7xjKW1Q3gll+pMN1DT6Ajx/t3JDSEg7BnnEW
32
+ r7AciSO6J4ApUdqyG+coLFlGdtgFTgRHv7ihbQtDI7Z/LV7A4Spn1j2PK3j0Omri
33
+ kSl1hPVigRytfgdVGiLXzvkkrkgj9EknCaj5UHbac7XvVBrljXj9hsnnqTANaKsg
34
+ jBZSA+N+xUTgUWpXjjwsLZjzJkhWATJWq+krNXcqpwXo6HsjmdUxoFMt63RBb+sI
35
+ XrxOxp8o0uOkU7FdLSGsyqJ2LzsR4obN
36
36
  -----END CERTIFICATE-----
37
37
  date: 2019-10-12 00:00:00.000000000 Z
38
38
  dependencies:
metadata.gz.sig CHANGED
Binary file