File tree Expand file tree Collapse file tree 4 files changed +15
-0
lines changed
Expand file tree Collapse file tree 4 files changed +15
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -678,6 +678,7 @@ const char *git_submodule_name(git_submodule *subm);
678678const char * git_submodule_path (git_submodule * subm );
679679const char * git_submodule_url (git_submodule * subm );
680680const char * git_submodule_branch (git_submodule * subm );
681+ const git_oid * git_submodule_head_id (git_submodule * subm );
681682
682683/*
683684 * git_index
Original file line number Diff line number Diff line change 2929# Import from the future
3030from __future__ import absolute_import , unicode_literals
3131
32+ from _pygit2 import Oid
3233from .errors import check_error
3334from .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+
Original file line number Diff line number Diff 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+
98103if __name__ == '__main__' :
99104 unittest .main ()
You can’t perform that action at this time.
0 commit comments