Skip to content

Conversation

@alee-r7
Copy link

@alee-r7 alee-r7 commented Dec 11, 2023

In the current state of go-git, checking out by a commit hash ID associated with a tag is not supported. This limitation arises from the fact that, under the hood, the hash is linked to a tag. The checkout process operates under the assumption that a CommitObject should always be obtained. However, if the commit is linked to a tag, the result is a TagObject, leading to an error during type checking.

To address this issue, my solution involves checking if the initial attempt to retrieve the commit using GetCommit fails. If it does, the code then examines whether the obtained object is a TagObject. If it is, the fix involves returning the CommitObject associated with the tag by utilizing the Commit method of the TagObject.

@alee-r7 alee-r7 changed the title Fix checkout by tag commit Fix issue where you cannot checkout by tag commit hash. Dec 11, 2023
aymanbagabas added a commit to aymanbagabas/go-git that referenced this pull request Dec 12, 2023
Allow checking out a worktree using a tag hash id.

Fixes: go-git#959
Supersedes: go-git#964
aymanbagabas added a commit to aymanbagabas/go-git that referenced this pull request Dec 12, 2023
Allow checking out a worktree using a tag hash id.

Fixes: go-git#959
Supersedes: go-git#964
aymanbagabas added a commit to aymanbagabas/go-git that referenced this pull request Dec 12, 2023
Allow checking out a worktree using a tag hash id.

Fixes: go-git#959
Supersedes: go-git#964
aymanbagabas added a commit to aymanbagabas/go-git that referenced this pull request Dec 12, 2023
Allow checking out a worktree using a tag hash id.

Fixes: go-git#959
Supersedes: go-git#964
@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Jan 2, 2025
@github-actions github-actions bot closed this Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Issues/PRs that are marked for closure due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant