gollum-rugged_adapter 1.1 → 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: 37cb3c6ab907f0e07284c8e86a4846fbc50835b1077ec78317ec8c6fe1338b8a
4
- data.tar.gz: 4d55049d3ef2801916730be8544843a301f692cd077795cce15048c605a4ea3b
3
+ metadata.gz: ff65dc7719f5202705485b44d61a70c6a46451393aeeb7243c820c468da85e69
4
+ data.tar.gz: 336e98811d5cb8c19638f6dd8a85d1c5f17d772f2828cea3230ba109e5aaf695
5
5
  SHA512:
6
- metadata.gz: 1564a85095a897ed8b4acb0fa5ccbdbd502ddde945945687edea68ddabfae008e0a566b0198ade261da1d49d1f7c763f2842018a1751b857a0a823773c15cbd7
7
- data.tar.gz: 95a38d72f09c71de0145084f8afeb7ef97ee204967794fe97c30b0528f6c7a8a207ea6271f3e92f35c883226c02d6b901cddbeb8ef968bb9947dad29c66c68de
6
+ metadata.gz: 67f5126eea74217c669854445059f74b7363e3473950b7cf34632b8652f61ad9b0efff8a2fa5ad9e05ee66c6a09144139a8a56d0e3b44b2f1511948cd11508ba
7
+ data.tar.gz: ab629d342c8346f067b485450a9d898c9238bdff88d60c96c4dab900da01757d4db0bded4f3fdb28522073e5f340757de6d92320d0a26cac71728d9c98d8c2c1
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/gollum-rugged_adapter.svg)](http://badge.fury.io/rb/gollum-rugged_adapter)
2
- [![Build Status](https://travis-ci.org/gollum/rugged_adapter.svg?branch=master)](https://travis-ci.org/gollum/rugged_adapter)
2
+ ![Build Status](https://github.com/gollum/rugged_adapter/actions/workflows/test.yaml/badge.svg)
3
3
  [![Dependency Status](https://gemnasium.com/gollum/rugged_adapter.svg)](https://gemnasium.com/gollum/rugged_adapter)
4
4
 
5
5
  ## DESCRIPTION
@@ -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,13 +180,13 @@ 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)
175
187
  ref = options[:ref] ? options[:ref] : "HEAD"
176
188
  tree = @repo.lookup(sha_from_ref(ref)).tree
177
- tree = @repo.lookup(tree[options[:path]][:oid]) if options[:path]
189
+ tree = @repo.lookup(tree.path(options[:path])[:oid]) if options[:path]
178
190
  enc = options.fetch(:encoding, 'utf-8')
179
191
  results = []
180
192
  tree.walk_blobs(:postorder) do |root, entry|
@@ -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
 
@@ -615,10 +628,10 @@ module Gollum
615
628
 
616
629
  def diff(sha1, sha2, *paths)
617
630
  opts = paths.nil? ? {} : {:paths => paths}
618
- @repo.diff(sha1, sha2, opts).patch
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'
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'
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-03-27 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
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.1.4
89
+ rubygems_version: 3.0.3
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Adapter for Gollum to use Rugged (libgit2) at the backend.