Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create reference with an initial reflog entry message #1061

Closed
pmrowla opened this issue Jan 19, 2021 · 0 comments · Fixed by #1062
Closed

Cannot create reference with an initial reflog entry message #1061

pmrowla opened this issue Jan 19, 2021 · 0 comments · Fixed by #1062

Comments

@pmrowla
Copy link
Contributor

pmrowla commented Jan 19, 2021

In pygit2, none of the create_reference_... methods support the message parameter, so currently the only way to set a reference with a message is via the Reference.set_target() method. However, set_target will not update the reflog if the ref is already pointing to the specified target. This means that there is no way to create a new reference with a reflog message.

In a new git repo containing 2 commits (fab58a5, 48f4093):

$ pip freeze
cached-property==1.5.2
cffi==1.14.4
pycparser==2.20
pygit2==1.4.0

$ python
Python 3.8.2 (default, Nov  4 2020, 21:23:28)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygit2
>>> repo = pygit2.repository(".")
>>> ref = repo.references.create("refs/foo/bar", "fab58a555d62a1fbbbd9c8be8159057ade88715d")
>>> [entry.message for entry in ref.log()]
[]
>>> ref.set_target("fab58a555d62a1fbbbd9c8be8159057ade88715d", message="cannot set message for unchanged ref")
>>> [entry.message for entry in ref.log()]
[]
>>> ref.set_target("48f4093a41f255ed8329eb05d7119902c842edea", message="can set message for changed ref")
>>> [entry.message for entry in ref.log()]
['can set message for changed ref']

To workaround this, if I want to create a ref with an initial reflog message, I would need to create the ref so that it points to any commit in my repo besides the intended ref target, and then call set_target() with a reflog message to point it to the correct target afterwards.

libgit2 does support specifying an initial reflog message on ref creation, so ideally pygit2's create_reference(), create_reference_direct(), and create_reference_symbolic() just need to be updated to accept a message parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant