Closed marcellodesales closed 4 years ago
Could get this for tag or branch, but I found out there are some limitations for SHA...
func main() {
CheckArgs("<url>", "<directory>", "<revision>", "type")
url := os.Args[1]
directory := os.Args[2]
revision := os.Args[3]
cloneType := os.Args[4]
var repo *git.Repository
var err error
if cloneType == "branch" {
Info("git clone --depth=1 %s --branch %s %s", url, revision, directory)
repo, err = git.PlainClone(directory, false, &git.CloneOptions{
URL: url,
Depth: 1,
// Branch ReferenceName: plumbing.ReferenceName("refs/heads/" + revision),
ReferenceName: plumbing.NewBranchReferenceName(revision),
})
} else if cloneType == "tag" {
Info("git clone --depth=1 %s --tag %s %s", url, revision, directory)
repo, err = git.PlainClone(directory, false, &git.CloneOptions{
URL: url,
Depth: 1,
// Branch ReferenceName: plumbing.ReferenceName("refs/heads/" + revision),
ReferenceName: plumbing.NewTagReferenceName(revision),
})
}
// Verify if any error occurred
CheckIfError(err)
// ... retrieving the branch being pointed by HEAD
ref, err := repo.Head()
CheckIfError(err)
// ... retrieving the commit object
commit, err := repo.CommitObject(ref.Hash())
CheckIfError(err)
fmt.Println(commit)
}
The git shallow is something we are looking at to solve clones of a single revision requested by Tag. The way to implement it is to use the shallow clones of a particular revision (
branch
,tag
orSHA
). The first test with git shows the single revision, cloned to dir/tmp/protobuf2
, gives the expected result, while the one withgo-git
is failing witherror: reference not found
...Regular Git Shallow
/tmp/protobuf2
go-git
returnserror: reference not found
whenrefs/tag
orref/heads
is not providedref/tags/
forTag
orref/heads
forBranch
the library fails witherror: reference not found
How to get ReferenceName for either a Branch, Tag, or SHA?