Permalink
Browse files

added submodule for libgit2

added ctest file
  • Loading branch information...
1 parent 7151126 commit 726c6888c80ddb253c9130a7466774f3683f80a8 str1ngs committed Mar 5, 2011
Showing with 61 additions and 42 deletions.
  1. +3 −0 .gitmodules
  2. +12 −3 Makefile
  3. +29 −0 ctest.c
  4. +6 −4 git.go
  5. +10 −35 git_test.go
  6. +1 −0 libgit2
View
@@ -0,0 +1,3 @@
+[submodule "libgit2"]
+ path = libgit2
+ url = git://github.com/libgit2/libgit2.git
View
@@ -3,19 +3,28 @@ include $(GOROOT)/src/Make.inc
TARG=go-git
CGOFILES=git.go
-
GOFILES=defs.go
CGO_CFLAGS:=`pkg-config --cflags libgit2`
-
CGO_LDFLAGS=`pkg-config --libs libgit2`
-CLEANFILES+=defs.go
+CFLAGS:=`pkg-config --cflags libgit2`
+LDFLAGS=`pkg-config --libs libgit2`
+
+CLEANFILES+=defs.go ./tmp ctest
include $(GOROOT)/src/Make.pkg
+ctest: clean ctest.c
+ gcc -g -O0 -Wall $(CFLAGS) $(LDFLAGS) $@.c -o $@
+ ./$@
+
defs.go: defs.c
godefs -g git defs.c > defs.go
format:
gofmt -l -w *.go
+
+all: ctest test
+
+defs.go: defs.c
View
29 ctest.c
@@ -0,0 +1,29 @@
+#include <git2.h>
+#include <stdio.h>
+#include <string.h>
+
+#define BARE 1
+#define NOTBARE 0
+
+int main() {
+ git_repository *repo;
+ int error;
+ const char *path = "/home/strings/git/go-git/tmp";
+
+ error = git_repository_init(&repo,path,NOTBARE);
+
+ if (error != 0) {
+ printf("ERROR: init %s code %i\n",path,BARE);
+ return(1);
+ };
+
+ error = git_repository_open(&repo, path);
+ if (error != 0) {
+ printf("ERROR: opening %s code %i\n",path,error);
+ return(1);
+ };
+
+ /* do stuff with the repository */
+ git_repository_free(repo);
+ return(0);
+}
View
10 git.go
@@ -20,8 +20,9 @@ type Repo struct {
}
func (v *Repo) Open(path string) (err os.Error) {
- if C.git_repository_open(&v.git_repo, C.CString(path)) != 0 {
- err = os.NewError("failed to open " + path)
+ ecode := C.git_repository_open(&v.git_repo, C.CString(path))
+ if ecode != 0 {
+ err = os.NewError(fmt.Sprintf("failed to open %v CODE %v", path, ecode))
}
return
}
@@ -35,8 +36,9 @@ func (v *Repo) Free() {
}
func (v *Repo) Init(path string, isbare uint8) (err os.Error) {
- if i := C.git_repository_init(&v.git_repo, C.CString(path), C.uint(isbare)); i != 0 {
- e := fmt.Sprintf("failed to init %v CODE %v", path, i)
+ ecode := C.git_repository_init(&v.git_repo, C.CString(path), C.uint(isbare))
+ if ecode != 0 {
+ e := fmt.Sprintf("failed to init %v CODE %v", path, ecode)
println(e)
return os.NewError(e)
}
View
@@ -12,84 +12,59 @@ var (
repo *Repo
revwalk *RevWalk
path string
- fatal bool = false
- calls int = 0
+ calls int = 0
)
func init() {
- path, _ = os.Getwd()
- path += "/tmp"
+ //path, _ = os.Getwd()
+ path = "/mnt/data/tmp"
repo = &Repo{}
}
func TestInit(t *testing.T) {
- if fatal {
- return
- }
- if err := repo.Init(path, NOTBARE); err != nil {
- fatal = true
- t.Error(err)
+ if err := repo.Init(path, BARE); err != nil {
+ t.Fatal("Error:", err)
}
}
func TestOpen(t *testing.T) {
- if fatal {
- return
- }
- err := repo.Open(path + "/.git")
+ err := repo.Open(path)
if err != nil {
- fatal = true
- println("We can not test with out a working Repo")
- println(err.String())
+ t.Fatal("Error:", err)
}
}
func TestNewOid(t *testing.T) {
- if fatal {
- return
- }
if _, err := NewOid(oid); err != nil {
- fatal = true
t.Error(err)
}
}
/*
func TestLookup(t *testing.T) {
- if fatal {
- return
- }
c := &Commit{}
o, _ := NewOid(oid)
repo.Lookup(c, o, GIT_OBJ_ANY)
if c.Author() != author {
- fatal = true
- t.Error(os.NewError("Lookup failed"))
+ t.Fatal("ERROR:",os.NewError("Lookup failed"))
}
}
*/
+
func TestNewRevWalk(t *testing.T) {
var err os.Error
- if fatal {
- return
- }
revwalk, err = NewRevWalk(repo)
if err != nil {
- fatal = true
- t.Error(err)
+ t.Fatal("ERROR:", err)
}
}
//Important: this must be called after all of the Test functions
func TestFinal(t *testing.T) {
- if fatal {
- return
- }
revwalk.Free()
repo.Free()
}
func TestTest(t *testing.T) {
-
test()
}
Submodule libgit2 added at 45314a

0 comments on commit 726c688

Please sign in to comment.