8000 Merge pull request #1088 from johnmatthiggins/examples · go-git/go-git@7ff5a5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ff5a5d

Browse files
authored
Merge pull request #1088 from johnmatthiggins/examples
git: Added an example for Repository.Branches
2 parents 9cc340a + c571526 commit 7ff5a5d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

example_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ func ExampleRepository_References() {
137137

138138
}
139139

140+
func ExampleRepository_Branches() {
141+
r, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
142+
URL: "https://github.com/git-fixtures/basic.git",
143+
})
144+
145+
branches, _ := r.Branches()
146+
branches.ForEach(func(branch *plumbing.Reference) error {
147+
fmt.Println(branch.Hash().String(), branch.Name())
148+
return nil
149+
})
150+
151+
// Example Output:
152+
// 6ecf0ef2c2dffb796033e5a02219af86ec6584e5 refs/heads/master
153+
}
154+
140155
func ExampleRepository_CreateRemote() {
141156
r, _ := git.Init(memory.NewStorage(), nil)
142157

0 commit comments

Comments
 (0)
0