simple_git 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfe7663686ad5df1231d65e3dd3f25f0460751d851ab5f58979f467e391d99bb
4
- data.tar.gz: 2cb02766d0ce2ce498059cd6e68419703fb383bdec6e5cad706e98e64ab78171
3
+ metadata.gz: 040b27ee12f2afa0136ffc8c7ce4aee21028dbe358fc889f05df5ddc4d02adb0
4
+ data.tar.gz: 8510882d86800026c0f88cebf145a9b9d94518b950d9637180d4772087749f95
5
5
  SHA512:
6
- metadata.gz: 1f947b79828cd0d70969d95002cae43b0c8d3785ede94acb4141ac45ca393622fe6781e058936eafd848cf5cfc6b3924bf5f04ed8455abcc30b18ad050308f9d
7
- data.tar.gz: 76126eefebe9ba70cb25a8d4429884c54ca1d7ad9ac2e97edcfd72ea51047d6167f8bf08441a81c9803b051a77730b25a8476373cfdb0c490009e9f5843cd961
6
+ metadata.gz: fac2194a0218cd74eda5c8af59e3d8dfbe7955b5388cb8a9f5625301aedb7e1aa93ca8ef60f142fd770e19cdc46416c2794595c85b56607bcd3d305524003878
7
+ data.tar.gz: e8b563d54120f50ca79fc5614c2749ec3fb755eed57e1a2c9ce0b02c7b54fdc4095a9c1a1d43a58e5b919d838d960241c4d99d3c8efe4d243084ad583822b59d
@@ -0,0 +1,51 @@
1
+ module SimpleGit
2
+ class Reference
3
+ attr_accessor :ptr
4
+
5
+ def from_head(repo)
6
+ wrapper = ReferenceWrapper.new
7
+ ret = Git2.git_repository_head(wrapper, repo.ptr)
8
+ if ret != 0
9
+ error = Git2::GitError.new(Git2.giterr_last)
10
+ raise ArgumentError, error[:message].read_string
11
+ end
12
+
13
+ @ptr = wrapper[:ref]
14
+ ObjectSpace.define_finalizer(self, self.class.finalize(@ptr))
15
+
16
+ self
17
+ end
18
+
19
+ def branch_name
20
+ name_wrapper = FFI::MemoryPointer.new(:pointer)
21
+ ret = Git2.git_branch_name(name_wrapper, @ptr)
22
+ if ret != 0
23
+ error = Git2::GitError.new(Git2.giterr_last)
24
+ raise ArgumentError, error[:message].read_string
25
+ end
26
+
27
+ name_wrapper.read_pointer.read_string
28
+ end
29
+
30
+ def to_object
31
+ wrapper = SimpleGit::Object::ObjectWrapper.new
32
+ ret = Git2.git_reference_peel(wrapper, @ptr, :GIT_OBJ_ANY)
33
+ if ret != 0
34
+ error = Git2::GitError.new(Git2.giterr_last)
35
+ raise ArgumentError, error[:message].read_string
36
+ end
37
+
38
+ Object.new.from_wrapper(wrapper)
39
+ end
40
+
41
+ private
42
+
43
+ def self.finalize(ptr)
44
+ proc { Git2.git_reference_free(ptr) }
45
+ end
46
+
47
+ class ReferenceWrapper < FFI::Struct
48
+ layout :ref, Git2::GitReference.by_ref
49
+ end
50
+ end
51
+ end
@@ -26,6 +26,10 @@ module SimpleGit
26
26
  Object.new.from_wrapper(wrapper)
27
27
  end
28
28
 
29
+ def head
30
+ Reference.new.from_head(self)
31
+ end
32
+
29
33
  private
30
34
 
31
35
  def self.finalize(ptr)
@@ -1,3 +1,3 @@
1
1
  module SimpleGit
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
data/lib/simple_git.rb CHANGED
@@ -8,6 +8,7 @@ require 'simple_git/diff_options'
8
8
  require 'simple_git/diff_stat'
9
9
  require 'simple_git/object'
10
10
  require 'simple_git/oid'
11
+ require 'simple_git/reference'
11
12
  require 'simple_git/repository'
12
13
  require 'simple_git/revwalk'
13
14
  require 'simple_git/signature'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam P. White
@@ -40,6 +40,7 @@ files:
40
40
  - lib/simple_git/diff_stat.rb
41
41
  - lib/simple_git/object.rb
42
42
  - lib/simple_git/oid.rb
43
+ - lib/simple_git/reference.rb
43
44
  - lib/simple_git/repository.rb
44
45
  - lib/simple_git/revwalk.rb
45
46
  - lib/simple_git/signature.rb