forked from go-git/go-git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into git-restore-with-latest
* master: Update github.com/xanzy/ssh-agent to v0.3.1 Document the push refspec format Add support to push commits per hashes better tests plumbing: gitignore, Read .git/info/exclude file too. plumbing: packp, Add encoding for push-options. Fixes go-git#268. go-git: Add field `Options` to `PushOptions`, wire functionality. git: add --follow-tags option for pushes add tests examples: add find-if-any-tag-point-head Add RemoteURL to {Fetch,Pull,Push}Options plumbing/storer/object: improve grammar Go Doc (go-git#350) plumbing: format/packfile, prevent large objects from being read into memory completely (go-git#330)
- Loading branch information
Showing
28 changed files
with
1,074 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/go-git/go-git/v5" | ||
. "github.com/go-git/go-git/v5/_examples" | ||
"github.com/go-git/go-git/v5/plumbing" | ||
) | ||
|
||
// Basic example of how to find if HEAD is tagged. | ||
func main() { | ||
CheckArgs("<path>") | ||
path := os.Args[1] | ||
|
||
// We instantiate a new repository targeting the given path (the .git folder) | ||
r, err := git.PlainOpen(path) | ||
CheckIfError(err) | ||
|
||
// Get HEAD reference to use for comparison later on. | ||
ref, err := r.Head() | ||
CheckIfError(err) | ||
|
||
tags, err := r.Tags() | ||
CheckIfError(err) | ||
|
||
// List all tags, both lightweight tags and annotated tags and see if some tag points to HEAD reference. | ||
err = tags.ForEach(func(t *plumbing.Reference) error { | ||
// This technique should work for both lightweight and annotated tags. | ||
revHash, err := r.ResolveRevision(plumbing.Revision(t.Name())) | ||
CheckIfError(err) | ||
if *revHash == ref.Hash() { | ||
fmt.Printf("Found tag %s with hash %s pointing to HEAD %s\n", t.Name().Short(), revHash, ref.Hash()) | ||
} | ||
return nil | ||
}) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.