Suggestion: better handling of `repo.set_head(pygit2.Commit)`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 408
- Avg merge
- 2d 57m
- Merged PRs (30d)
- 7
Description
I have tried to emulate git checkout --detach <commit> in pygit2, to create detached HEAD checkout, and I did come up with the following rough equivalent (though the following does not uses transactions as git does):
rev = repo.revparse_single(commit_name)
repo.checkout_tree(rev)
repo.set_head(rev.id)
However when I tried to use simply repo.set_head(rev), I got the following error:
TypeError Traceback (most recent call last)
<ipython-input-35-9612528ec0ac> in <module>()
----> 1 repo.set_head(rev)
/usr/lib/python2.7/dist-packages/pygit2/repository.pyc in set_head(self, target)
293
294 # if it's a string, then it's a reference name
--> 295 err = C.git_repository_set_head(self._repo, to_bytes(target))
296 check_error(err)
297
TypeError: initializer for ctype 'char *' must be a cdata pointer, not _pygit2.Commit
It would be nice if pygit2.Commit object was automatically peeled, but if it is decided to be not good idea, then what it needs is more user-friendly error message than the one above.
pygit2 0.26.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Repository.set_head in the repository.py traceback and compare the shown revparse_single, checkout_tree, and C.git_repository_set_head flow. Check existing tests or documentation for accepted target types; done means Commit input behavior is settled and covered, including a clear failure message if it remains unsupported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100