src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 541 forks source link

Best way to check if repo has any remote commits? #1253

Open rnag opened 4 years ago

rnag commented 4 years ago

Currently i have been using :

// Check the remote commit history for a Git repository
func repoHasRemoteCommits(r *git.Repository) bool {
    var hasRemoteCommits bool
    revision := "origin/master"

    _, err := r.ResolveRevision(plumbing.Revision(revision))
    hasRemoteCommits = err == nil

    return hasRemoteCommits
}

Does this approach cover all edge cases? wondering if there is a better way as well.