Skip to content

Commit c200084

Browse files
committed
Merge remote-tracking branch 'upstream/master' into git_index_add_frombuffer
2 parents 79fe156 + 4bca045 commit c200084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1046
-154
lines changed

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: git2go CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- release-*
8+
- v*
9+
10+
jobs:
11+
12+
build-legacy:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
go: [ '1.9', '1.10' ]
17+
name: Go ${{ matrix.go }}
18+
19+
runs-on: ubuntu-18.04
20+
21+
steps:
22+
- name: Set up Go
23+
uses: actions/setup-go@v1
24+
with:
25+
go-version: ${{ matrix.go }}
26+
id: go
27+
- name: Check out code into the GOPATH
28+
uses: actions/checkout@v1
29+
with:
30+
fetch-depth: 1
31+
path: src/github.com/${{ github.repository }}
32+
- name: Build
33+
env:
34+
GOPATH: /home/runner/work/git2go
35+
run: |
36+
git submodule update --init
37+
make build-libgit2-static
38+
go get --tags "static" github.com/${{ github.repository }}/...
39+
go build --tags "static" github.com/${{ github.repository }}/...
40+
- name: Test
41+
env:
42+
GOPATH: /home/runner/work/git2go
43+
run: make test-static
44+
45+
build-static:
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
go: [ '1.11', '1.12', '1.13' ]
50+
name: Go ${{ matrix.go }}
51+
52+
runs-on: ubuntu-18.04
53+
54+
steps:
55+
- name: Set up Go
56+
uses: actions/setup-go@v1
57+
with:
58+
go-version: ${{ matrix.go }}
59+
id: go
60+
- name: Check out code into the Go module directory
61+
uses: actions/checkout@v1
62+
- name: Build
63+
run: |
64+
git submodule update --init
65+
make build-libgit2-static
66+
- name: Test
67+
run: make test-static
68+
69+
build-dynamic:
70+
strategy:
71+
fail-fast: false
72+
name: Go (dynamic)
73+
74+
runs-on: ubuntu-18.04
75+
76+
steps:
77+
- name: Set up Go
78+
uses: actions/setup-go@v1
79+
with:
80+
go-version: '1.13'
81+
id: go
82+
- name: Check out code into the Go module directory
83+
uses: actions/checkout@v1
84+
- name: Build
85+
run: |
86+
git submodule update --init
87+
make build-libgit2-dynamic
88+
- name: Test
89+
run: make test-dynamic

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/static-build/
2+
/dynamic-build/

.travis.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
language: go
22

33
go:
4-
- 1.7
5-
- 1.8
4+
- "1.9"
5+
- "1.10"
6+
- "1.11"
7+
- "1.12"
8+
- "1.13"
69
- tip
710

8-
script: make test-static
11+
install:
12+
- make build-libgit2-static
13+
- go get --tags "static" ./...
14+
15+
script:
16+
- make test-static
917

1018
matrix:
1119
allow_failures:
1220
- go: tip
1321

22+
git:
23+
submodules: true
24+
1425
branches:
1526
only:
1627
- master
1728
- /v\d+/
18-
- next
29+
- /release-.*/

Makefile

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,53 @@
11
default: test
22

3-
test: build-libgit2
3+
# System library
4+
# ==============
5+
# This uses whatever version of libgit2 can be found in the system.
6+
test:
47
go run script/check-MakeGitError-thread-lock.go
5-
go test ./...
8+
go test --count=1 ./...
69

7-
install: build-libgit2
10+
install:
811
go install ./...
912

10-
build-libgit2:
13+
# Bundled dynamic library
14+
# =======================
15+
# In order to avoid having to manipulate `git_dynamic.go`, which would prevent
16+
# the system-wide libgit2.so from being used in a sort of ergonomic way, this
17+
# instead moves the complexity of overriding the paths so that the built
18+
# libraries can be found by the build and tests.
19+
.PHONY: build-libgit2-dynamic
20+
build-libgit2-dynamic:
21+
./script/build-libgit2-dynamic.sh
22+
23+
dynamic-build/install/lib/libgit2.so:
24+
./script/build-libgit2-dynamic.sh
25+
26+
test-dynamic: dynamic-build/install/lib/libgit2.so
27+
PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \
28+
go run script/check-MakeGitError-thread-lock.go
29+
PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \
30+
LD_LIBRARY_PATH=dynamic-build/install/lib \
31+
go test --count=1 ./...
32+
33+
install-dynamic: dynamic-build/install/lib/libgit2.so
34+
PKG_CONFIG_PATH=dynamic-build/install/lib/pkgconfig \
35+
go install ./...
36+
37+
# Bundled static library
38+
# ======================
39+
# This is mostly used in tests, but can also be used to provide a
40+
# statically-linked library with the bundled version of libgit2.
41+
.PHONY: build-libgit2-static
42+
build-libgit2-static:
1143
./script/build-libgit2-static.sh
1244

13-
install-static: build-libgit2
14-
go install --tags "static" ./...
45+
static-build/install/lib/libgit2.a:
46+
./script/build-libgit2-static.sh
1547

16-
test-static: build-libgit2
48+
test-static: static-build/install/lib/libgit2.a
1749
go run script/check-MakeGitError-thread-lock.go
18-
go test --tags "static" ./...
50+
go test --count=1 --tags "static" ./...
51+
52+
install-static: static-build/install/lib/libgit2.a
53+
go install --tags "static" ./...

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ If using `master` or building a branch statically, we need to build libgit2 firs
3535
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.
3636

3737
git submodule update --init # get libgit2
38-
make install
38+
make install-static
3939

40-
will compile libgit2, link it into git2go and install it.
40+
will compile libgit2, link it into git2go and install it. The `master` branch is set up to follow the specific libgit2 version that is vendored, so trying dynamic linking may or may not work depending on the exact versions involved.
4141

4242
Parallelism and network operations
4343
----------------------------------
@@ -47,19 +47,19 @@ libgit2 may use OpenSSL and LibSSH2 for performing encrypted network connections
4747
Running the tests
4848
-----------------
4949

50-
For the stable version, `go test` will work as usual. For the `next` branch, similarly to installing, running the tests requires building a local libgit2 library, so the Makefile provides a wrapper that makes sure it's built
50+
For the stable version, `go test` will work as usual. For the `master` branch, similarly to installing, running the tests requires building a local libgit2 library, so the Makefile provides a wrapper that makes sure it's built
5151

52-
make test
52+
make test-static
5353

5454
Alternatively, you can build the library manually first and then run the tests
5555

5656
./script/build-libgit2-static.sh
57-
go test -v
57+
go test -v --tags "static" ./...
5858

5959
License
6060
-------
6161

62-
M to the I to the T. See the LICENSE file if you've never seen a MIT license before.
62+
M to the I to the T. See the LICENSE file if you've never seen an MIT license before.
6363

6464
Authors
6565
-------

blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
4848
var size C.size_t
4949

5050
// Go 1.6 added some increased checking of passing pointer to
51-
// C, but its check depends on its expectations of waht we
51+
// C, but its check depends on its expectations of what we
5252
// pass to the C function, so unless we take the address of
5353
// its contents at the call site itself, it can fail when
5454
// 'data' is a slice of a slice.

branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
208208
if ret < 0 {
209209
return "", MakeGitError(ret)
210210
}
211-
defer C.git_buf_free(&nameBuf)
211+
defer C.git_buf_dispose(&nameBuf)
212212

213213
return C.GoString(nameBuf.ptr), nil
214214
}
@@ -256,7 +256,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
256256
if ret < 0 {
257257
return "", MakeGitError(ret)
258258
}
259-
defer C.git_buf_free(&nameBuf)
259+
defer C.git_buf_dispose(&nameBuf)
260260

261261
return C.GoString(nameBuf.ptr), nil
262262
}

checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
3636
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
3737
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files
38-
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
38+
CheckoutUseOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
3939
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index
4040
CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
4141
CheckoutSkipLockedDirectories CheckoutStrategy = C.GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES // Ignore directories in use, they will be left empty

commit.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ func (c *Commit) Message() string {
2828
return ret
2929
}
3030

