Submodule foreach fix #171
|
@ -97,10 +97,10 @@ func (repo *Repository) LookupSubmodule(name string) (*Submodule, error) {
|
||||||
type SubmoduleCbk func(sub *Submodule, name string) int
|
type SubmoduleCbk func(sub *Submodule, name string) int
|
||||||
|
|
||||||
//export SubmoduleVisitor
|
//export SubmoduleVisitor
|
||||||
func SubmoduleVisitor(csub unsafe.Pointer, name string, cfct unsafe.Pointer) int {
|
func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, cfct unsafe.Pointer) C.int {
|
||||||
sub := &Submodule{(*C.git_submodule)(csub)}
|
sub := &Submodule{(*C.git_submodule)(csub)}
|
||||||
fct := *(*SubmoduleCbk)(cfct)
|
fct := *(*SubmoduleCbk)(cfct)
|
||||||
return fct(sub, name)
|
return (C.int)(fct(sub, C.GoString(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) ForeachSubmodule(cbk SubmoduleCbk) error {
|
func (repo *Repository) ForeachSubmodule(cbk SubmoduleCbk) error {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSubmoduleForeach(t *testing.T) {
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
seedTestRepo(t, repo)
|
||||||
|
|
||||||
|
_, err := repo.AddSubmodule("http://example.org/submodule", "submodule", true)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
err = repo.ForeachSubmodule(func(sub *Submodule, name string) int {
|
||||||
|
i++
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if i != 1 {
|
||||||
|
t.Fatalf("expected one submodule found but got %i", i)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue