From b1d97c1ebd3c66e7311c11c02575d66f41bab953 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 6 Oct 2015 15:12:49 -0500 Subject: [PATCH 1/3] Fix typo in README: manaager -> manager --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a5e6100..315032f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Go bindings for [libgit2](http://libgit2.github.com/). The `master` branch follo Installing ---------- -This project wraps the functionality provided by libgit2. If you're using a stable version, install it to your system via your system's package manaager and then install git2go as usual. +This project wraps the functionality provided by libgit2. If you're using a stable version, install it to your system via your system's package manager and then install git2go as usual. Otherwise (`next` which tracks an unstable version), we need to build libgit2 as well. In order to build it, you need `cmake`, `pkg-config` and a C compiler. You will also need the development packages for OpenSSL and LibSSH2 installed if you want libgit2 to support HTTPS and SSH respectively. -- 2.45.2 From 80cf533fe4e48ddfab3015d9570f2833951c1dea Mon Sep 17 00:00:00 2001 From: David Pierce Date: Sat, 26 Sep 2015 15:37:48 -0700 Subject: [PATCH 2/3] Config#LookupString uses git_buf to load value --- config.go | 8 ++++--- config_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 config_test.go diff --git a/config.go b/config.go index 9d25e35..c4c4028 100644 --- a/config.go +++ b/config.go @@ -115,18 +115,20 @@ func (c *Config) LookupInt64(name string) (int64, error) { } func (c *Config) LookupString(name string) (string, error) { - var ptr *C.char cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) + valBuf := C.git_buf{} + runtime.LockOSThread() defer runtime.UnlockOSThread() - if ret := C.git_config_get_string(&ptr, c.ptr, cname); ret < 0 { + if ret := C.git_config_get_string_buf(&valBuf, c.ptr, cname); ret < 0 { return "", MakeGitError(ret) } + defer C.git_buf_free(&valBuf) - return C.GoString(ptr), nil + return C.GoString(valBuf.ptr), nil } func (c *Config) LookupBool(name string) (bool, error) { diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..e4a2c1f --- /dev/null +++ b/config_test.go @@ -0,0 +1,58 @@ +package git + +import ( + "os" + "testing" +) + +func setupConfig() (*Config, error) { + var ( + c *Config + err error + p string + ) + + p, err = ConfigFindGlobal() + if err != nil { + return nil, err + } + + c, err = OpenOndisk(nil, p) + if err != nil { + return nil, err + } + + c.SetString("foo.bar", "baz") + + return c, err +} + +func cleanupConfig() { + os.Remove(tempConfig) +} + +func TestConfigLookupString(t *testing.T) { + var ( + err error + val string + c *Config + ) + + c, err = setupConfig() + defer cleanupConfig() + if err != nil { + t.Errorf("Setup error: '%v'. Expected none\n", err) + t.FailNow() + } + defer c.Free() + + val, err = c.LookupString("foo.bar") + if err != nil { + t.Errorf("Got error: '%v', expected none\n", err) + t.FailNow() + } + + if val != "baz" { + t.Errorf("Got '%s', expected 'bar'\n", val) + } +} -- 2.45.2 From 81e0b16d9fbbfa916b34d0fa38967a14f8796f49 Mon Sep 17 00:00:00 2001 From: David Pierce Date: Sat, 26 Sep 2015 16:11:49 -0700 Subject: [PATCH 3/3] Tests config lookup methods --- config_test.go | 73 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/config_test.go b/config_test.go index e4a2c1f..8c2decc 100644 --- a/config_test.go +++ b/config_test.go @@ -5,24 +5,23 @@ import ( "testing" ) +var tempConfig = "./temp.gitconfig" + func setupConfig() (*Config, error) { var ( c *Config err error - p string ) - p, err = ConfigFindGlobal() - if err != nil { - return nil, err - } - - c, err = OpenOndisk(nil, p) + c, err = OpenOndisk(nil, tempConfig) if err != nil { return nil, err } c.SetString("foo.bar", "baz") + c.SetBool("foo.bool", true) + c.SetInt32("foo.int32", 32) + c.SetInt64("foo.int64", 64) return c, err } @@ -31,28 +30,66 @@ func cleanupConfig() { os.Remove(tempConfig) } -func TestConfigLookupString(t *testing.T) { +type TestRunner func(*Config, *testing.T) + +var tests = []TestRunner{ + // LookupString + func(c *Config, t *testing.T) { + val, err := c.LookupString("foo.bar") + if err != nil { + t.Errorf("Got LookupString error: '%v', expected none\n", err) + } + if val != "baz" { + t.Errorf("Got '%s' from LookupString, expected 'bar'\n", val) + } + }, + // LookupBool + func(c *Config, t *testing.T) { + val, err := c.LookupBool("foo.bool") + if err != nil { + t.Errorf("Got LookupBool error: '%v', expected none\n", err) + } + if !val { + t.Errorf("Got %b from LookupBool, expected 'false'\n", val) + } + }, + // LookupInt32 + func(c *Config, t *testing.T) { + val, err := c.LookupInt32("foo.int32") + if err != nil { + t.Errorf("Got LookupInt32 error: '%v', expected none\n", err) + } + if val != 32 { + t.Errorf("Got %v, expected 32\n", val) + } + }, + // LookupInt64 + func(c *Config, t *testing.T) { + val, err := c.LookupInt64("foo.int64") + if err != nil { + t.Errorf("Got LookupInt64 error: '%v', expected none\n", err) + } + if val != 64 { + t.Errorf("Got %v, expected 64\n", val) + } + }, +} + +func TestConfigLookups(t *testing.T) { var ( err error - val string c *Config ) c, err = setupConfig() defer cleanupConfig() + if err != nil { t.Errorf("Setup error: '%v'. Expected none\n", err) - t.FailNow() } defer c.Free() - val, err = c.LookupString("foo.bar") - if err != nil { - t.Errorf("Got error: '%v', expected none\n", err) - t.FailNow() - } - - if val != "baz" { - t.Errorf("Got '%s', expected 'bar'\n", val) + for _, test := range tests { + test(c, t) } } -- 2.45.2