Merge pull request #171 from pks-t/submodule-foreach-fix
Submodule foreach fix
This commit is contained in:
commit
2b17dffc07
|
@ -97,10 +97,10 @@ func (repo *Repository) LookupSubmodule(name string) (*Submodule, error) {
|
|||
type SubmoduleCbk func(sub *Submodule, name string) int
|
||||
|
||||
//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)}
|
||||
fct := *(*SubmoduleCbk)(cfct)
|
||||
return fct(sub, name)
|
||||
return (C.int)(fct(sub, C.GoString(name)))
|
||||
}
|
||||
|
||||
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