Created
December 30, 2020 20:07
-
-
Save percybolmer/ff909f1c1b0758d3713fa91f6a73b48f to your computer and use it in GitHub Desktop.
Check if a git commit is Nearest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IsCommitNearest will check if a commit tag Hash is equal to the current repository HEAD tag | |
// If the Hashes matches, it will return true | |
func (r *Repository) IsCommitNearest(commit *object.Commit) (bool, error) { | |
latestTag, previousTag, err := r.GetLatestTag() | |
if err != nil { | |
return false, fmt.Errorf("%v:%w", "Couldn't get latest tag...", err) | |
} | |
if latestTag != nil { | |
// Compare latest tag Hash with the repository HEAD hash | |
// Hash() returns a Slice which can be compared without converting to string | |
// Noticed by /OfficialTomCruise on reddit comments | |
if latestTag.Hash() == r.ref.Hash() { | |
return true, nil | |
} | |
return previousTag.Hash() == commit.Hash, nil | |
} | |
return false, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment