gollum-rjgit_adapter 0.6.1-java → 1.0-java

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: ac50e5f74344c41b8825a441c882de7b4ae8b1659dfcf87005d7fe5a6379a078
4
- data.tar.gz: 6b9f7fe732d3cfa7a3043c3371905426bbdb33843238c876cf83bc09b7a2a148
3
+ metadata.gz: 6bdbce54e2c9a4776e5f86ca0a2b549d35e3be6d816afb83e3ac028af24b9756
4
+ data.tar.gz: 5373306b3d9279ab924eede20362ea9ee9aea96f875a1b17f0bbc31d9cd936f4
5
5
  SHA512:
6
- metadata.gz: 6971e4b7bd7e5c26d2b0e0a7cd0dcd52e759fd01c6378112478e8874d7af295be3f84d928d2c9a5f91337d7ab5ba68037e380379420bc64407e238f6423ffc3b
7
- data.tar.gz: 3524aff2bd136eda0eb80d12ad833b845095cb570faf2d5f2cc3250041e57744888c6934f9a12653ffca9f6c12457e212673c5bd4cd6d191825649c341511c49
6
+ metadata.gz: 7467a015e62e23f710f0fe8e9e6e0a2a9e9216966cb9a57d2883d95ee000ae35087932624495e6a76569a849981f3523d62d4f4ae13776a5564b467f652f1216
7
+ data.tar.gz: 4f0b0910be9ecf5767a65a99f730c609062b8bedda96759c7dc27d80f8c07035aa143e26938544feb5404c808927af1e101fc02fab27554fae77223354ba6ba3
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Adapter for Gollum to use RJGit at the backend.}
13
13
  s.description = %q{Adapter for Gollum to use RJGit at the backend.}
14
14
 
15
- s.add_runtime_dependency "rjgit", "> 5.7.0", "~> 5.7.0"
15
+ s.add_runtime_dependency "rjgit", "~> 6.1"
16
16
  s.add_development_dependency "rspec", "3.4.0"
17
17
 
18
18
  s.files = Dir['lib/**/*.rb'] + ["README.md", "Gemfile"]
@@ -15,15 +15,40 @@ module Gollum
15
15
 
16
16
  import 'org.eclipse.jgit.revwalk.RevWalk'
17
17
  import 'org.eclipse.jgit.lib.ObjectId'
18
+ import org.eclipse.jgit.lib.ConfigConstants
18
19
 
19
- # Convert refspec to jgit canonical form
20
+ BACKUP_DEFAULT_REF = 'refs/heads/master'
21
+
22
+ def self.head_ref_name(repo)
23
+ r = RJGit.repository_type(repo)
24
+ begin
25
+ # Mimic rugged's behavior: if HEAD points at a given ref, but that ref has no commits yet, return nil
26
+ r.resolve('HEAD') ? r.getFullBranch : nil
27
+ rescue Java::OrgEclipseJgitApiErrors::RefNotFoundException
28
+ nil
29
+ end
30
+ end
31
+
32
+ def self.global_default_branch
33
+ org.eclipse.jgit.util.SystemReader.getInstance().getUserConfig().getString(ConfigConstants::CONFIG_INIT_SECTION, nil, ConfigConstants::CONFIG_KEY_DEFAULT_BRANCH)
34
+ end
35
+
36
+ def self.default_ref_for_repo(repo)
37
+ self.head_ref_name(repo) || self.global_default_branch || BACKUP_DEFAULT_REF
38
+ end
39
+
40
+ # Don't touch if ref is a SHA or Git::Ref, otherwise convert it to jgit canonical form
20
41
  def self.canonicalize(ref)
21
- return ref if sha?(ref)
22
- return 'refs/heads/master' if ref.nil?
42
+ return ref if ref.is_a?(String) and sha?(ref)
23
43
  result = ref.is_a?(Gollum::Git::Ref) ? ref.name : ref
