Skip to content

Commit 6d3a349

Browse files
committed
Merge branch 'master-v23'
2 parents 157593f + 4090c40 commit 6d3a349

38 files changed

+1596
-748
lines changed

.travis.yml

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

3-
install:
4-
- cd "${HOME}"
5-
- wget -O libgit2-0.22.1.tar.gz https://github.com/libgit2/libgit2/archive/v0.22.1.tar.gz
6-
- tar -xzvf libgit2-0.22.1.tar.gz
7-
- cd libgit2-0.22.1 && mkdir build && cd build
8-
- cmake -DTHREADSAFE=ON -DBUILD_CLAR=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DCMAKE_INSTALL_PREFIX=/usr/local .. && make && sudo make install
9-
- sudo ldconfig
10-
- cd "${TRAVIS_BUILD_DIR}"
3+
sudo: required
4+
5+
install: ./script/install-libgit2.sh
116

127
go:
138
- 1.1
149
- 1.2
1510
- 1.3
1611
- 1.4
12+
- 1.5
1713
- tip
1814

1915
matrix:

branch.go

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,17 @@ func (repo *Repository) NewBranchIterator(flags BranchType) (*BranchIterator, er
9090
return newBranchIteratorFromC(repo, ptr), nil
9191
}
9292

93-
func (repo *Repository) CreateBranch(branchName string, target *Commit, force bool, signature *Signature, msg string) (*Branch, error) {
93+
func (repo *Repository) CreateBranch(branchName string, target *Commit, force bool) (*Branch, error) {
9494

9595
var ptr *C.git_reference
9696
cBranchName := C.CString(branchName)
9797
defer C.free(unsafe.Pointer(cBranchName))
9898
cForce := cbool(force)
9999

100-
cSignature, err := signature.toC()
101-
if err != nil {
102-
return nil, err
103-
}
104-
defer C.git_signature_free(cSignature)
105-
106-
var cmsg *C.char
107-
if msg == "" {
108-
cmsg = nil
109-
} else {
110-
cmsg = C.CString(msg)
111-
defer C.free(unsafe.Pointer(cmsg))
112-
}
113-
114100
runtime.LockOSThread()
115101
defer runtime.UnlockOSThread()
116102

117-
ret := C.git_branch_create(&ptr, repo.ptr, cBranchName, target.cast_ptr, cForce, cSignature, cmsg)
103+
ret := C.git_branch_create(&ptr, repo.ptr, cBranchName, target.cast_ptr, cForce)
118104
if ret < 0 {
119105
return nil, MakeGitError(ret)
120106
}
@@ -132,30 +118,16 @@ func (b *Branch) Delete() error {
132118
return nil
133119
}
134120

135-
func (b *Branch) Move(newBranchName string, force bool, signature *Signature, msg string) (*Branch, error) {
121+
func (b *Branch) Move(newBranchName string, force bool) (*Branch, error) {
136122
var ptr *C.git_reference
137123
cNewBranchName := C.CString(newBranchName)
138124
defer C.free(unsafe.Pointer(cNewBranchName))
139125
cForce := cbool(force)
140126

141-
cSignature, err := signature.toC()
142-
if err != nil {
143-
return nil, err
144-
}
145-
defer C.git_signature_free(cSignature)
146-
147-
var cmsg *C.char
148-
if msg == "" {
149-
cmsg = nil
150-
} else {
151-
cmsg = C.CString(msg)
152-
defer C.free(unsafe.Pointer(cmsg))
153-
}
154-
155127
runtime.LockOSThread()
156128
defer runtime.UnlockOSThread()
157129

158-
ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce, cSignature, cmsg)
130+
ret := C.git_branch_move(&ptr, b.Reference.ptr, cNewBranchName, cForce)
159131
if ret < 0 {
160132
return nil, MakeGitError(ret)
161133
}

checkout.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,24 @@ type CheckoutStrategy uint
1515
const (
1616
CheckoutNone CheckoutStrategy = C.GIT_CHECKOUT_NONE // Dry run, no actual updates
1717
CheckoutSafe CheckoutStrategy = C.GIT_CHECKOUT_SAFE // Allow safe updates that cannot overwrite uncommitted data
18-
CheckoutSafeCreate CheckoutStrategy = C.GIT_CHECKOUT_SAFE_CREATE // Allow safe updates plus creation of missing files
1918
CheckoutForce CheckoutStrategy = C.GIT_CHECKOUT_FORCE // Allow all updates to force working directory to look like index
19+
CheckoutRecreateMissing CheckoutStrategy = C.GIT_CHECKOUT_RECREATE_MISSING // Allow checkout to recreate missing files
2020
CheckoutAllowConflicts CheckoutStrategy = C.GIT_CHECKOUT_ALLOW_CONFLICTS // Allow checkout to make safe updates even if conflicts are found
2121
CheckoutRemoveUntracked CheckoutStrategy = C.GIT_CHECKOUT_REMOVE_UNTRACKED // Remove untracked files not in index (that are not ignored)
2222
CheckoutRemoveIgnored CheckoutStrategy = C.GIT_CHECKOUT_REMOVE_IGNORED // Remove ignored files not in index
2323
CheckoutUpdateOnly CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_ONLY // Only update existing files, don't create new ones
2424
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
2525
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
26+
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files
27+
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
28+
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index
2629
CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
27-
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files (NOT IMPLEMENTED)
28-
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index (NOT IMPLEMENTED)
29-
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index (NOT IMPLEMENTED)
30+
CheckoutSkipLockedDirectories CheckoutStrategy = C.GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES // Ignore directories in use, they will be left empty
31+
CheckoutDontOverwriteIgnored CheckoutStrategy = C.GIT_CHECKOUT_DONT_OVERWRITE_IGNORED // Don't overwrite ignored files that exist in the checkout target
32+
CheckoutConflictStyleMerge CheckoutStrategy = C.GIT_CHECKOUT_CONFLICT_STYLE_MERGE // Write normal merge files for conflicts
33+
CheckoutConflictStyleDiff3 CheckoutStrategy = C.GIT_CHECKOUT_CONFLICT_STYLE_DIFF3 // Include common ancestor data in diff3 format files for conflicts
34+
CheckoutDontRemoveExisting CheckoutStrategy = C.GIT_CHECKOUT_DONT_REMOVE_EXISTING // Don't overwrite existing files or folders
35+
CheckoutDontWriteIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_WRITE_INDEX // Normally checkout writes the index upon completion; this prevents that
3036
CheckoutUpdateSubmodules CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_SUBMODULES // Recursively checkout submodules with same options (NOT IMPLEMENTED)
3137
CheckoutUpdateSubmodulesIfChanged CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED // Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED)
3238
)

cherrypick_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func checkout(t *testing.T, repo *Repository, commit *Commit) {
1616
t.Fatal(err)
1717
}
1818

19-
err = repo.SetHeadDetached(commit.Id(), commit.Author(), "checkout")
19+
err = repo.SetHeadDetached(commit.Id())
2020
if err != nil {
2121
t.Fatal(err)
2222
}

clone.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ import (
1111
"unsafe"
1212
)
1313

14-
type RemoteCreateCallback func(repo Repository, name, url string) (*Remote, ErrorCode)
14+
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, ErrorCode)
1515

1616
type CloneOptions struct {
1717
*CheckoutOpts
18-
*RemoteCallbacks
18+
*FetchOptions
1919
Bare bool
2020
CheckoutBranch string
2121
RemoteCreateCallback RemoteCreateCallback
2222
}
2323

2424
func Clone(url string, path string, options *CloneOptions) (*Repository, error) {
25-
repo := new(Repository)
26-
2725
curl := C.CString(url)
2826
defer C.free(unsafe.Pointer(curl))
2927

@@ -40,30 +38,33 @@ func Clone(url string, path string, options *CloneOptions) (*Repository, error)
4038

4139
runtime.LockOSThread()
4240
defer runtime.UnlockOSThread()
43-
ret := C.git_clone(&repo.ptr, curl, cpath, copts)
41+
42+
var ptr *C.git_repository
43+
ret := C.git_clone(&ptr, curl, cpath, copts)
44+
freeCheckoutOpts(&copts.checkout_opts)
4445

4546
if ret < 0 {
4647
return nil, MakeGitError(ret)
4748
}
4849

49-
runtime.SetFinalizer(repo, (*Repository).Free)
50-
return repo, nil
50+
return newRepositoryFromC(ptr), nil
5151
}
5252

5353
//export remoteCreateCallback
5454
func remoteCreateCallback(cremote unsafe.Pointer, crepo unsafe.Pointer, cname, curl *C.char, payload unsafe.Pointer) C.int {
5555
name := C.GoString(cname)
5656
url := C.GoString(curl)
57-
repo := Repository{(*C.git_repository)(crepo)}
57+
repo := newRepositoryFromC((*C.git_repository)(crepo))
58+
// We don't own this repository, so make sure we don't try to free it
59+
runtime.SetFinalizer(repo, nil)
5860

5961
if opts, ok := pointerHandles.Get(payload).(CloneOptions); ok {
6062
remote, err := opts.RemoteCreateCallback(repo, name, url)
63+
// clear finalizer as the calling C function will
64+
// free the remote itself
65+
runtime.SetFinalizer(remote, nil)
6166

6267
if err == ErrOk && remote != nil {
63-
// clear finalizer as the calling C function will
64-
// free the remote itself
65-
runtime.SetFinalizer(remote, nil)
66-
6768
cptr := (**C.git_remote)(cremote)
6869
*cptr = remote.ptr
6970
} else if err == ErrOk && remote == nil {
@@ -83,7 +84,7 @@ func populateCloneOptions(ptr *C.git_clone_options, opts *CloneOptions) {
8384
return
8485
}
8586
populateCheckoutOpts(&ptr.checkout_opts, opts.CheckoutOpts)
86-
populateRemoteCallbacks(&ptr.remote_callbacks, opts.RemoteCallbacks)
87+
populateFetchOptions(&ptr.fetch_opts, opts.FetchOptions)
8788
ptr.bare = cbool(opts.Bare)
8889

8990
if opts.RemoteCreateCallback != nil {

clone_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ func TestClone(t *testing.T) {
1818
path, err := ioutil.TempDir("", "git2go")
1919
checkFatal(t, err)
2020

21+
ref, err := repo.References.Lookup("refs/heads/master")
22+
checkFatal(t, err)
23+
2124
repo2, err := Clone(repo.Path(), path, &CloneOptions{Bare: true})
2225
defer cleanupTestRepo(t, repo2)
2326

2427
checkFatal(t, err)
28+
29+
ref2, err := repo2.References.Lookup("refs/heads/master")
30+
checkFatal(t, err)
31+
32+
if ref.Cmp(ref2) != 0 {
33+
t.Fatal("reference in clone does not match original ref")
34+
}
2535
}
2636

2737
func TestCloneWithCallback(t *testing.T) {
@@ -37,10 +47,10 @@ func TestCloneWithCallback(t *testing.T) {
3747

3848
opts := CloneOptions{
3949
Bare: true,
40-
RemoteCreateCallback: func(r Repository, name, url string) (*Remote, ErrorCode) {
50+
RemoteCreateCallback: func(r *Repository, name, url string) (*Remote, ErrorCode) {
4151
testPayload += 1
4252

43-
remote, err := r.CreateRemote(REMOTENAME, url)
53+
remote, err := r.Remotes.Create(REMOTENAME, url)
4454
if err != nil {
4555
return nil, ErrGeneric
4656
}
@@ -58,7 +68,7 @@ func TestCloneWithCallback(t *testing.T) {
5868
t.Fatal("Payload's value has not been changed")
5969
}
6070

61-
remote, err := repo2.LookupRemote(REMOTENAME)
71+
remote, err := repo2.Remotes.Lookup(REMOTENAME)
6272
if err != nil || remote == nil {
6373
t.Fatal("Remote was not created properly")
6474
}

0 commit comments

Comments
 (0)