Skip to content

git_repository_set_head: use tag name in reflog#4174

Merged
carlosmn merged 2 commits intomasterfrom
ethomson/set_head_to_tag
May 20, 2017
Merged

git_repository_set_head: use tag name in reflog#4174
carlosmn merged 2 commits intomasterfrom
ethomson/set_head_to_tag

Conversation

@ethomson
Copy link
Copy Markdown
Member

When git_repository_set_head is provided a tag reference, update the reflog with the tag name, like we do with a branch. This helps consumers match the semantics of git checkout tag.

If you think of git_repository_set_head as an analog to git symbolic-ref HEAD ... then this doesn't make a lot of sense. But I would argue that it's not a perfect analog already to git symbolic-ref, and this is natural for users who want to git checkout ... to switch branches.

See #3909

When `git_repository_set_head` is provided a tag reference, update the
reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout tag`.
@carlosmn
Copy link
Copy Markdown
Member

If we're going full-on with this, should we short-hand everything? git checkout origin/master stores origin/master as the destination.

@ethomson
Copy link
Copy Markdown
Member Author

Hrmf. I dunno... origin/master makes sense to shorthand here... but I worry that we're running out of the ability to communicate our desires. You can git checkout tag^{commit} and git stores tag^{commit} but that gets here.

We could actually be very dwimmy here, but I'm not sure how far we want to go. This is a very middle of the road approach in this PR, but we could actually try to parse what we're given.

🤷‍♂️

@carlosmn
Copy link
Copy Markdown
Member

If you want to include the exact text from the user, that's what git_repository_set_head_detached_from_annotated() does, but this is for passing in references. We could swing in the other direction and only accept annotated, but that sucks ergonomically. Using the shorthand for the ref (as long as it's a ref name we can look up) seems to be what you'd expect git to do here.

When `git_repository_set_head` is provided a remote reference, update
the reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout remote`.
@ethomson
Copy link
Copy Markdown
Member Author

ethomson commented Apr 2, 2017

Right - that makes sense. The acceptance of a ref name string (instead of a ref) was confusing me. In any case, I updated this to deal with shortnames for remote branches.

@carlosmn carlosmn merged commit e694e4e into master May 20, 2017
ethomson added a commit to libgit2/libgit2sharp that referenced this pull request Jun 13, 2017
Tag names are now recorded in the reflog without a leading `refs/tags/`,
beginning in libgit2/libgit2#4174
@ethomson ethomson deleted the ethomson/set_head_to_tag branch January 9, 2019 10:18
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 this pull request may close these issues.

2 participants