31+
func (c *Commit) MessageEncoding() string {
32+
ret := C.GoString(C.git_commit_message_encoding(c.cast_ptr))
33+
runtime.KeepAlive(c)
34+
return ret
35+
}
36+
3137
func (c *Commit) RawMessage() string {
3238
ret := C.GoString(C.git_commit_message_raw(c.cast_ptr))
3339
runtime.KeepAlive(c)
@@ -37,10 +43,10 @@ func (c *Commit) RawMessage() string {
3743
func (c *Commit) ExtractSignature() (string, string, error) {
3844

3945
var c_signed C.git_buf
40-
defer C.git_buf_free(&c_signed)
46+
defer C.git_buf_dispose(&c_signed)
4147

4248
var c_signature C.git_buf
43-
defer C.git_buf_free(&c_signature)
49+
defer C.git_buf_dispose(&c_signature)
4450

4551
oid := c.Id()
4652
repo := C.git_commit_owner(c.cast_ptr)

config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *Config) AddFile(path string, level ConfigLevel, force bool) error {
7777
runtime.LockOSThread()
7878
defer runtime.UnlockOSThread()
7979

80-
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), cbool(force))
80+
ret := C.git_config_add_file_ondisk(c.ptr, cpath, C.git_config_level_t(level), nil, cbool(force))
8181
runtime.KeepAlive(c)
8282
if ret < 0 {
8383
return MakeGitError(ret)
@@ -134,7 +134,7 @@ func (c *Config) LookupString(name string) (string, error) {
134134
if ret < 0 {
135135
return "", MakeGitError(ret)
136136
}
137-
defer C.git_buf_free(&valBuf)
137+
defer C.git_buf_dispose(&valBuf)
138138

139139
return C.GoString(valBuf.ptr), nil
140140
}
@@ -344,7 +344,7 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
344344
}
345345

346346
// OpenOndisk creates a new config instance containing a single on-disk file
347-
func OpenOndisk(parent *Config, path string) (*Config, error) {
347+
func OpenOndisk(path string) (*Config, error) {
348348
cpath := C.CString(path)
349349
defer C.free(unsafe.Pointer(cpath))
350350

@@ -390,7 +390,7 @@ func (iter *ConfigIterator) Free() {
390390

391391
func ConfigFindGlobal() (string, error) {
392392
var buf C.git_buf
393-
defer C.git_buf_free(&buf)
393+
defer C.git_buf_dispose(&buf)
394394

395395
runtime.LockOSThread()
396396
defer runtime.UnlockOSThread()
@@ -405,7 +405,7 @@ func ConfigFindGlobal() (string, error) {
405405

406406
func ConfigFindSystem() (string, error) {
407407
var buf C.git_buf
408-
defer C.git_buf_free(&buf)
408+
defer C.git_buf_dispose(&buf)
409409

410410
runtime.LockOSThread()
411411
defer runtime.UnlockOSThread()
@@ -420,7 +420,7 @@ func ConfigFindSystem() (string, error) {
420420

421421
func ConfigFindXDG() (string, error) {
422422
var buf C.git_buf
423-
defer C.git_buf_free(&buf)
423+
defer C.git_buf_dispose(&buf)
424424

425425
runtime.LockOSThread()
426426
defer runtime.UnlockOSThread()
@@ -438,7 +438,7 @@ func ConfigFindXDG() (string, error) {
438438
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
439439
func ConfigFindProgramdata() (string, error) {
440440
var buf C.git_buf
441-
defer C.git_buf_free(&buf)
441+
defer C.git_buf_dispose(&buf)
442442

443443
runtime.LockOSThread()
444444
defer runtime.UnlockOSThread()

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func setupConfig() (*Config, error) {
1313
err error
1414
)
1515

16-
c, err = OpenOndisk(nil, tempConfig)
16+
c, err = OpenOndisk(tempConfig)
1717
if err != nil {
1818
return nil, err
1919
}

credentials.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package git
22

33
/*
44
#include <git2.h>
5+
#include <git2/sys/cred.h>
6+
7+
git_credtype_t _go_git_cred_credtype(git_cred *cred);
58
*/
69
import "C"
710
import "unsafe"
@@ -27,7 +30,7 @@ func (o *Cred) HasUsername() bool {
2730
}
2831

2932
func (o *Cred) Type() CredType {
30-
return (CredType)(o.ptr.credtype)
33+
return (CredType)(C._go_git_cred_credtype(o.ptr))
3134
}
3235

3336
func credFromC(ptr *C.git_cred) *Cred {

0 commit comments

Comments
 (0)