24
44
  (result =~ /^refs\/heads\// || result.upcase == 'HEAD') ? result : "refs/heads/#{result}"
25
45
  end
26
46
 
47
+ def self.decanonicalize(ref_name)
48
+ match = /^refs\/heads\/(.*)/.match(ref_name)
49
+ match ? match[1] : nil
50
+ end
51
+
27
52
  def self.sha?(str)
28
53
  !!(str =~ /^[0-9a-f]{40}$/)
29
54
  end
@@ -176,7 +201,7 @@ module Gollum
176
201
  end
177
202
 
178
203
  def grep(query, options={}, &block)
179
- ref = Gollum::Git.canonicalize(options[:ref])
204
+ ref = options[:ref] ? Gollum::Git.canonicalize(options[:ref]) : Gollum::Git.default_ref_for_repo(@git.jrepo)
180
205
  results = []
181
206
  walk = RevWalk.new(@git.jrepo)
182
207
  RJGit::Porcelain.ls_tree(@git.jrepo, options[:path], ref, {:recursive => true}).each do |item|
@@ -193,10 +218,13 @@ module Gollum
193
218
  end
194
219
 
195
220
  def checkout(path, ref, options = {})
196
- ref = Gollum::Git.canonicalize(ref)
221
+ options[:commit] = if ref == 'HEAD'
222
+ "#{Gollum::Git.default_ref_for_repo(@git.jrepo)}"
223
+ else
224
+ "#{Gollum::Git.canonicalize(ref)}}"
225
+ end
197
226
  options[:paths] = [path]
198
227
  options[:force] = true
199
- options[:commit] = "#{ref}^{commit}"
200
228
  @git.checkout(ref, options)
201
229
  end
202
230
 
@@ -213,16 +241,16 @@ module Gollum
213
241
  end
214
242
  end
215
243
 
216
- def revert_path(path, sha1, sha2, ref = 'HEAD^{commit}')
244
+ def revert_path(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
217
245
  result, _paths = revert(path, sha1, sha2, ref)
218
246
  result
219
247
  end
220
248
 
221
- def revert_commit(sha1, sha2, ref = 'HEAD^{commit}')
249
+ def revert_commit(sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
222
250
  revert(nil, sha1, sha2, ref)
223
251
  end
224
252
 
225
- def revert(path, sha1, sha2, ref)
253
+ def revert(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
226
254
  patch = generate_patch(sha1, sha2, path)
227
255
  return false unless patch
228
256
  begin
@@ -238,10 +266,9 @@ module Gollum
238
266
  @git.cat_file(options, sha)
239
267
  end
240
268
 
241
- def log(ref = 'refs/heads/master', path = nil, options = {})
242
- ref = Gollum::Git.canonicalize(ref)
269
+ def log(ref = Gollum::Git.default_ref_for_repo(@git.jrepo), path = nil, options = {})
243
270
  options[:list_renames] = true if path && options[:follow]
244
- @git.log(path, ref, options).map {|commit| Gollum::Git::Commit.new(commit)}
271
+ @git.log(path, Gollum::Git.canonicalize(ref), options).map {|commit| Gollum::Git::Commit.new(commit)}
245
272
  end
246
273
 
247
274
  def versions_for_path(path, ref, options)
@@ -283,11 +310,10 @@ module Gollum
283
310
  @index.add(path, data)
284
311
  end
285
312
 
286
- def commit(message, parents = nil, actor = nil, last_tree = nil, ref = 'refs/heads/master')
287
- ref = Gollum::Git.canonicalize(ref)
313
+ def commit(message, parents = nil, actor = nil, last_tree = nil, ref = Gollum::Git.default_ref_for_repo(@index.jrepo))
288
314
  actor = actor ? actor.actor : RJGit::Actor.new('Gollum', 'gollum@wiki')
289
315
  parents = parents.map{|parent| parent.commit} if parents
290
- commit_data = @index.commit(message, actor, parents, ref)
316
+ commit_data = @index.commit(message, actor, parents, Gollum::Git.canonicalize(ref))
291
317
  return false if !commit_data
292
318
  commit_data[2]
293
319
  end
@@ -313,8 +339,8 @@ module Gollum
313
339
  end
314
340
 
315
341
  class Ref
316
- def initialize(name, commit)
317
- @name, @commit = name, commit
342
+ def initialize(commit, name)
343
+ @commit, @name = commit, name
318
344
  end
319
345
 
320
346
  def name
@@ -367,8 +393,7 @@ module Gollum
367
393
  end
368
394
 
369
395
  def commit(ref)
370
- ref = Gollum::Git.canonicalize(ref)
371
- objectid = @repo.jrepo.resolve(ref)
396
+ objectid = @repo.jrepo.resolve(Gollum::Git.canonicalize(ref))
372
397
  return nil if objectid.nil?
373
398
  id = objectid.name
374
399
  commit = @repo.find(id, :commit)
@@ -378,8 +403,7 @@ module Gollum
378
403
  raise Gollum::Git::NoSuchShaFound
379
404
  end
380
405
 
381
- def commits(ref = nil, max_count = 10, skip = 0)
382
- ref = Gollum::Git.canonicalize(ref)
406
+ def commits(ref = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0)
383
407
  @repo.commits(ref, max_count).map{|commit| Gollum::Git::Commit.new(commit)}
384
408
  end
385
409
 
@@ -391,16 +415,15 @@ module Gollum
391
415
  # @wiki.repo.head.commit.sha
392
416
  def head
393
417
  return nil unless @repo.head
394
- Gollum::Git::Ref.new('refs/heads/master', @repo.head)
418
+ Gollum::Git::Ref.new(@repo.head, Gollum::Git.head_ref_name(@repo))
395
419
  end
396
420
 
397
421
  def index
398
422
  @index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo))
399
423
  end
400
424
 
401
- def log(ref = 'refs/heads/master', path = nil, options = {})
402
- commit = Gollum::Git.canonicalize(commit)
403
- git.log(ref, path, options)
425
+ def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
426
+ git.log(Gollum::Git.canonicalize(ref), path, options)
404
427
  end
405
428
 
406
429
  def lstree(sha, options={})
@@ -416,16 +439,24 @@ module Gollum
416
439
  @repo.path
417
440
  end
418
441
 
419
- def update_ref(ref = 'refs/heads/master', commit_sha)
420
- ref = Gollum::Git.canonicalize(head)
442
+ def update_ref(ref, commit_sha)
421
443
  cm = self.commit(commit_sha)
422
- @repo.update_ref(cm.commit, true, ref)
444
+ @repo.update_ref(cm.commit, true, Gollum::Git.canonicalize(ref))
423
445
  end
424
446
 
425
447
  def diff(sha1, sha2, path = nil)
426
448
  RJGit::Porcelain.diff(@repo, {:old_rev => sha1, :new_rev => sha2, :file_path => path, :patch => true}).inject("") {|result, diff| result << diff[:patch]}
427
449
  end
428
-
450
+
451
+ # Find the first existing branch in an Array of branch names of the form ['main', ...] and return its String name.
452
+ def find_branch(search_list)
453
+ search_list.find do |branch_name|
454
+ @repo.branches.find do |canonical_name|
455
+ Gollum::Git.decanonicalize(canonical_name) == branch_name
456
+ end
457
+ end
458
+ end
459
+
429
460
  end
430
461
 
431
462
  class Tree
@@ -1,7 +1,7 @@
1
1
  module Gollum
2
2
  module Lib
3
3
  module Git
4
- VERSION = '0.6.1'
4
+ VERSION = '1.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-rjgit_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: '1.0'
5
5
  platform: java
6
6
  authors:
7
7
  - Bart Kamphorst, Dawa Ometto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-28 00:00:00.000000000 Z
11
+ date: 2022-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">"
17
- - !ruby/object:Gem::Version
18
- version: 5.7.0
19
16
  - - "~>"
20
17
  - !ruby/object:Gem::Version
21
- version: 5.7.0
18
+ version: '6.1'
22
19
  name: rjgit
23
- type: :runtime
24
20
  prerelease: false
21
+ type: :runtime
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">"
28
- - !ruby/object:Gem::Version
29
- version: 5.7.0
30
24
  - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 5.7.0
26
+ version: '6.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  requirement: !ruby/object:Gem::Requirement
35
29
  requirements:
@@ -37,8 +31,8 @@ dependencies:
37
31
  - !ruby/object:Gem::Version
38
32
  version: 3.4.0
39
33
  name: rspec
40
- type: :development
41
34
  prerelease: false
35
+ type: :development
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - '='
@@ -77,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
71
  - !ruby/object:Gem::Version
78
72
  version: '0'
79
73
  requirements: []
80
- rubygems_version: 3.0.6
74
+ rubygems_version: 3.2.29
81
75
  signing_key:
82
76
  specification_version: 4
83
77
  summary: Adapter for Gollum to use RJGit at the backend.