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

ResolveRevision() will panic on empty input string #259

Closed
abrander opened this issue Feb 19, 2021 · 2 comments
Closed

ResolveRevision() will panic on empty input string #259

abrander opened this issue Feb 19, 2021 · 2 comments
Labels
stale Issues/PRs that are marked for closure due to inactivity

Comments

@abrander
Copy link

To reproduce after a simple $ git init .:

package main

import (
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing"
)

func main() {
	repo, _ := git.PlainOpen(".")
	repo.ResolveRevision(plumbing.Revision(""))
}

I have investigated how to solve this, but I'm unsure if the parser should return an error, or ResolveRevision() should catch the empty items slice. Oh well. Here's the problem:

func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error) {
	p := revision.NewParserFromString(string(rev))

	items, err := p.Parse()

	if err != nil {
		return nil, err
	}

	var commit *object.Commit // <- nil zero value.

	for _, item := range items {
...
	}

	return &commit.Hash, nil // <- dereferences the nil pointer, if the for-loop is never executed.
}
Copy link

To help us keep things tidy and focus on the active tasks, we've introduced a stale bot to spot issues/PRs that haven't had any activity in a while.

This particular issue hasn't had any updates or activity in the past 90 days, so it's been labeled as 'stale'. If it remains inactive for the next 30 days, it'll be automatically closed.

We understand everyone's busy, but if this issue is still important to you, please feel free to add a comment or make an update to keep it active.

Thanks for your understanding and cooperation!

@github-actions github-actions bot added the stale Issues/PRs that are marked for closure due to inactivity label Jan 20, 2024
@abrander
Copy link
Author

abrander commented Feb 1, 2024

I have verified that this issue was resolved by #696. I'll close this issue.

v5.6.1 includes the fix.

@abrander abrander closed this as completed Feb 1, 2024
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

No branches or pull requests

1 participant