bringit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/bringit.rb +96 -0
- data/lib/bringit/attributes.rb +129 -0
- data/lib/bringit/blame.rb +73 -0
- data/lib/bringit/blob.rb +175 -0
- data/lib/bringit/blob_snippet.rb +30 -0
- data/lib/bringit/branch.rb +7 -0
- data/lib/bringit/cloning.rb +79 -0
- data/lib/bringit/commit.rb +331 -0
- data/lib/bringit/commit_stats.rb +24 -0
- data/lib/bringit/committing.rb +334 -0
- data/lib/bringit/committing/merge.rb +125 -0
- data/lib/bringit/compare.rb +41 -0
- data/lib/bringit/diff.rb +320 -0
- data/lib/bringit/diff_collection.rb +127 -0
- data/lib/bringit/encoding_helper.rb +56 -0
- data/lib/bringit/hook.rb +87 -0
- data/lib/bringit/index.rb +128 -0
- data/lib/bringit/path_helper.rb +14 -0
- data/lib/bringit/popen.rb +34 -0
- data/lib/bringit/pulling.rb +43 -0
- data/lib/bringit/ref.rb +56 -0
- data/lib/bringit/repository.rb +1230 -0
- data/lib/bringit/rev_list.rb +40 -0
- data/lib/bringit/tag.rb +19 -0
- data/lib/bringit/tree.rb +104 -0
- data/lib/bringit/util.rb +16 -0
- data/lib/bringit/version.rb +5 -0
- data/lib/bringit/version_info.rb +54 -0
- data/lib/bringit/wrapper.rb +136 -0
- metadata +137 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
module Bringit
|
2
|
+
class RevList
|
3
|
+
attr_reader :repository, :env
|
4
|
+
|
5
|
+
ALLOWED_VARIABLES = %w[GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES].freeze
|
6
|
+
|
7
|
+
def initialize(oldrev, newrev, repository:, env: nil)
|
8
|
+
@repository = repository
|
9
|
+
@env = env.presence || {}
|
10
|
+
@args = ["git",
|
11
|
+
"--git-dir=#{repository.path}",
|
12
|
+
"rev-list",
|
13
|
+
"--max-count=1",
|
14
|
+
oldrev,
|
15
|
+
"^#{newrev}"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
Bringit::Popen.popen(@args, nil, parse_environment_variables)
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid?
|
23
|
+
environment_variables.all? do |(name, value)|
|
24
|
+
value.to_s.start_with?(repository.path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def parse_environment_variables
|
31
|
+
return {} unless valid?
|
32
|
+
|
33
|
+
environment_variables
|
34
|
+
end
|
35
|
+
|
36
|
+
def environment_variables
|
37
|
+
@environment_variables ||= env.slice(*ALLOWED_VARIABLES).compact
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/bringit/tag.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Bringit
|
2
|
+
class Tag < Ref
|
3
|
+
attr_reader :object_sha
|
4
|
+
|
5
|
+
def self.find(repository, name)
|
6
|
+
repository.tags.find { |tag| tag.name == name }
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(repository, name, target, message = nil)
|
10
|
+
super(repository, name, target)
|
11
|
+
|
12
|
+
@message = message
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
encode! @message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/bringit/tree.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
module Bringit
|
2
|
+
class Tree
|
3
|
+
include Bringit::EncodingHelper
|
4
|
+
|
5
|
+
attr_accessor :id, :root_id, :name, :path, :type,
|
6
|
+
:mode, :commit_id, :submodule_url
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# Get list of tree objects
|
10
|
+
# for repository based on commit sha and path
|
11
|
+
# Uses rugged for raw objects
|
12
|
+
def where(repository, sha, path = nil)
|
13
|
+
path = path&.sub(%r{\A/*}, '')
|
14
|
+
path = nil if path == '' || path == '/'
|
15
|
+
|
16
|
+
commit = repository.lookup(sha)
|
17
|
+
root_tree = commit.tree
|
18
|
+
|
19
|
+
tree = if path
|
20
|
+
id = find_id_by_path(repository, root_tree.oid, path)
|
21
|
+
if id
|
22
|
+
repository.lookup(id)
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
root_tree
|
28
|
+
end
|
29
|
+
|
30
|
+
tree.map do |entry|
|
31
|
+
new(
|
32
|
+
id: entry[:oid],
|
33
|
+
root_id: root_tree.oid,
|
34
|
+
name: entry[:name],
|
35
|
+
type: entry[:type],
|
36
|
+
mode: entry[:filemode],
|
37
|
+
path: path ? File.join(path, entry[:name]) : entry[:name],
|
38
|
+
commit_id: sha,
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Recursive search of tree id for path
|
44
|
+
#
|
45
|
+
# Ex.
|
46
|
+
# blog/ # oid: 1a
|
47
|
+
# app/ # oid: 2a
|
48
|
+
# models/ # oid: 3a
|
49
|
+
# views/ # oid: 4a
|
50
|
+
#
|
51
|
+
#
|
52
|
+
# Tree.find_id_by_path(repo, '1a', 'app/models') # => '3a'
|
53
|
+
#
|
54
|
+
def find_id_by_path(repository, root_id, path)
|
55
|
+
root_tree = repository.lookup(root_id)
|
56
|
+
path = path.sub(%r{\A/*}, '')
|
57
|
+
path_arr = path.split('/')
|
58
|
+
|
59
|
+
entry = root_tree.find do |entry|
|
60
|
+
entry[:name] == path_arr[0] && entry[:type] == :tree
|
61
|
+
end
|
62
|
+
|
63
|
+
return nil unless entry
|
64
|
+
|
65
|
+
if path_arr.size > 1
|
66
|
+
path_arr.shift
|
67
|
+
find_id_by_path(repository, entry[:oid], path_arr.join('/'))
|
68
|
+
else
|
69
|
+
entry[:oid]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def initialize(options)
|
75
|
+
%w(id root_id name path type mode commit_id).each do |key|
|
76
|
+
self.send("#{key}=", options[key.to_sym])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def name
|
81
|
+
encode! @name
|
82
|
+
end
|
83
|
+
|
84
|
+
def dir?
|
85
|
+
type == :tree
|
86
|
+
end
|
87
|
+
|
88
|
+
def file?
|
89
|
+
type == :blob
|
90
|
+
end
|
91
|
+
|
92
|
+
def submodule?
|
93
|
+
type == :commit
|
94
|
+
end
|
95
|
+
|
96
|
+
def readme?
|
97
|
+
name =~ /^readme/i
|
98
|
+
end
|
99
|
+
|
100
|
+
def contributing?
|
101
|
+
name =~ /^contributing/i
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/bringit/util.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Bringit
|
2
|
+
class VersionInfo
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
attr_reader :major, :minor, :patch
|
6
|
+
|
7
|
+
def self.parse(str)
|
8
|
+
if str && m = str.match(/(\d+)\.(\d+)\.(\d+)/)
|
9
|
+
VersionInfo.new(m[1].to_i, m[2].to_i, m[3].to_i)
|
10
|
+
else
|
11
|
+
VersionInfo.new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(major = 0, minor = 0, patch = 0)
|
16
|
+
@major = major
|
17
|
+
@minor = minor
|
18
|
+
@patch = patch
|
19
|
+
end
|
20
|
+
|
21
|
+
def <=>(other)
|
22
|
+
return unless other.is_a? VersionInfo
|
23
|
+
return unless valid? && other.valid?
|
24
|
+
|
25
|
+
if other.major < @major
|
26
|
+
1
|
27
|
+
elsif @major < other.major
|
28
|
+
-1
|
29
|
+
elsif other.minor < @minor
|
30
|
+
1
|
31
|
+
elsif @minor < other.minor
|
32
|
+
-1
|
33
|
+
elsif other.patch < @patch
|
34
|
+
1
|
35
|
+
elsif @patch < other.patch
|
36
|
+
-1
|
37
|
+
else
|
38
|
+
0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
if valid?
|
44
|
+
"%d.%d.%d" % [@major, @minor, @patch]
|
45
|
+
else
|
46
|
+
"Unknown"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid?
|
51
|
+
@major >= 0 && @minor >= 0 && @patch >= 0 && @major + @minor + @patch > 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bringit
|
4
|
+
# This class encapsulates all git related functionality for convenience.
|
5
|
+
class Wrapper
|
6
|
+
extend ::Bringit::Cloning::ClassMethods
|
7
|
+
include ::Bringit::Committing
|
8
|
+
include ::Bringit::Pulling
|
9
|
+
|
10
|
+
class ::Bringit::Error < ::StandardError; end
|
11
|
+
class ::Bringit::InvalidRefName < ::Bringit::Error; end
|
12
|
+
|
13
|
+
attr_reader :bringit
|
14
|
+
delegate :bare?, :branches, :branch_count, :branch_exists?, :branch_names,
|
15
|
+
:commit_count, :diff, :find_commits, :empty?, :ls_files,
|
16
|
+
:rugged, :tag_names, :tags, to: :bringit
|
17
|
+
|
18
|
+
def self.create(path)
|
19
|
+
raise Error, "Path #{path} already exists." if Pathname.new(path).exist?
|
20
|
+
FileUtils.mkdir_p(File.dirname(path))
|
21
|
+
Rugged::Repository.init_at(path.to_s, :bare)
|
22
|
+
new(path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.destroy(path)
|
26
|
+
new(path.to_s).bringit.repo_exists? && FileUtils.rm_rf(path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(path)
|
30
|
+
@bringit = Bringit::Repository.new(path.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
def repo_exists?
|
34
|
+
bringit.repo_exists?
|
35
|
+
rescue Bringit::Repository::NoRepository
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def path
|
40
|
+
Pathname.new(bringit.
|
41
|
+
instance_variable_get(:@attributes).
|
42
|
+
instance_variable_get(:@path))
|
43
|
+
end
|
44
|
+
|
45
|
+
# Query for a blob
|
46
|
+
def blob(ref, path)
|
47
|
+
Bringit::Blob.find(bringit, ref, path)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Query for a tree
|
51
|
+
def tree(ref, path)
|
52
|
+
Bringit::Tree.where(bringit, ref, path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def commit(ref)
|
56
|
+
Bringit::Commit.find(bringit, ref)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Query for a tree
|
60
|
+
def path_exists?(ref, path)
|
61
|
+
!blob(ref, path).nil? || tree(ref, path).any?
|
62
|
+
end
|
63
|
+
|
64
|
+
def branch_sha(name)
|
65
|
+
bringit.find_branch(name)&.dereferenced_target&.sha
|
66
|
+
end
|
67
|
+
|
68
|
+
def default_branch
|
69
|
+
bringit.discover_default_branch
|
70
|
+
end
|
71
|
+
|
72
|
+
def default_branch=(name)
|
73
|
+
ref = "refs/heads/#{name}" unless name.start_with?('refs/heads/')
|
74
|
+
rugged.head = ref
|
75
|
+
end
|
76
|
+
|
77
|
+
# Create a branch with name +name+ at the reference +ref+.
|
78
|
+
def create_branch(name, revision)
|
79
|
+
raise_invalid_name_error(name) unless Ref.name_valid?(name)
|
80
|
+
bringit.create_branch(name, revision)
|
81
|
+
end
|
82
|
+
|
83
|
+
def find_branch(name)
|
84
|
+
Bringit::Branch.find(self, name)
|
85
|
+
end
|
86
|
+
|
87
|
+
def rm_branch(name)
|
88
|
+
rugged.branches.delete(name) if find_branch(name)
|
89
|
+
end
|
90
|
+
|
91
|
+
# If +annotation+ is not +nil+, it will cause the creation of an
|
92
|
+
# annotated tag object. +annotation+ has to contain the following key
|
93
|
+
# value pairs:
|
94
|
+
# :tagger ::
|
95
|
+
# An optional Hash containing a git signature. Defaults to the signature
|
96
|
+
# from the configuration if only `:message` is given. Will cause the
|
97
|
+
# creation of an annotated tag object if present.
|
98
|
+
# :message ::
|
99
|
+
# An optional string containing the message for the new tag.
|
100
|
+
def create_tag(name, revision, annotation = nil)
|
101
|
+
raise_invalid_name_error(name) unless Ref.name_valid?(name)
|
102
|
+
rugged.tags.create(name, revision, annotation)
|
103
|
+
find_tag(name)
|
104
|
+
rescue Rugged::TagError => error
|
105
|
+
raise Bringit::Repository::InvalidRef, error.message
|
106
|
+
end
|
107
|
+
|
108
|
+
def find_tag(name)
|
109
|
+
Bringit::Tag.find(self, name)
|
110
|
+
end
|
111
|
+
|
112
|
+
def rm_tag(name)
|
113
|
+
rugged.tags.delete(name) if find_tag(name)
|
114
|
+
end
|
115
|
+
|
116
|
+
def diff_from_parent(ref = default_branch, options = {})
|
117
|
+
Commit.find(bringit, ref).diffs(options)
|
118
|
+
end
|
119
|
+
|
120
|
+
def log(options)
|
121
|
+
result = bringit.log(options)
|
122
|
+
return result if options[:only_commit_sha]
|
123
|
+
result.map do |commit|
|
124
|
+
Bringit::Commit.new(commit, bringit)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
protected
|
129
|
+
|
130
|
+
def raise_invalid_name_error(name)
|
131
|
+
url = 'https://git-scm.com/docs/git-check-ref-format'
|
132
|
+
raise ::Bringit::InvalidRefName,
|
133
|
+
%(Name "#{name}" is invalid. See #{url} for a valid format.)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bringit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ontohub Core Developers
|
8
|
+
- Dmitriy Zaporozhets
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-11-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: github-linguist
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '5.1'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '5.4'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '5.1'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.4'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: activesupport
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rugged
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.26.0
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.26.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: charlock_holmes
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.7.3
|
69
|
+
type: :runtime
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.7.3
|
76
|
+
description: Bringit wrapper around git objects
|
77
|
+
email:
|
78
|
+
- ontohub-dev-l@ovgu.de
|
79
|
+
- dmitriy.zaporozhets@gmail.com
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- lib/bringit.rb
|
85
|
+
- lib/bringit/attributes.rb
|
86
|
+
- lib/bringit/blame.rb
|
87
|
+
- lib/bringit/blob.rb
|
88
|
+
- lib/bringit/blob_snippet.rb
|
89
|
+
- lib/bringit/branch.rb
|
90
|
+
- lib/bringit/cloning.rb
|
91
|
+
- lib/bringit/commit.rb
|
92
|
+
- lib/bringit/commit_stats.rb
|
93
|
+
- lib/bringit/committing.rb
|
94
|
+
- lib/bringit/committing/merge.rb
|
95
|
+
- lib/bringit/compare.rb
|
96
|
+
- lib/bringit/diff.rb
|
97
|
+
- lib/bringit/diff_collection.rb
|
98
|
+
- lib/bringit/encoding_helper.rb
|
99
|
+
- lib/bringit/hook.rb
|
100
|
+
- lib/bringit/index.rb
|
101
|
+
- lib/bringit/path_helper.rb
|
102
|
+
- lib/bringit/popen.rb
|
103
|
+
- lib/bringit/pulling.rb
|
104
|
+
- lib/bringit/ref.rb
|
105
|
+
- lib/bringit/repository.rb
|
106
|
+
- lib/bringit/rev_list.rb
|
107
|
+
- lib/bringit/tag.rb
|
108
|
+
- lib/bringit/tree.rb
|
109
|
+
- lib/bringit/util.rb
|
110
|
+
- lib/bringit/version.rb
|
111
|
+
- lib/bringit/version_info.rb
|
112
|
+
- lib/bringit/wrapper.rb
|
113
|
+
homepage: https://github.com/ontohub/bringit
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.6.13
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Bringit library
|
137
|
+
test_files: []
|