rdavila-rugged 0.24.0b13

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.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +619 -0
  4. data/ext/rugged/extconf.rb +105 -0
  5. data/ext/rugged/rugged.c +527 -0
  6. data/ext/rugged/rugged.h +185 -0
  7. data/ext/rugged/rugged_backend.c +34 -0
  8. data/ext/rugged/rugged_blame.c +292 -0
  9. data/ext/rugged/rugged_blob.c +638 -0
  10. data/ext/rugged/rugged_branch.c +195 -0
  11. data/ext/rugged/rugged_branch_collection.c +408 -0
  12. data/ext/rugged/rugged_commit.c +691 -0
  13. data/ext/rugged/rugged_config.c +404 -0
  14. data/ext/rugged/rugged_cred.c +148 -0
  15. data/ext/rugged/rugged_diff.c +686 -0
  16. data/ext/rugged/rugged_diff_delta.c +105 -0
  17. data/ext/rugged/rugged_diff_hunk.c +103 -0
  18. data/ext/rugged/rugged_diff_line.c +83 -0
  19. data/ext/rugged/rugged_index.c +1255 -0
  20. data/ext/rugged/rugged_note.c +376 -0
  21. data/ext/rugged/rugged_object.c +383 -0
  22. data/ext/rugged/rugged_patch.c +245 -0
  23. data/ext/rugged/rugged_reference.c +396 -0
  24. data/ext/rugged/rugged_reference_collection.c +446 -0
  25. data/ext/rugged/rugged_remote.c +691 -0
  26. data/ext/rugged/rugged_remote_collection.c +457 -0
  27. data/ext/rugged/rugged_repo.c +2669 -0
  28. data/ext/rugged/rugged_revwalk.c +495 -0
  29. data/ext/rugged/rugged_settings.c +155 -0
  30. data/ext/rugged/rugged_signature.c +106 -0
  31. data/ext/rugged/rugged_submodule.c +852 -0
  32. data/ext/rugged/rugged_submodule_collection.c +384 -0
  33. data/ext/rugged/rugged_tag.c +251 -0
  34. data/ext/rugged/rugged_tag_collection.c +347 -0
  35. data/ext/rugged/rugged_tree.c +919 -0
  36. data/lib/rugged.rb +23 -0
  37. data/lib/rugged/attributes.rb +41 -0
  38. data/lib/rugged/blob.rb +28 -0
  39. data/lib/rugged/branch.rb +19 -0
  40. data/lib/rugged/commit.rb +54 -0
  41. data/lib/rugged/console.rb +9 -0
  42. data/lib/rugged/credentials.rb +43 -0
  43. data/lib/rugged/diff.rb +20 -0
  44. data/lib/rugged/diff/delta.rb +53 -0
  45. data/lib/rugged/diff/hunk.rb +18 -0
  46. data/lib/rugged/diff/line.rb +47 -0
  47. data/lib/rugged/index.rb +13 -0
  48. data/lib/rugged/object.rb +7 -0
  49. data/lib/rugged/patch.rb +36 -0
  50. data/lib/rugged/reference.rb +7 -0
  51. data/lib/rugged/remote.rb +4 -0
  52. data/lib/rugged/repository.rb +227 -0
  53. data/lib/rugged/submodule_collection.rb +48 -0
  54. data/lib/rugged/tag.rb +50 -0
  55. data/lib/rugged/tree.rb +38 -0
  56. data/lib/rugged/version.rb +3 -0
  57. data/lib/rugged/walker.rb +5 -0
  58. metadata +146 -0
