Fix crash when using Pathspec in StatusOptions

Using `StatusOptions.Pathspec` results in a fatal error panic with
the message 'unexpected signal during runtime execution'.

This is because the `&cpathspec` C.git_strarray gets freed in
`*StatusOptions.toC()` before being passed to
`C.git_status_init_options()` in `*Repository.StatusList()`
(see https://github.com/libgit2/git2go/blob/b3e7705c48f038ef335204a2a9e1ee829784c30e/status.go#L138)

The relevant panic trace is:

```
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x4062609]

runtime stack:
runtime.throw(0x469a080, 0x2a)
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/sigpanic_unix.go:12
+0x5a

goroutine 71 [syscall, locked to thread]:
runtime.cgocall(0x400a720, 0xc8204e9998, 0x0)
    /usr/local/Cellar/go/1.5.1/libexec/src/runtime/cgocall.go:120 +0x11b
fp=0xc8204e9968 sp=0xc8204e9938
github.com/libgit2/git2go._Cfunc_git_status_list_new(0xc8204c39c8,
0x5e17780, 0xc820478c40, 0xc800000000)
    ??:0 +0x39 fp=0xc8204e9998 sp=0xc8204e9968
github.com/libgit2/git2go.(*Repository).StatusList(0xc820013290,
0xc8204e9b58, 0x0, 0x0, 0x0)
    /Users/calin/go/src/github.com/libgit2/git2go/status.go:168 +0x11d
fp=0xc8204e99e8 sp=0xc8204e9998
```
1 file changed
tree: e4c7f57478ccc86de4a236d26b03249bc6380e94
  1. script/
  2. .travis.yml
  3. blame.go
  4. blame_test.go
  5. blob.go
  6. blob_test.go
  7. branch.go
  8. branch_test.go
  9. checkout.go
  10. cherrypick.go
  11. cherrypick_test.go
  12. clone.go
  13. clone_test.go
  14. commit.go
  15. config.go
  16. credentials.go
  17. describe.go
  18. describe_test.go
  19. diff.go
  20. diff_test.go
  21. git.go
  22. git_test.go
  23. graph.go
  24. handles.go
  25. index.go
  26. index_test.go
  27. LICENSE
  28. Makefile
  29. merge.go
  30. merge_test.go
  31. note.go
  32. note_test.go
  33. object.go
  34. object_test.go
  35. odb.go
  36. odb_test.go
  37. packbuilder.go
  38. patch.go
  39. patch_test.go
  40. push_test.go
  41. README.md
  42. refdb.go
  43. reference.go
  44. reference_test.go
  45. remote.go
  46. remote_test.go
  47. repository.go
  48. reset.go
  49. reset_test.go
  50. revparse.go
  51. revparse_test.go
  52. settings.go
  53. settings_test.go
  54. signature.go
  55. status.go
  56. status_test.go
  57. submodule.go
  58. submodule_test.go
  59. tag.go
  60. tag_test.go
  61. tree.go
  62. tree_test.go
  63. walk.go
  64. wrapper.c
README.md

git2go

GoDoc Build Status

Go bindings for libgit2. The master branch follows the latest libgit2 release. The versioned branches indicate which libgit2 version they work against.

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.

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.

Stable version

git2go has master which tracks the latest release of libgit2, and versioned branches which indicate which version of libgit2 they work against. Install the development package on your system via your favourite package manager or from source and you can use a service like gopkg.in to use the appropriate version. For the libgit2 v0.22 case, you can use

import "gopkg.in/libgit2/git2go.v22"

to use a version of git2go which will work against libgit2 v0.22 and dynamically link to the library. You can use

import "github.com/libgit2/git2go"

to use the version which works against the latest release.

From next

The next branch follows libgit2's master branch, which means there is no stable API or ABI to link against. git2go can statically link against a vendored version of libgit2.

Run go get -d github.com/libgit2/git2go to download the code and go to your $GOPATH/src/github.com/libgit2/git2go directory. From there, we need to build the C code and put it into the resulting go binary.

git checkout next
git submodule update --init # get libgit2
make install

will compile libgit2. Run go install so that it's statically linked to the git2go package.

Parallelism and network operations

libgit2 uses OpenSSL and LibSSH2 for performing encrypted network connections. For now, git2go asks libgit2 to set locking for OpenSSL. This makes HTTPS connections thread-safe, but it is fragile and will likely stop doing it soon. This may also make SSH connections thread-safe if your copy of libssh2 is linked against OpenSSL. Check libgit2's THREADSAFE.md for more information.

Running the tests

For the stable version, go test will work as usual. For the next branch, similarly to installing, running the tests requires linking against the local libgit2 library, so the Makefile provides a wrapper

make test

Alternatively, if you want to pass arguments to go test, you can use the script that sets it all up

./script/with-static.sh go test -v

which will run the specified arguments with the correct environment variables.

License

M to the I to the T. See the LICENSE file if you've never seen a MIT license before.

Authors

  • Carlos Martín (@carlosmn)
  • Vicent Martí (@vmg)