Merge pull request #171 from pks-t/submodule-foreach-fix

Submodule foreach fix
This commit is contained in:
Carlos Martín Nieto 2015-01-29 15:15:28 +01:00
commit 2b17dffc07
2 changed files with 26 additions and 2 deletions

View File

@ -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 {

24
submodule_test.go Normal file
View File

@ -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)
}
}