Open Broham opened 5 years ago
You can get the reference to a branch without iteration:
ref, err := r.Reference(plumbing.ReferenceName("refs/heads/master"), false)
or
ref, err := r.Reference(plumbing.NewBranchReferenceName("master"), false)
So in full:
ref, err := r.Reference(plumbing.ReferenceName("refs/heads/master"), false)
if err != nil {
panic(err)
}
commit, err := r.CommitObject(ref.Hash())
if err != nil {
panic(err)
}
files, err := commit.Files()
if err != nil {
panic(err)
}
files.ForEach(func(f *object.File) error {
fmt.Println("File Name:", f.Name)
return nil
})
So far I've come up with the code below (which does work):
But the portion where I'm looping through all the branches and checking the name seems like it's not ideal. I had been hoping that I could get the files for a branch by using
config.Branch
like below:But I can't figure out any way to get a hash from
config.Branch
. Is it possible to do what I'm trying in the second example or is the first example I provided the best way to get files for a branch?