gollum-rugged_adapter 1.1.2 → 2.0.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: 3b4b572fd56e0608c76ab7b3536ed18a54211571ded4f37dbfe77e296df17bfe
4
- data.tar.gz: e3f2ab7a9ae0ebe06eaa1983426a9f89f78796e8535cb6373d21499d45914c72
3
+ metadata.gz: ff65dc7719f5202705485b44d61a70c6a46451393aeeb7243c820c468da85e69
4
+ data.tar.gz: 336e98811d5cb8c19638f6dd8a85d1c5f17d772f2828cea3230ba109e5aaf695
5
5
  SHA512:
6
- metadata.gz: 4c481c8741c577b5cf0e0af292745c04fea0a32d96f89ed77ddb54db726c510517e35e134ca80ab3ddba8966618814fb1590c590c89e2f453fdab2447a62acba
7
- data.tar.gz: 8b7cbcc97c857862a2e60ddb9beb7f625d5eb184ca7800189d95400cbe38400511075083f0dbd50bef91bbe21c9f38f1ba1599675d83dbb31fe5e72d2b903545
6
+ metadata.gz: 67f5126eea74217c669854445059f74b7363e3473950b7cf34632b8652f61ad9b0efff8a2fa5ad9e05ee66c6a09144139a8a56d0e3b44b2f1511948cd11508ba
7
+ data.tar.gz: ab629d342c8346f067b485450a9d898c9238bdff88d60c96c4dab900da01757d4db0bded4f3fdb28522073e5f340757de6d92320d0a26cac71728d9c98d8c2c1
@@ -17,6 +17,18 @@ module Gollum
17
17
  DEFAULT_MIME_TYPE = "text/plain"
18
18
  class NoSuchShaFound < StandardError; end
19
19
 
20
+ def self.global_default_branch
21
+ Rugged::Config.global['init.defaultBranch']
22
+ end
23
+
24
+ def self.default_ref_for_repo(repo)
25
+ begin
26
+ repo.head.name
27
+ rescue Rugged::ReferenceError
28
+ self.global_default_branch || 'refs/heads/master'
29
+ end
30
+ end
31
+
20
32
  class Actor
21
33
 
22
34
  attr_accessor :name, :email, :time
@@ -168,7 +180,7 @@ module Gollum
168
180
  end
169
181
 
170
182
  def exist?
171
- ::File.exists?(@repo.path)
183
+ ::File.exist?(@repo.path)
172
184
  end
173
185
 
174
186
  def grep(search_terms, options={}, &block)
@@ -239,7 +251,7 @@ module Gollum
239
251
  end
240
252
  end
241
253
 
242
- def log(ref = 'refs/heads/master', path = nil, options = {})
254
+ def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
243
255
  default_options = {
244
256
  :limit => options[:max_count] ? options[:max_count] : 10,
245
257
  :offset => options[:skip] ? options[:skip] : 0,
@@ -265,7 +277,7 @@ module Gollum
265
277
  end
266
278
 
267
279
  def ls_files(query, options = {})
268
- ref = options[:ref] || "refs/heads/master"
280
+ ref = options[:ref] || Gollum::Git.default_ref_for_repo(@repo)
269
281
  tree = @repo.lookup(sha_from_ref(ref)).tree
270
282
  tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
271
283
  results = []
@@ -459,6 +471,7 @@ module Gollum
459
471
  def initialize(index, repo)
460
472
  @index = index
461
473
  @rugged_repo = repo
474
+ @default_ref = Gollum::Git.default_ref_for_repo(@rugged_repo)
462
475
  @treemap = {}
463
476
  end
464
477
 
@@ -479,7 +492,7 @@ module Gollum
479
492
  @index
480
493
  end
481
494
 
482
- def commit(message, parents = nil, actor = nil, last_tree = nil, head = 'refs/heads/master')
495
+ def commit(message, parents = nil, actor = nil, last_tree = nil, head = @default_ref)
483
496
  commit_options = {}
484
497
  head = "refs/heads/#{head}" unless head =~ /^refs\/heads\//
485
498
  parents = get_parents(parents, head) || []
@@ -597,7 +610,7 @@ module Gollum
597
610
  end
598
611
  end
599
612
 
600
- def commits(start = 'refs/heads/master', max_count = 10, skip = 0)
613
+ def commits(start = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0)
601
614
  git.log(start, nil, :max_count => max_count, :skip => skip)
602
615
  end
603
616
 
@@ -618,7 +631,7 @@ module Gollum
618
631
  @repo.diff(sha1, sha2, opts).patch.force_encoding('utf-8')
619
632
  end
620
633
 
621
- def log(commit = 'refs/heads/master', path = nil, options = {})
634
+ def log(commit = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
622
635
  git.log(commit, path, **options)
623
636
  end
624
637
 
@@ -648,6 +661,14 @@ module Gollum
648
661
  @repo.checkout(ref, :strategy => :force) unless @repo.bare?
649
662
  end
650
663
  end
664
+
665
+ # Find the first existing branch in an Array of branch names of the form ['main', ...] and return its String name.
666
+ def find_branch(search_list)
667
+ all_branches = @repo.branches.to_a.map {|b| b.name}
668
+ search_list.find do |branch_name|
669
+ all_branches.include?(branch_name)
670
+ end
671
+ end
651
672
  end
652
673
 
653
674
  class Tree
@@ -1,7 +1,7 @@
1
1
  module Gollum
2
2
  module Lib
3
3
  module Git
4
- VERSION = '1.1.2'
4
+ VERSION = '2.0.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-rugged_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bart Kamphorst, Dawa Ometto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-22 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged