gollum-rjgit_adapter 0.6.1-java → 1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/Rakefile +58 -2
- data/gollum-rjgit_adapter.gemspec +1 -1
- data/lib/rjgit_adapter/git_layer_rjgit.rb +68 -29
- data/lib/rjgit_adapter/version.rb +1 -1
- metadata +7 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8320bee3de062a2a2766b026cb4604a070bc335eb3a5caaec00da60ae1afe18
|
4
|
+
data.tar.gz: 859167265d4a159c42b659bb9d96aadfaf9169923c8df059154a34355c71a111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7d23fa515e68a8bc97de2c893b7ab6a916025bdb10627db826b314be34d872629bd79304747294520d8ffd348e3e080c63df3b962b2b6790fc5e2adf50b42cb
|
7
|
+
data.tar.gz: 7e89aaf1c081f2532c949c84d6044450b0b375dceeb6d82942122070b47f6ceb293988bbf338b93d24e607e37e1e84d7136d4d4b1325b39ac068fdccdb9c30c5
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
gollum-lib_rjgit_adapter
|
2
2
|
========================
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/gollum-rjgit_adapter.svg)](http://badge.fury.io/rb/gollum-rjgit_adapter)
|
4
|
-
|
4
|
+
![Build Status](https://github.com/gollum/rjgit_adapter/actions/workflows/test.yml/badge.svg)
|
5
|
+
[![Cutting Edge Dependency Status](https://cuttingedge.onrender.com/github/gollum/rjgit_adapter/svg 'Cutting Edge Dependency Status')](https://cuttingedge.onrender.com/github/gollum/rjgit_adapter/info)
|
5
6
|
|
6
7
|
Adapter for Gollum to use [RJGit](https://github.com/repotag/rjgit) at the backend. The adapter requires using [JRuby](https://www.jruby.org/). This adapter is the default when your platform is JRuby, so you need only to `gem install gollum` and then use gollum normally.
|
data/Rakefile
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
require 'tempfile'
|
2
5
|
|
3
6
|
task :default => :rspec
|
4
7
|
|
@@ -8,6 +11,18 @@ def name
|
|
8
11
|
"rjgit_adapter"
|
9
12
|
end
|
10
13
|
|
14
|
+
def date
|
15
|
+
Time.now.strftime("%Y-%m-%d")
|
16
|
+
end
|
17
|
+
|
18
|
+
def latest_changes_file
|
19
|
+
'LATEST_CHANGES.md'
|
20
|
+
end
|
21
|
+
|
22
|
+
def history_file
|
23
|
+
'HISTORY.md'
|
24
|
+
end
|
25
|
+
|
11
26
|
def version
|
12
27
|
line = File.read("lib/rjgit_adapter/version.rb")[/^\s*VERSION\s*=\s*.*/]
|
13
28
|
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
@@ -72,12 +87,13 @@ task :release => :build do
|
|
72
87
|
puts "You must be on the master branch to release!"
|
73
88
|
exit!
|
74
89
|
end
|
90
|
+
Rake::Task[:changelog].execute
|
75
91
|
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
76
92
|
sh "git pull --rebase origin master"
|
77
|
-
sh "git tag v#{version}"
|
93
|
+
sh "git tag v#{version} -m 'Release v#{version}'"
|
78
94
|
sh "git push origin master"
|
79
95
|
sh "git push origin v#{version}"
|
80
|
-
sh "gem push pkg/#{
|
96
|
+
sh "gem push pkg/#{gem_file}"
|
81
97
|
end
|
82
98
|
|
83
99
|
desc 'Publish to rubygems. Same as release'
|
@@ -123,4 +139,44 @@ task :validate do
|
|
123
139
|
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
124
140
|
exit!
|
125
141
|
end
|
142
|
+
end
|
143
|
+
|
144
|
+
desc 'Build changlog'
|
145
|
+
task :changelog do
|
146
|
+
[latest_changes_file, history_file].each do |f|
|
147
|
+
unless File.exist?(f)
|
148
|
+
puts "#{f} does not exist but is required to build a new release."
|
149
|
+
exit!
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
latest_changes = File.open(latest_changes_file)
|
154
|
+
version_pattern = "# #{version}"
|
155
|
+
|
156
|
+
if !`grep "#{version_pattern}" #{history_file}`.empty?
|
157
|
+
puts "#{version} is already described in #{history_file}"
|
158
|
+
exit!
|
159
|
+
end
|
160
|
+
|
161
|
+
begin
|
162
|
+
unless latest_changes.readline.chomp! =~ %r{#{version_pattern}}
|
163
|
+
puts "#{latest_changes_file} should begin with '#{version_pattern}'"
|
164
|
+
exit!
|
165
|
+
end
|
166
|
+
rescue EOFError
|
167
|
+
puts "#{latest_changes_file} is empty!"
|
168
|
+
exit!
|
169
|
+
end
|
170
|
+
|
171
|
+
body = latest_changes.read
|
172
|
+
body.scan(/\s*#\s+\d\.\d.*/) do |match|
|
173
|
+
puts "#{latest_changes_file} may not contain multiple markdown headers!"
|
174
|
+
exit!
|
175
|
+
end
|
176
|
+
|
177
|
+
temp = Tempfile.new
|
178
|
+
temp.puts("#{version_pattern} / #{date}\n#{body}\n\n")
|
179
|
+
temp.close
|
180
|
+
`cat #{history_file} >> #{temp.path}`
|
181
|
+
`cat #{temp.path} > #{history_file}`
|
126
182
|
end
|
@@ -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", "
|
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
|
-
|
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
|
@@ -163,6 +188,14 @@ module Gollum
|
|
163
188
|
end
|
164
189
|
end
|
165
190
|
|
191
|
+
def note(ref='refs/notes/commits')
|
192
|
+
result = @commit.note(ref)
|
193
|
+
result ? result.to_s : nil
|
194
|
+
end
|
195
|
+
|
196
|
+
def note=(msg, ref='refs/notes/commits')
|
197
|
+
@commit.send(:note=,msg,ref)
|
198
|
+
end
|
166
199
|
end
|
167
200
|
|
168
201
|
class Git
|
@@ -176,7 +209,7 @@ module Gollum
|
|
176
209
|
end
|
177
210
|
|
178
211
|
def grep(query, options={}, &block)
|
179
|
-
ref = Gollum::Git.canonicalize(options[:ref])
|
212
|
+
ref = options[:ref] ? Gollum::Git.canonicalize(options[:ref]) : Gollum::Git.default_ref_for_repo(@git.jrepo)
|
180
213
|
results = []
|
181
214
|
walk = RevWalk.new(@git.jrepo)
|
182
215
|
RJGit::Porcelain.ls_tree(@git.jrepo, options[:path], ref, {:recursive => true}).each do |item|
|
@@ -193,10 +226,13 @@ module Gollum
|
|
193
226
|
end
|
194
227
|
|
195
228
|
def checkout(path, ref, options = {})
|
196
|
-
|
229
|
+
options[:commit] = if ref == 'HEAD'
|
230
|
+
"#{Gollum::Git.default_ref_for_repo(@git.jrepo)}"
|
231
|
+
else
|
232
|
+
"#{Gollum::Git.canonicalize(ref)}}"
|
233
|
+
end
|
197
234
|
options[:paths] = [path]
|
198
235
|
options[:force] = true
|
199
|
-
options[:commit] = "#{ref}^{commit}"
|
200
236
|
@git.checkout(ref, options)
|
201
237
|
end
|
202
238
|
|
@@ -213,16 +249,16 @@ module Gollum
|
|
213
249
|
end
|
214
250
|
end
|
215
251
|
|
216
|
-
def revert_path(path, sha1, sha2, ref =
|
252
|
+
def revert_path(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
|
217
253
|
result, _paths = revert(path, sha1, sha2, ref)
|
218
254
|
result
|
219
255
|
end
|
220
256
|
|
221
|
-
def revert_commit(sha1, sha2, ref =
|
257
|
+
def revert_commit(sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
|
222
258
|
revert(nil, sha1, sha2, ref)
|
223
259
|
end
|
224
260
|
|
225
|
-
def revert(path, sha1, sha2, ref)
|
261
|
+
def revert(path, sha1, sha2, ref = Gollum::Git.default_ref_for_repo(@git.jrepo))
|
226
262
|
patch = generate_patch(sha1, sha2, path)
|
227
263
|
return false unless patch
|
228
264
|
begin
|
@@ -238,10 +274,9 @@ module Gollum
|
|
238
274
|
@git.cat_file(options, sha)
|
239
275
|
end
|
240
276
|
|
241
|
-
def log(ref =
|
242
|
-
ref = Gollum::Git.canonicalize(ref)
|
277
|
+
def log(ref = Gollum::Git.default_ref_for_repo(@git.jrepo), path = nil, options = {})
|
243
278
|
options[:list_renames] = true if path && options[:follow]
|
244
|
-
@git.log(path, ref, options).map {|commit| Gollum::Git::Commit.new(commit)}
|
279
|
+
@git.log(path, Gollum::Git.canonicalize(ref), options).map {|commit| Gollum::Git::Commit.new(commit)}
|
245
280
|
end
|
246
281
|
|
247
282
|
def versions_for_path(path, ref, options)
|
@@ -283,11 +318,10 @@ module Gollum
|
|
283
318
|
@index.add(path, data)
|
284
319
|
end
|
285
320
|
|
286
|
-
def commit(message, parents = nil, actor = nil, last_tree = nil, ref =
|
287
|
-
ref = Gollum::Git.canonicalize(ref)
|
321
|
+
def commit(message, parents = nil, actor = nil, last_tree = nil, ref = Gollum::Git.default_ref_for_repo(@index.jrepo))
|
288
322
|
actor = actor ? actor.actor : RJGit::Actor.new('Gollum', 'gollum@wiki')
|
289
323
|
parents = parents.map{|parent| parent.commit} if parents
|
290
|
-
commit_data = @index.commit(message, actor, parents, ref)
|
324
|
+
commit_data = @index.commit(message, actor, parents, Gollum::Git.canonicalize(ref))
|
291
325
|
return false if !commit_data
|
292
326
|
commit_data[2]
|
293
327
|
end
|
@@ -313,8 +347,8 @@ module Gollum
|
|
313
347
|
end
|
314
348
|
|
315
349
|
class Ref
|
316
|
-
def initialize(
|
317
|
-
@
|
350
|
+
def initialize(commit, name)
|
351
|
+
@commit, @name = commit, name
|
318
352
|
end
|
319
353
|
|
320
354
|
def name
|
@@ -367,8 +401,7 @@ module Gollum
|
|
367
401
|
end
|
368
402
|
|
369
403
|
def commit(ref)
|
370
|
-
|
371
|
-
objectid = @repo.jrepo.resolve(ref)
|
404
|
+
objectid = @repo.jrepo.resolve(Gollum::Git.canonicalize(ref))
|
372
405
|
return nil if objectid.nil?
|
373
406
|
id = objectid.name
|
374
407
|
commit = @repo.find(id, :commit)
|
@@ -378,8 +411,7 @@ module Gollum
|
|
378
411
|
raise Gollum::Git::NoSuchShaFound
|
379
412
|
end
|
380
413
|
|
381
|
-
def commits(ref =
|
382
|
-
ref = Gollum::Git.canonicalize(ref)
|
414
|
+
def commits(ref = Gollum::Git.default_ref_for_repo(@repo), max_count = 10, skip = 0)
|
383
415
|
@repo.commits(ref, max_count).map{|commit| Gollum::Git::Commit.new(commit)}
|
384
416
|
end
|
385
417
|
|
@@ -391,16 +423,15 @@ module Gollum
|
|
391
423
|
# @wiki.repo.head.commit.sha
|
392
424
|
def head
|
393
425
|
return nil unless @repo.head
|
394
|
-
Gollum::Git::Ref.new(
|
426
|
+
Gollum::Git::Ref.new(@repo.head, Gollum::Git.head_ref_name(@repo))
|
395
427
|
end
|
396
428
|
|
397
429
|
def index
|
398
430
|
@index ||= Gollum::Git::Index.new(RJGit::Plumbing::Index.new(@repo))
|
399
431
|
end
|
400
432
|
|
401
|
-
def log(ref =
|
402
|
-
|
403
|
-
git.log(ref, path, options)
|
433
|
+
def log(ref = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = {})
|
434
|
+
git.log(Gollum::Git.canonicalize(ref), path, options)
|
404
435
|
end
|
405
436
|
|
406
437
|
def lstree(sha, options={})
|
@@ -416,16 +447,24 @@ module Gollum
|
|
416
447
|
@repo.path
|
417
448
|
end
|
418
449
|
|
419
|
-
def update_ref(ref
|
420
|
-
ref = Gollum::Git.canonicalize(head)
|
450
|
+
def update_ref(ref, commit_sha)
|
421
451
|
cm = self.commit(commit_sha)
|
422
|
-
@repo.update_ref(cm.commit, true, ref)
|
452
|
+
@repo.update_ref(cm.commit, true, Gollum::Git.canonicalize(ref))
|
423
453
|
end
|
424
454
|
|
425
455
|
def diff(sha1, sha2, path = nil)
|
426
456
|
RJGit::Porcelain.diff(@repo, {:old_rev => sha1, :new_rev => sha2, :file_path => path, :patch => true}).inject("") {|result, diff| result << diff[:patch]}
|
427
457
|
end
|
428
|
-
|
458
|
+
|
459
|
+
# Find the first existing branch in an Array of branch names of the form ['main', ...] and return its String name.
|
460
|
+
def find_branch(search_list)
|
461
|
+
search_list.find do |branch_name|
|
462
|
+
@repo.branches.find do |canonical_name|
|
463
|
+
Gollum::Git.decanonicalize(canonical_name) == branch_name
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
429
468
|
end
|
430
469
|
|
431
470
|
class Tree
|
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:
|
4
|
+
version: '1.1'
|
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:
|
11
|
+
date: 2023-03-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:
|
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:
|
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.
|
74
|
+
rubygems_version: 3.3.25
|
81
75
|
signing_key:
|
82
76
|
specification_version: 4
|
83
77
|
summary: Adapter for Gollum to use RJGit at the backend.
|