Skip to content

Commit 7e377c8

Browse files
committed
Merge remote-tracking branch 'assafnativ/nativ/submodule_oid'
2 parents 1eaba18 + a3f5376 commit 7e377c8

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

docs/submodule.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ The Submodule type
1919
.. autoattribute:: pygit2.Submodule.path
2020
.. autoattribute:: pygit2.Submodule.url
2121
.. autoattribute:: pygit2.Submodule.branch
22+
.. autoattribute:: pygit2.Submodule.head_id

pygit2/decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ const char *git_submodule_name(git_submodule *subm);
678678
const char *git_submodule_path(git_submodule *subm);
679679
const char *git_submodule_url(git_submodule *subm);
680680
const char *git_submodule_branch(git_submodule *subm);
681+
const git_oid *git_submodule_head_id(git_submodule *subm);
681682

682683
/*
683684
* git_index

pygit2/submodule.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# Import from the future
3030
from __future__ import absolute_import, unicode_literals
3131

32+
from _pygit2 import Oid
3233
from .errors import check_error
3334
from .ffi import ffi, C
3435

@@ -77,3 +78,10 @@ def branch(self):
7778
"""Branch that is to be tracked by the submodule."""
7879
branch = C.git_submodule_branch(self._subm)
7980
return ffi.string(branch).decode('utf-8')
81+
82+
@property
83+
def head_id(self):
84+
"""Head of the submodule."""
85+
head = C.git_submodule_head_id(self._subm)
86+
return Oid(raw=bytes(ffi.buffer(head)[:]))
87+

test/test_submodule.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,10 @@ def test_oneshot_update(self):
9595
self.repo.update_submodules(init=True)
9696
self.assertTrue(os.path.exists(subrepo_file_path))
9797

98+
@unittest.skipIf(utils.no_network(), "Requires network")
99+
def test_head_id(self):
100+
s = self.repo.lookup_submodule(SUBM_PATH)
101+
self.assertEqual(str(s.head_id), SUBM_HEAD_SHA)
102+
98103
if __name__ == '__main__':
99104
unittest.main()

0 commit comments

Comments
 (0)