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

Git prompt using libgit2 (again) #55

Merged
merged 36 commits into from
Oct 30, 2024
Merged

Git prompt using libgit2 (again) #55

merged 36 commits into from
Oct 30, 2024

Conversation

tfpf
Copy link
Owner

@tfpf tfpf commented Oct 26, 2024

No description provided.

The reference (which can be the branch name or commit hash) is obtained by reading `.git/HEAD` because the suggested way (https://stackoverflow.com/questions/12132862) does not work (`git_repository_head` fails) if there are no commits on the branch yet.
custom-prompt/custom-prompt.cc Outdated Show resolved Hide resolved
@tfpf
Copy link
Owner Author

tfpf commented Oct 27, 2024

Getting the Git tag using the following is not working.

  • git_describe_workdir with a git_reference.
  • git_describe_commit with a git_object obtained using git_reference_peel on the git_reference.
  • git_reference_is_tag with a git_reference.
  • git_reference_peel with a git_reference and GIT_OBJECT_TAG.
  • git_tag_lookup with a git_reference and its oid obtained using git_reference_target following git_reference_resolve.

All of these functions return a failure code even when an existing tag is checked out using git checkout v0.0.0.

Hence, I shall iterate over all tags and look for one matching the current commit.

custom-prompt/custom-prompt.cc Outdated Show resolved Hide resolved
custom-prompt/custom-prompt.cc Outdated Show resolved Hide resolved
custom-prompt/custom-prompt.cc Outdated Show resolved Hide resolved
custom-prompt/custom-prompt.cc Outdated Show resolved Hide resolved
@tfpf
Copy link
Owner Author

tfpf commented Oct 28, 2024

Test Matrix: Scenarios to Verify the Behaviour

  • Repository Type
    • bare, regular
  • HEAD Type
    • commit (detached), branch (attached), tag (detached)
  • Repository State
    • bisecting, cherry-picking, merging, rebasing, reverting
  • Repository Status
    • dirty, staged, untracked

@tfpf
Copy link
Owner Author

tfpf commented Oct 30, 2024

Getting the Git tag using the following is not working.

  • git_describe_workdir with a git_reference.

  • git_describe_commit with a git_object obtained using git_reference_peel on the git_reference.

  • git_reference_is_tag with a git_reference.

  • git_reference_peel with a git_reference and GIT_OBJECT_TAG.

  • git_tag_lookup with a git_reference and its oid obtained using git_reference_target following git_reference_resolve.

All of these functions return a failure code even when an existing tag is checked out using git checkout v0.0.0.

Hence, I shall iterate over all tags and look for one matching the current commit.

The reason these did not work is probably the tags I was testing were unannotated tags, while these functions are provided for annotated tags.

@tfpf tfpf merged commit 2e922e4 into main Oct 30, 2024
@tfpf tfpf deleted the libgit2-git-ps1-impl branch October 31, 2024 11:48
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.

1 participant