@@ -0,0 +1,4 @@
1
+ module Rugged
2
+ class Remote
3
+ end
4
+ end
@@ -0,0 +1,227 @@
1
+ module Rugged
2
+ # Repository is an interface into a Git repository on-disk. It's the primary
3
+ # interface between your app and the main Git objects Rugged makes available
4
+ # to you.
5
+ class Repository
6
+ # Pretty formatting of a Repository.
7
+ #
8
+ # Returns a very pretty String.
9
+ def inspect
10
+ "#<Rugged::Repository:#{object_id} {path: #{path.inspect}}>"
11
+ end
12
+
13
+ # Get the most recent commit from this repo.
14
+ #
15
+ # Returns a Rugged::Commit object.
16
+ def last_commit
17
+ self.head.target
18
+ end
19
+
20
+ # Checkout the specified branch, reference or commit.
21
+ #
22
+ # target - A revparse spec for the branch, reference or commit to check out.
23
+ # options - Options passed to #checkout_tree.
24
+ def checkout(target, options = {})
25
+ options[:strategy] ||= :safe
26
+ options.delete(:paths)
27
+
28
+ return checkout_head(options) if target == "HEAD"
29
+
30
+ if target.kind_of?(Rugged::Branch)
31
+ branch = target
32
+ else
33
+ branch = branches[target]
34
+ end
35
+
36
+ if branch
37
+ self.checkout_tree(branch.target, options)
38
+
39
+ if branch.remote?
40
+ references.create("HEAD", branch.target_id, force: true)
41
+ else
42
+ references.create("HEAD", branch.canonical_name, force: true)
43
+ end
44
+ else
45
+ commit = Commit.lookup(self, self.rev_parse_oid(target))
46
+ references.create("HEAD", commit.oid, force: true)
47
+ self.checkout_tree(commit, options)
48
+ end
49
+ end
50
+
51
+ def diff(left, right, opts = {})
52
+ left = rev_parse(left) if left.kind_of?(String)
53
+ right = rev_parse(right) if right.kind_of?(String)
54
+
55
+ if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit) && !left.nil?
56
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
57
+ end
58
+
59
+ if !right.is_a?(Rugged::Tree) && !right.is_a?(Rugged::Commit) && !right.nil?
60
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
61
+ end
62
+
63
+ if left
64
+ left.diff(right, opts)
65
+ elsif right
66
+ right.diff(left, opts.merge(:reverse => !opts[:reverse]))
67
+ end
68
+ end
69
+
70
+ def diff_workdir(left, opts = {})
71
+ left = rev_parse(left) if left.kind_of?(String)
72
+
73
+ if !left.is_a?(Rugged::Tree) && !left.is_a?(Rugged::Commit)
74
+ raise TypeError, "Expected a Rugged::Tree or Rugged::Commit instance"
75
+ end
76
+
77
+ left.diff_workdir(opts)
78
+ end
79
+
80
+ # Walks over a set of commits using Rugged::Walker.
81
+ #
82
+ # from - The String SHA1 to push onto Walker to begin our walk.
83
+ # sorting - The sorting order of the commits, as defined in the README.
84
+ # block - A block that we pass into walker#each.
85
+ #
86
+ # Returns nothing if called with a block, otherwise returns an instance of
87
+ # Enumerable::Enumerator containing Rugged::Commit objects.
88
+ def walk(from, sorting=Rugged::SORT_DATE, &block)
89
+ walker = Rugged::Walker.new(self)
90
+ walker.sorting(sorting)
91
+ walker.push(from)
92
+ walker.each(&block)
93
+ end
94
+
95
+ # Look up a SHA1.
96
+ #
97
+ # Returns one of the four classes that inherit from Rugged::Object.
98
+ def lookup(oid)
99
+ Rugged::Object.lookup(self, oid)
100
+ end
101
+
102
+ # Look up an object by a revision string.
103
+ #
104
+ # Returns one of the four classes that inherit from Rugged::Object.
105
+ def rev_parse(spec)
106
+ Rugged::Object.rev_parse(self, spec)
107
+ end
108
+
109
+ # Look up an object by a revision string.
110
+ #
111
+ # Returns the oid of the matched object as a String
112
+ def rev_parse_oid(spec)
113
+ Rugged::Object.rev_parse_oid(self, spec)
114
+ end
115
+
116
+ # Look up a single reference by name.
117
+ #
118
+ # Example:
119
+ #
120
+ # repo.ref 'refs/heads/master'
121
+ # # => #<Rugged::Reference:2199125780 {name: "refs/heads/master",
122
+ # target: "25b5d3b40c4eadda8098172b26c68cf151109799"}>
123
+ #
124
+ # Returns a Rugged::Reference.
125
+ def ref(ref_name)
126
+ references[ref_name]
127
+ end
128
+
129
+ def refs(glob = nil)
130
+ references.each(glob)
131
+ end
132
+
133
+ def references
134
+ @references ||= ReferenceCollection.new(self)
135
+ end
136
+
137
+ def ref_names(glob = nil)
138
+ references.each_name(glob)
139
+ end
140
+
141
+ # All the tags in the repository.
142
+ #
143
+ # Returns an TagCollection containing all the tags.
144
+ def tags
145
+ @tags ||= TagCollection.new(self)
146
+ end
147
+
148
+ # All the remotes in the repository.
149
+ #
150
+ # Returns a Rugged::RemoteCollection containing all the Rugged::Remote objects
151
+ # in the repository.
152
+ def remotes
153
+ @remotes ||= RemoteCollection.new(self)
154
+ end
155
+
156
+ # All the branches in the repository
157
+ #
158
+ # Returns an BranchCollection containing Rugged::Branch objects
159
+ def branches
160
+ @branches ||= BranchCollection.new(self)
161
+ end
162
+
163
+ # All the submodules in the repository
164
+ #
165
+ # Returns an SubmoduleCollection containing Rugged::Submodule objects
166
+ def submodules
167
+ @submodules ||= SubmoduleCollection.new(self)
168
+ end
169
+
170
+ # Create a new branch in the repository
171
+ #
172
+ # name - The name of the branch (without a full reference path)
173
+ # sha_or_ref - The target of the branch; either a String representing
174
+ # an OID or a reference name, or a Rugged::Object instance.
175
+ #
176
+ # Returns a Rugged::Branch object
177
+ def create_branch(name, sha_or_ref = "HEAD")
178
+ case sha_or_ref
179
+ when Rugged::Object
180
+ target = sha_or_ref.oid
181
+ else
182
+ target = rev_parse_oid(sha_or_ref)
183
+ end
184
+
185
+ branches.create(name, target)
186
+ end
187
+
188
+ # Get the blob at a path for a specific revision.
189
+ #
190
+ # revision - The String SHA1.
191
+ # path - The String file path.
192
+ #
193
+ # Returns a String.
194
+ def blob_at(revision, path)
195
+ tree = Rugged::Commit.lookup(self, revision).tree
196
+ begin
197
+ blob_data = tree.path(path)
198
+ rescue Rugged::TreeError
199
+ return nil
200
+ end
201
+ blob = Rugged::Blob.lookup(self, blob_data[:oid])
202
+ (blob.type == :blob) ? blob : nil
203
+ end
204
+
205
+ def fetch(remote_or_url, *args)
206
+ unless remote_or_url.kind_of? Remote
207
+ remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url)
208
+ end
209
+
210
+ remote_or_url.fetch(*args)
211
+ end
212
+
213
+ # Push a list of refspecs to the given remote.
214
+ #
215
+ # refspecs - A list of refspecs that should be pushed to the remote.
216
+ #
217
+ # Returns a hash containing the pushed refspecs as keys and
218
+ # any error messages or +nil+ as values.
219
+ def push(remote_or_url, *args)
220
+ unless remote_or_url.kind_of? Remote
221
+ remote_or_url = remotes[remote_or_url] || remotes.create_anonymous(remote_or_url)
222
+ end
223
+
224
+ remote_or_url.push(*args)
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,48 @@
1
+ module Rugged
2
+ class SubmoduleCollection
3
+
4
+ # call-seq:
5
+ # submodules.setup_add(url, path[, options]) -> submodule
6
+ #
7
+ # Add a new +submodule+.
8
+ #
9
+ # This does <tt>"git submodule add"</tt> incuding fetch and checkout of the
10
+ # submodule contents.
11
+ #
12
+ # - +url+: URL for the submodule's remote
13
+ # - +path+: path at which the submodule should be created
14
+ #
15
+ # The +options+ hash accepts all options supported by Rugged::Remote#fetch
16
+ # and the following:
17
+ # :gitlink ::
18
+ # (defaults to +true+) should workdir contain a
19
+ # gitlink to the repository in +.git/modules+ vs. repository
20
+ # directly in workdir.
21
+ #
22
+ # Returns the newly created +submodule+
23
+ def add(url, path, options = {})
24
+ submodule = setup_add(url, path, options)
25
+ clone_submodule(submodule.repository, options)
26
+ submodule.finalize_add
27
+ end
28
+
29
+ private
30
+ # currently libgit2's `git_submodule_add_setup` initializes a repo
31
+ # with a workdir for the submodule. libgit2's `git_clone` however
32
+ # requires the target for the clone to be an empty dir.
33
+ #
34
+ # This provides a ghetto clone implementation that:
35
+ # 1. fetches the remote
36
+ # 2. sets up a master branch to be tracking origin/master
37
+ # 3. checkouts the submodule
38
+ def clone_submodule(repo, fetch_options)
39
+ # the remote was just added by setup_add, no need to check presence
40
+ repo.remotes['origin'].fetch(fetch_options)
41
+
42
+ repo.branches.create('master','origin/master')
43
+ repo.branches['master'].upstream = repo.branches['origin/master']
44
+
45
+ repo.checkout_head(strategy: :force)
46
+ end
47
+ end
48
+ end
data/lib/rugged/tag.rb ADDED
@@ -0,0 +1,50 @@
1
+ module Rugged
2
+ class Tag < Rugged::Reference
3
+ GPG_SIGNATURE_PREFIX = "-----BEGIN PGP SIGNATURE-----".freeze
4
+
5
+ def self.extract_signature(repo, oid, prefix=GPG_SIGNATURE_PREFIX)
6
+ object = repo.read(oid)
7
+
8
+ unless object.type == :tag
9
+ raise GitRPC::InvalidObject, "Invalid object type #{object.type}, expected tag"
10
+ end
11
+
12
+ if index = object.data.index(prefix)
13
+ [
14
+ object.data.byteslice(index..-1),
15
+ object.data.byteslice(0...index)
16
+ ]
17
+ else
18
+ [nil, object.data]
19
+ end
20
+ end
21
+
22
+ def name
23
+ canonical_name.sub(%r{^refs/tags/}, "")
24
+ end
25
+
26
+ class Annotation
27
+ def self.prettify_message(msg, strip_comments = true)
28
+ Rugged::prettify_message(msg, strip_comments)
29
+ end
30
+
31
+ def inspect
32
+ "#<Rugged::Tag::Annotation:#{object_id} {name: #{name.inspect}, message: #{message.inspect}, target: #{target.inspect}>"
33
+ end
34
+
35
+ def to_hash
36
+ {
37
+ :message => message,
38
+ :name => name,
39
+ :target => target,
40
+ :tagger => tagger,
41
+ }
42
+ end
43
+
44
+ def modify(new_args, force=True)
45
+ args = self.to_hash.merge(new_args)
46
+ Tag.create(args, force)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,38 @@
1
+ module Rugged
2
+ class Tree
3
+ include Enumerable
4
+
5
+ attr_reader :owner
6
+ alias repo owner
7
+
8
+ def diff(other = nil, options = nil)
9
+ Tree.diff(repo, self, other, options)
10
+ end
11
+
12
+ def inspect
13
+ data = "#<Rugged::Tree:#{object_id} {oid: #{oid}}>\n"
14
+ self.each { |e| data << " <\"#{e[:name]}\" #{e[:oid]}>\n" }
15
+ data
16
+ end
17
+
18
+ # Walks the tree but only yields blobs
19
+ def walk_blobs(mode=:postorder)
20
+ self.walk(mode) { |root, e| yield root, e if e[:type] == :blob }
21
+ end
22
+
23
+ # Walks the tree but only yields subtrees
24
+ def walk_trees(mode=:postorder)
25
+ self.walk(mode) { |root, e| yield root, e if e[:type] == :tree }
26
+ end
27
+
28
+ # Iterate over the blobs in this tree
29
+ def each_blob
30
+ self.each { |e| yield e if e[:type] == :blob }
31
+ end
32
+
33
+ # Iterat over the subtrees in this tree
34
+ def each_tree
35
+ self.each { |e| yield e if e[:type] == :tree }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Rugged
2
+ Version = VERSION = '0.24.0b13'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Rugged
2
+ class Walker
3
+ include Enumerable
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdavila-rugged
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.24.0b13
5
+ platform: ruby
6
+ authors:
7
+ - Scott Chacon
8
+ - Vicent Marti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 0.9.0
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ description: |
57
+ Rugged is a Ruby bindings to the libgit2 linkable C Git library. This is
58
+ for testing and using the libgit2 library in a language that is awesome.
59
+ email: schacon@gmail.com
60
+ executables: []
61
+ extensions:
62
+ - ext/rugged/extconf.rb
63
+ extra_rdoc_files: []
64
+ files:
65
+ - LICENSE
66
+ - README.md
67
+ - ext/rugged/extconf.rb
68
+ - ext/rugged/rugged.c
69
+ - ext/rugged/rugged.h
70
+ - ext/rugged/rugged_backend.c
71
+ - ext/rugged/rugged_blame.c
72
+ - ext/rugged/rugged_blob.c
73
+ - ext/rugged/rugged_branch.c
74
+ - ext/rugged/rugged_branch_collection.c
75
+ - ext/rugged/rugged_commit.c
76
+ - ext/rugged/rugged_config.c
77
+ - ext/rugged/rugged_cred.c
78
+ - ext/rugged/rugged_diff.c
79
+ - ext/rugged/rugged_diff_delta.c
80
+ - ext/rugged/rugged_diff_hunk.c
81
+ - ext/rugged/rugged_diff_line.c
82
+ - ext/rugged/rugged_index.c
83
+ - ext/rugged/rugged_note.c
84
+ - ext/rugged/rugged_object.c
85
+ - ext/rugged/rugged_patch.c
86
+ - ext/rugged/rugged_reference.c
87
+ - ext/rugged/rugged_reference_collection.c
88
+ - ext/rugged/rugged_remote.c
89
+ - ext/rugged/rugged_remote_collection.c
90
+ - ext/rugged/rugged_repo.c
91
+ - ext/rugged/rugged_revwalk.c
92
+ - ext/rugged/rugged_settings.c
93
+ - ext/rugged/rugged_signature.c
94
+ - ext/rugged/rugged_submodule.c
95
+ - ext/rugged/rugged_submodule_collection.c
96
+ - ext/rugged/rugged_tag.c
97
+ - ext/rugged/rugged_tag_collection.c
98
+ - ext/rugged/rugged_tree.c
99
+ - lib/rugged.rb
100
+ - lib/rugged/attributes.rb
101
+ - lib/rugged/blob.rb
102
+ - lib/rugged/branch.rb
103
+ - lib/rugged/commit.rb
104
+ - lib/rugged/console.rb
105
+ - lib/rugged/credentials.rb
106
+ - lib/rugged/diff.rb
107
+ - lib/rugged/diff/delta.rb
108
+ - lib/rugged/diff/hunk.rb
109
+ - lib/rugged/diff/line.rb
110
+ - lib/rugged/index.rb
111
+ - lib/rugged/object.rb
112
+ - lib/rugged/patch.rb
113
+ - lib/rugged/reference.rb
114
+ - lib/rugged/remote.rb
115
+ - lib/rugged/repository.rb
116
+ - lib/rugged/submodule_collection.rb
117
+ - lib/rugged/tag.rb
118
+ - lib/rugged/tree.rb
119
+ - lib/rugged/version.rb
120
+ - lib/rugged/walker.rb
121
+ homepage: https://github.com/libgit2/rugged
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 1.9.3
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.1
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Rugged is a Ruby binding to the libgit2 linkable library
145
+ test_files: []
146
+ has_rdoc: