I would like to get the behavior of git show -s --format=%H in Dulwich; i.e. getting the full commit hash pointed to by HEAD. However, as it turns out the porcelain.show() function behaves pretty much like git show but doesn't seem to know any additional options like the Git CLI.
I am not surprised, given porcelain.describe() behaves similarly. But what alternative means do I have with Dulwich to see the full commit hash of HEAD?
For the abbreviated - albeit hardcoded to 7 characters (!) - hash I can use the aforementioned porcelain.describe().
By consulting the code for
porcelain.describe()we can pull the pieces together.open_repo_closingoffers a nice context manager for thedulwich.repo.BaseRepoclass, withcontextlib.closingbehaviorBaseRepo.head()contains the information asbytesA minimal implementation could look like this:
Simpler than I initially expected.