Compare commits
45 Commits
main
...
cherry-pic
Author | SHA1 | Date |
---|---|---|
lhchavez | 3d458b1e58 | |
github-actions[bot] | ea4c8f5916 | |
github-actions[bot] | 1d03712afd | |
Dylan Richardson | 4941b3d1cb | |
github-actions[bot] | de2552a523 | |
github-actions[bot] | 71def521d3 | |
lhchavez | 0c7782a2f6 | |
lhchavez | 1828c9db5e | |
github-actions[bot] | a4d6699c91 | |
github-actions[bot] | 34d31c0438 | |
lhchavez | 7145746145 | |
github-actions[bot] | c26c144a82 | |
github-actions[bot] | 4a1a8951e0 | |
github-actions[bot] | 7b11c62bc1 | |
github-actions[bot] | 781e820fca | |
github-actions[bot] | bb7920d61f | |
lhchavez | 5bc02752df | |
github-actions[bot] | 6ee9afef19 | |
github-actions[bot] | d410e7ecf7 | |
github-actions[bot] | a2a0858e3a | |
lhchavez | a47c12d858 | |
lhchavez | dbb9b3b5d0 | |
lhchavez | a7c2176e8d | |
github-actions[bot] | 103e835387 | |
github-actions[bot] | b5bd080841 | |
github-actions[bot] | 3bbde00303 | |
github-actions[bot] | 0e6a600b79 | |
github-actions[bot] | a8883c8679 | |
github-actions[bot] | 9030cade50 | |
github-actions[bot] | 5621f1b826 | |
github-actions[bot] | 71aa7350af | |
github-actions[bot] | 5cfb6c2b85 | |
github-actions[bot] | 9b6e1d92cc | |
github-actions[bot] | d21ba51f4e | |
github-actions[bot] | 3128d76936 | |
lhchavez | e57ff6c391 | |
lhchavez | 07b98b44c3 | |
github-actions[bot] | b7d6ab837c | |
github-actions[bot] | a54915d90b | |
nmeum | 30caea3934 | |
github-actions[bot] | 46766a72f0 | |
github-actions[bot] | 4f57b9bff6 | |
github-actions[bot] | c53a41ce8e | |
github-actions[bot] | 2bf0e14e9e | |
lhchavez | bcfa256837 |
|
@ -0,0 +1,54 @@
|
||||||
|
name: Backport to older releases
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
backport:
|
||||||
|
name: Backport change to branch ${{ matrix.branch }}
|
||||||
|
continue-on-error: true
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
branch: [ 'release-0.28', 'release-0.27' ]
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Create a cherry-pick PR
|
||||||
|
run: |
|
||||||
|
if ! git diff --quiet HEAD^ HEAD -- vendor/libgit2; then
|
||||||
|
echo '::warning::Skipping cherry-pick since it is a vendored libgit2 bump'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
BRANCH_NAME="cherry-pick-${{ github.run_id }}-${{ matrix.branch }}"
|
||||||
|
|
||||||
|
# Setup usernames and authentication
|
||||||
|
git config --global user.name "${{ github.actor }}"
|
||||||
|
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
|
||||||
|
cat <<- EOF > $HOME/.netrc
|
||||||
|
machine github.com
|
||||||
|
login ${{ github.actor }}
|
||||||
|
password ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
machine api.github.com
|
||||||
|
login ${{ github.actor }}
|
||||||
|
password ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
EOF
|
||||||
|
chmod 600 $HOME/.netrc
|
||||||
|
|
||||||
|
# Create the cherry-pick commit and create the PR for it.
|
||||||
|
git checkout "${{ matrix.branch }}"
|
||||||
|
git switch -c "${BRANCH_NAME}"
|
||||||
|
git cherry-pick -x "${{ github.sha }}"
|
||||||
|
git push --set-upstream origin "${BRANCH_NAME}"
|
||||||
|
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" gh pr create \
|
||||||
|
--base "${{ matrix.branch }}" \
|
||||||
|
--title "$(git --no-pager show --format="%s" --no-patch HEAD)" \
|
||||||
|
--body "$(git --no-pager show --format="%b" --no-patch HEAD)"
|
|
@ -0,0 +1,133 @@
|
||||||
|
name: git2go CI
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- release-*
|
||||||
|
- v*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build-static:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
go: [ '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17' ]
|
||||||
|
name: Go ${{ matrix.go }}
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
git submodule update --init
|
||||||
|
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
||||||
|
make build-libgit2-static
|
||||||
|
- name: Test
|
||||||
|
run: make TEST_ARGS=-test.v test-static
|
||||||
|
|
||||||
|
build-dynamic:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
name: Go (dynamic)
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
git submodule update --init
|
||||||
|
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
||||||
|
make build-libgit2-dynamic
|
||||||
|
- name: Test
|
||||||
|
run: make TEST_ARGS=-test.v test-dynamic
|
||||||
|
|
||||||
|
build-system-dynamic:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
libgit2:
|
||||||
|
- 'v1.0.0'
|
||||||
|
- 'v1.1.0'
|
||||||
|
- 'v1.2.0'
|
||||||
|
- 'v1.3.0'
|
||||||
|
name: Go (system-wide, dynamic)
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Build libgit2 ${{ matrix.libgit2 }}
|
||||||
|
run: |
|
||||||
|
git submodule update --init
|
||||||
|
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
||||||
|
sudo env BUILD_LIBGIT_REF=${{ matrix.libgit2 }} ./script/build-libgit2.sh --dynamic --system
|
||||||
|
- name: Test
|
||||||
|
run: make TEST_ARGS=-test.v test
|
||||||
|
|
||||||
|
build-system-static:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
name: Go (system-wide, static)
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- name: Build libgit2
|
||||||
|
run: |
|
||||||
|
git submodule update --init
|
||||||
|
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
||||||
|
sudo ./script/build-libgit2.sh --static --system
|
||||||
|
- name: Test
|
||||||
|
run: go test --count=1 --tags "static,system_libgit2" ./...
|
||||||
|
|
||||||
|
check-generate:
|
||||||
|
name: Check generated files were not modified
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
id: go
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install libgit2 build dependencies
|
||||||
|
run: |
|
||||||
|
git submodule update --init
|
||||||
|
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
||||||
|
go install golang.org/x/tools/cmd/stringer@latest
|
||||||
|
- name: Generate files
|
||||||
|
run: |
|
||||||
|
export PATH=$(go env GOPATH)/bin:$PATH
|
||||||
|
make generate
|
||||||
|
- name: Check nothing changed
|
||||||
|
run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1)
|
|
@ -0,0 +1,28 @@
|
||||||
|
name: Tag new releases
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- release-*
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
tag-release:
|
||||||
|
name: Bump tag in ${{ github.ref }}
|
||||||
|
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Bump version and push tag
|
||||||
|
id: bump-version
|
||||||
|
uses: anothrNick/github-tag-action@43ed073f5c1445ca8b80d920ce2f8fa550ae4e8d
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
WITH_V: true
|
||||||
|
DEFAULT_BUMP: patch
|
||||||
|
TAG_CONTEXT: branch
|
||||||
|
RELEASE_BRANCHES: .*
|
|
@ -1,4 +1,2 @@
|
||||||
/static-build/
|
/static-build/
|
||||||
/dynamic-build/
|
/dynamic-build/
|
||||||
|
|
||||||
go.*
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
[submodule "vendor/libgit2"]
|
||||||
|
path = vendor/libgit2
|
||||||
|
url = https://github.com/libgit2/libgit2
|
|
@ -1,4 +1,3 @@
|
||||||
//go:build static && !system_libgit2
|
|
||||||
// +build static,!system_libgit2
|
// +build static,!system_libgit2
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
@ -10,8 +9,8 @@ package git
|
||||||
#cgo CFLAGS: -DLIBGIT2_STATIC
|
#cgo CFLAGS: -DLIBGIT2_STATIC
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
|
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 0 || LIBGIT2_VER_MINOR > 3
|
||||||
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.0"
|
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.0.0 and v1.3.0".
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
//go:build !static
|
|
||||||
// +build !static
|
// +build !static
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo pkg-config: libgit2
|
#cgo pkg-config: libgit2
|
||||||
#cgo CFLAGS: -DLIBGIT2_DYNAMIC -I/opt/libgit2/include
|
#cgo CFLAGS: -DLIBGIT2_DYNAMIC
|
||||||
#cgo LDFLAGS: -L/opt/libgit2 -lgit2
|
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
|
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 0 || LIBGIT2_VER_MINOR > 3
|
||||||
|
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.0.0 and v1.3.0".
|
||||||
|
#endif
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
//go:build static && system_libgit2
|
|
||||||
// +build static,system_libgit2
|
// +build static,system_libgit2
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
@ -8,8 +7,8 @@ package git
|
||||||
#cgo CFLAGS: -DLIBGIT2_STATIC
|
#cgo CFLAGS: -DLIBGIT2_STATIC
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
|
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 0 || LIBGIT2_VER_MINOR > 3
|
||||||
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.0"
|
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.0.0 and v1.3.0".
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
The MIT License
|
The MIT License
|
||||||
|
|
||||||
Copyright (c) 2013 The libgit2 contributors
|
Copyright (c) 2013 The git2go contributors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
15
Makefile
15
Makefile
|
@ -1,11 +1,7 @@
|
||||||
TEST_ARGS ?= --count=1
|
TEST_ARGS ?= --count=1
|
||||||
|
|
||||||
PKG_CONFIG_PATH=/opt/libgit2/
|
default: test
|
||||||
|
|
||||||
default: goimports test
|
|
||||||
|
|
||||||
goimports:
|
|
||||||
goimports -w *.go
|
|
||||||
|
|
||||||
generate: static-build/install/lib/libgit2.a
|
generate: static-build/install/lib/libgit2.a
|
||||||
go generate --tags "static" ./...
|
go generate --tags "static" ./...
|
||||||
|
@ -14,19 +10,12 @@ generate: static-build/install/lib/libgit2.a
|
||||||
# ==============
|
# ==============
|
||||||
# This uses whatever version of libgit2 can be found in the system.
|
# This uses whatever version of libgit2 can be found in the system.
|
||||||
test:
|
test:
|
||||||
-go-mod-clean # go install go.wit.com/apps/go-mod-clean@latest
|
|
||||||
go run script/check-MakeGitError-thread-lock.go
|
go run script/check-MakeGitError-thread-lock.go
|
||||||
PKG_CONFIG_PATH=/opt/libgit2/ go test -v -x $(TEST_ARGS) ./...
|
go test $(TEST_ARGS) ./...
|
||||||
|
|
||||||
add-remote:
|
|
||||||
git remote add git2go https://github.com/libgit2/git2go.git
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
go install ./...
|
go install ./...
|
||||||
|
|
||||||
clean:
|
|
||||||
rm go.*
|
|
||||||
|
|
||||||
# Bundled dynamic library
|
# Bundled dynamic library
|
||||||
# =======================
|
# =======================
|
||||||
# In order to avoid having to manipulate `git_dynamic.go`, which would prevent
|
# In order to avoid having to manipulate `git_dynamic.go`, which would prevent
|
||||||
|
|
73
README.md
73
README.md
|
@ -1,48 +1,87 @@
|
||||||
GO libgit2
|
git2go
|
||||||
======
|
======
|
||||||
[![GoDoc](https://godoc.org/go.wit.com/lib/libgit2?status.svg)](http://godoc.org/go.wit.com/lib/libgit2) [![Build Status](https://travis-ci.org/libgit2/libgit2.svg?branch=main)](https://travis-ci.org/libgit2/libgit2)
|
[![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go/v30) [![Build Status](https://travis-ci.org/libgit2/git2go.svg?branch=main)](https://travis-ci.org/libgit2/git2go)
|
||||||
|
|
||||||
Go bindings for [libgit2](http://libgit2.github.com/).
|
Go bindings for [libgit2](http://libgit2.github.com/).
|
||||||
|
|
||||||
### Updated 2024/12/16
|
|
||||||
|
|
||||||
### Which Go version to use
|
### Which Go version to use
|
||||||
|
|
||||||
* This package is updated to work against libgit2 version 1.8 on Debian sid
|
Due to the fact that Go 1.11 module versions have semantic meaning and don't necessarily align with libgit2's release schedule, please consult the following table for a mapping between libgit2 and git2go module versions:
|
||||||
* There is one line commented out which needs to be fixed in remote.go
|
|
||||||
* some of the tests seem to run
|
| libgit2 | git2go |
|
||||||
|
|---------|---------------|
|
||||||
|
| main | (will be v31) |
|
||||||
|
| 1.0 | v30 |
|
||||||
|
| 0.99 | v29 |
|
||||||
|
| 0.28 | v28 |
|
||||||
|
| 0.27 | v27 |
|
||||||
|
|
||||||
|
You can import them in your project with the version's major number as a suffix. For example, if you have libgit2 v1.0 installed, you'd import git2go v30 with
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go install go.wit.com/apps/go-clone@latest
|
go get github.com/libgit2/git2go/v30
|
||||||
go install go.wit.com/apps/go-mod-clean@latest
|
```
|
||||||
go-clone --recusive go.wit.com/lib/libgit2
|
```go
|
||||||
|
import "github.com/libgit2/git2go/v30"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
which will ensure there are no sudden changes to the API.
|
||||||
|
|
||||||
|
The `main` branch follows the tip of libgit2 itself (with some lag) and as such has no guarantees on the stability of libgit2's API. Thus this only supports statically linking against libgit2.
|
||||||
|
|
||||||
### Which branch to send Pull requests to
|
### Which branch to send Pull requests to
|
||||||
|
|
||||||
TODO: not sure yet
|
If there's something version-specific that you'd want to contribute to, you can send them to the `release-${MAJOR}.${MINOR}` branches, which follow libgit2's releases.
|
||||||
|
|
||||||
Installing
|
Installing
|
||||||
----------
|
----------
|
||||||
|
|
||||||
This project wraps the functionality provided by libgit2. It thus needs it in order to perform the work.
|
This project wraps the functionality provided by libgit2. It thus needs it in order to perform the work.
|
||||||
|
|
||||||
This project wraps the functionality provided by libgit2. If you're using a versioned branch, install it to your system via your system's package manager and then install libgit2.
|
This project wraps the functionality provided by libgit2. If you're using a versioned branch, install it to your system via your system's package manager and then install git2go.
|
||||||
|
|
||||||
|
|
||||||
### Versioned branch, dynamic linking
|
### Versioned branch, dynamic linking
|
||||||
|
|
||||||
When linking dynamically against a released version of libgit2, install it via your system's package manager. CGo will take care of finding its pkg-config file and set up the linking. Import via Go modules, e.g. to work against libgit2 v1.2
|
When linking dynamically against a released version of libgit2, install it via your system's package manager. CGo will take care of finding its pkg-config file and set up the linking. Import via Go modules, e.g. to work against libgit2 v1.0
|
||||||
|
|
||||||
```go
|
```go
|
||||||
goimports -w *.go
|
import "github.com/libgit2/git2go/v30"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Versioned branch, static linking
|
||||||
|
|
||||||
|
Follow the instructions for [Versioned branch, dynamic linking](#versioned-branch-dynamic-linking), but pass the `-tags static,system_libgit2` flag to all `go` commands that build any binaries. For instance:
|
||||||
|
|
||||||
|
go build -tags static,system_libgit2 github.com/my/project/...
|
||||||
|
go test -tags static,system_libgit2 github.com/my/project/...
|
||||||
|
go install -tags static,system_libgit2 github.com/my/project/...
|
||||||
|
|
||||||
|
### `main` branch, or vendored static linking
|
||||||
|
|
||||||
|
If using `main` or building a branch with the vendored libgit2 statically, we need to build libgit2 first. In order to build it, you need `cmake`, `pkg-config` and a C compiler. You will also need the development packages for OpenSSL (outside of Windows or macOS) and LibSSH2 installed if you want libgit2 to support HTTPS and SSH respectively. Note that even if libgit2 is included in the resulting binary, its dependencies will not be.
|
||||||
|
|
||||||
|
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 submodule update --init # get libgit2
|
||||||
|
make install-static
|
||||||
|
|
||||||
|
will compile libgit2, link it into git2go and install it. The `main` 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.
|
||||||
|
|
||||||
|
In order to let Go pass the correct flags to `pkg-config`, `-tags static` needs to be passed to all `go` commands that build any binaries. For instance:
|
||||||
|
|
||||||
|
go build -tags static github.com/my/project/...
|
||||||
|
go test -tags static github.com/my/project/...
|
||||||
|
go install -tags static github.com/my/project/...
|
||||||
|
|
||||||
|
One thing to take into account is that since Go expects the `pkg-config` file to be within the same directory where `make install-static` was called, so the `go.mod` file may need to have a [`replace` directive](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive) so that the correct setup is achieved. So if `git2go` is checked out at `$GOPATH/src/github.com/libgit2/git2go` and your project at `$GOPATH/src/github.com/my/project`, the `go.mod` file of `github.com/my/project` might need to have a line like
|
||||||
|
|
||||||
|
replace github.com/libgit2/git2go/v30 => ../../libgit2/git2go
|
||||||
|
|
||||||
Parallelism and network operations
|
Parallelism and network operations
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
libgit2 may use OpenSSL and LibSSH2 for performing encrypted network connections. For now, libgit2 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.
|
libgit2 may use 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
|
Running the tests
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -64,6 +103,6 @@ M to the I to the T. See the LICENSE file if you've never seen an MIT license be
|
||||||
Authors
|
Authors
|
||||||
-------
|
-------
|
||||||
|
|
||||||
- Carlos Martín (github@carlosmn)
|
- Carlos Martín (@carlosmn)
|
||||||
- Vicent Martí (github@vmg)
|
- Vicent Martí (@vmg)
|
||||||
|
|
||||||
|
|
1
blame.go
1
blame.go
|
@ -48,7 +48,6 @@ const (
|
||||||
BlameTrackCopiesAnyCommitCopies BlameOptionsFlag = C.GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES
|
BlameTrackCopiesAnyCommitCopies BlameOptionsFlag = C.GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES
|
||||||
BlameFirstParent BlameOptionsFlag = C.GIT_BLAME_FIRST_PARENT
|
BlameFirstParent BlameOptionsFlag = C.GIT_BLAME_FIRST_PARENT
|
||||||
BlameUseMailmap BlameOptionsFlag = C.GIT_BLAME_USE_MAILMAP
|
BlameUseMailmap BlameOptionsFlag = C.GIT_BLAME_USE_MAILMAP
|
||||||
BlameIgnoreWhitespace BlameOptionsFlag = C.GIT_BLAME_IGNORE_WHITESPACE
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *Repository) BlameFile(path string, opts *BlameOptions) (*Blame, error) {
|
func (v *Repository) BlameFile(path string, opts *BlameOptions) (*Blame, error) {
|
||||||
|
|
11
checkout.go
11
checkout.go
|
@ -7,6 +7,7 @@ extern void _go_git_populate_checkout_callbacks(git_checkout_options *opts);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -48,8 +49,8 @@ const (
|
||||||
CheckoutUpdateSubmodulesIfChanged CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED // Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED)
|
CheckoutUpdateSubmodulesIfChanged CheckoutStrategy = C.GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED // Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED)
|
||||||
)
|
)
|
||||||
|
|
||||||
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) error
|
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) ErrorCode
|
||||||
type CheckoutProgressCallback func(path string, completed, total uint)
|
type CheckoutProgressCallback func(path string, completed, total uint) ErrorCode
|
||||||
|
|
||||||
type CheckoutOptions struct {
|
type CheckoutOptions struct {
|
||||||
Strategy CheckoutStrategy // Default will be a dry run
|
Strategy CheckoutStrategy // Default will be a dry run
|
||||||
|
@ -115,9 +116,9 @@ func checkoutNotifyCallback(
|
||||||
if data.options.NotifyCallback == nil {
|
if data.options.NotifyCallback == nil {
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
err := data.options.NotifyCallback(CheckoutNotifyType(why), path, baseline, target, workdir)
|
ret := data.options.NotifyCallback(CheckoutNotifyType(why), path, baseline, target, workdir)
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
|
|
|
@ -9,16 +9,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type CherrypickOptions struct {
|
type CherrypickOptions struct {
|
||||||
Mainline uint
|
Version uint
|
||||||
MergeOptions MergeOptions
|
Mainline uint
|
||||||
CheckoutOptions CheckoutOptions
|
MergeOpts MergeOptions
|
||||||
|
CheckoutOpts CheckoutOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
||||||
opts := CherrypickOptions{
|
opts := CherrypickOptions{
|
||||||
Mainline: uint(c.mainline),
|
Version: uint(c.version),
|
||||||
MergeOptions: mergeOptionsFromC(&c.merge_opts),
|
Mainline: uint(c.mainline),
|
||||||
CheckoutOptions: checkoutOptionsFromC(&c.checkout_opts),
|
MergeOpts: mergeOptionsFromC(&c.merge_opts),
|
||||||
|
CheckoutOpts: checkoutOptionsFromC(&c.checkout_opts),
|
||||||
}
|
}
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
@ -29,8 +31,8 @@ func populateCherrypickOptions(copts *C.git_cherrypick_options, opts *Cherrypick
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.mainline = C.uint(opts.Mainline)
|
copts.mainline = C.uint(opts.Mainline)
|
||||||
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
|
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@ func (r *Repository) CherrypickCommit(pick, our *Commit, opts CherrypickOptions)
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOptions)
|
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOpts)
|
||||||
defer freeMergeOptions(cOpts)
|
defer freeMergeOptions(cOpts)
|
||||||
|
|
||||||
var ptr *C.git_index
|
var ptr *C.git_index
|
||||||
|
|
18
clone.go
18
clone.go
|
@ -7,15 +7,16 @@ extern void _go_git_populate_clone_callbacks(git_clone_options *opts);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, error)
|
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, ErrorCode)
|
||||||
|
|
||||||
type CloneOptions struct {
|
type CloneOptions struct {
|
||||||
CheckoutOptions CheckoutOptions
|
*CheckoutOpts
|
||||||
FetchOptions FetchOptions
|
*FetchOptions
|
||||||
Bare bool
|
Bare bool
|
||||||
CheckoutBranch string
|
CheckoutBranch string
|
||||||
RemoteCreateCallback RemoteCreateCallback
|
RemoteCreateCallback RemoteCreateCallback
|
||||||
|
@ -70,10 +71,9 @@ func remoteCreateCallback(
|
||||||
panic("invalid remote create callback")
|
panic("invalid remote create callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
remote, err := data.options.RemoteCreateCallback(repo, name, url)
|
remote, ret := data.options.RemoteCreateCallback(repo, name, url)
|
||||||
|
if ret < 0 {
|
||||||
if err != nil {
|
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
||||||
*data.errorTarget = err
|
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
if remote == nil {
|
if remote == nil {
|
||||||
|
@ -100,8 +100,8 @@ func populateCloneOptions(copts *C.git_clone_options, opts *CloneOptions, errorT
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
|
||||||
populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
|
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget)
|
||||||
copts.bare = cbool(opts.Bare)
|
copts.bare = cbool(opts.Bare)
|
||||||
|
|
||||||
if opts.RemoteCreateCallback != nil {
|
if opts.RemoteCreateCallback != nil {
|
||||||
|
|
|
@ -50,9 +50,15 @@ func TestCloneWithCallback(t *testing.T) {
|
||||||
|
|
||||||
opts := CloneOptions{
|
opts := CloneOptions{
|
||||||
Bare: true,
|
Bare: true,
|
||||||
RemoteCreateCallback: func(r *Repository, name, url string) (*Remote, error) {
|
RemoteCreateCallback: func(r *Repository, name, url string) (*Remote, ErrorCode) {
|
||||||
testPayload += 1
|
testPayload += 1
|
||||||
return r.Remotes.Create(REMOTENAME, url)
|
|
||||||
|
remote, err := r.Remotes.Create(REMOTENAME, url)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrorCodeGeneric
|
||||||
|
}
|
||||||
|
|
||||||
|
return remote, ErrorCodeOK
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
23
commit.go
23
commit.go
|
@ -37,14 +37,10 @@ func (c *Commit) Message() string {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) MessageEncoding() MessageEncoding {
|
func (c *Commit) MessageEncoding() string {
|
||||||
ptr := C.git_commit_message_encoding(c.cast_ptr)
|
ret := C.GoString(C.git_commit_message_encoding(c.cast_ptr))
|
||||||
if ptr == nil {
|
|
||||||
return MessageEncodingUTF8
|
|
||||||
}
|
|
||||||
ret := C.GoString(ptr)
|
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
return MessageEncoding(ret)
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) RawMessage() string {
|
func (c *Commit) RawMessage() string {
|
||||||
|
@ -68,19 +64,6 @@ func (c *Commit) ContentToSign() string {
|
||||||
// CommitSigningCallback defines a function type that takes some data to sign and returns (signature, signature_field, error)
|
// CommitSigningCallback defines a function type that takes some data to sign and returns (signature, signature_field, error)
|
||||||
type CommitSigningCallback func(string) (signature, signatureField string, err error)
|
type CommitSigningCallback func(string) (signature, signatureField string, err error)
|
||||||
|
|
||||||
// CommitCreateCallback defines a function type that is called when another
|
|
||||||
// function is going to create commits (for example, Rebase) to allow callers
|
|
||||||
// to override the commit creation behavior. For example, users may wish to
|
|
||||||
// sign commits by providing this information to Repository.CreateCommitBuffer,
|
|
||||||
// signing that buffer, then calling Repository.CreateCommitWithSignature.
|
|
||||||
type CommitCreateCallback func(
|
|
||||||
author, committer *Signature,
|
|
||||||
messageEncoding MessageEncoding,
|
|
||||||
message string,
|
|
||||||
tree *Tree,
|
|
||||||
parents ...*Commit,
|
|
||||||
) (oid *Oid, err error)
|
|
||||||
|
|
||||||
// WithSignatureUsing creates a new signed commit from this one using the given signing callback
|
// WithSignatureUsing creates a new signed commit from this one using the given signing callback
|
||||||
func (c *Commit) WithSignatureUsing(f CommitSigningCallback) (*Oid, error) {
|
func (c *Commit) WithSignatureUsing(f CommitSigningCallback) (*Oid, error) {
|
||||||
signature, signatureField, err := f(c.ContentToSign())
|
signature, signatureField, err := f(c.ContentToSign())
|
||||||
|
|
|
@ -230,27 +230,7 @@ func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("invalid submodule visitor callback")
|
panic("invalid submodule visitor callback")
|
||||||
}
|
}
|
||||||
err := callback(sub, C.GoString(name))
|
return (C.int)(callback(sub, C.GoString(name)))
|
||||||
if err != nil {
|
|
||||||
return C.int(ErrorCodeUser)
|
|
||||||
}
|
|
||||||
return C.int(ErrorCodeOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
// reference.go
|
|
||||||
|
|
||||||
// Deprecated: ReferenceIsValidName is a deprecated alias of ReferenceNameIsValid.
|
|
||||||
func ReferenceIsValidName(name string) bool {
|
|
||||||
valid, _ := ReferenceNameIsValid(name)
|
|
||||||
return valid
|
|
||||||
}
|
|
||||||
|
|
||||||
// remote.go
|
|
||||||
|
|
||||||
// Deprecated: RemoteIsValidName is a deprecated alias of RemoteNameIsValid.
|
|
||||||
func RemoteIsValidName(name string) bool {
|
|
||||||
valid, _ := RemoteNameIsValid(name)
|
|
||||||
return valid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tree.go
|
// tree.go
|
||||||
|
@ -259,13 +239,9 @@ func RemoteIsValidName(name string) bool {
|
||||||
func CallbackGitTreeWalk(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
func CallbackGitTreeWalk(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer) C.int {
|
||||||
root := C.GoString(_root)
|
root := C.GoString(_root)
|
||||||
|
|
||||||
callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback)
|
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
||||||
if !ok {
|
return C.int(callback(root, newTreeEntry(entry)))
|
||||||
|
} else {
|
||||||
panic("invalid treewalk callback")
|
panic("invalid treewalk callback")
|
||||||
}
|
}
|
||||||
err := callback(root, newTreeEntry(entry))
|
|
||||||
if err != nil {
|
|
||||||
return C.int(ErrorCodeUser)
|
|
||||||
}
|
|
||||||
return C.int(ErrorCodeOK)
|
|
||||||
}
|
}
|
||||||
|
|
4
git.go
4
git.go
|
@ -171,7 +171,7 @@ func initLibGit2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown frees all the resources acquired by libgit2. Make sure no
|
// Shutdown frees all the resources acquired by libgit2. Make sure no
|
||||||
// references to any libgit2 go objects are live before calling this.
|
// references to any git2go objects are live before calling this.
|
||||||
// After this is called, invoking any function from this library will result in
|
// After this is called, invoking any function from this library will result in
|
||||||
// undefined behavior, so make sure this is called carefully.
|
// undefined behavior, so make sure this is called carefully.
|
||||||
func Shutdown() {
|
func Shutdown() {
|
||||||
|
@ -229,7 +229,7 @@ func NewOid(s string) (*Oid, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(slice) != 20 {
|
if len(slice) != 20 {
|
||||||
return nil, &GitError{"invalid oid", ErrorClassNone, ErrorCodeGeneric}
|
return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric}
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(o[:], slice[:20])
|
copy(o[:], slice[:20])
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
module github.com/libgit2/git2go/v30
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||||
|
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c
|
||||||
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,13 @@
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
|
||||||
|
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k=
|
||||||
|
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso=
|
||||||
|
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
|
||||||
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
27
graph.go
27
graph.go
|
@ -40,30 +40,3 @@ func (repo *Repository) AheadBehind(local, upstream *Oid) (ahead, behind int, er
|
||||||
|
|
||||||
return int(aheadT), int(behindT), nil
|
return int(aheadT), int(behindT), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReachableFromAny returns whether a commit is reachable from any of a list of
|
|
||||||
// commits by following parent edges.
|
|
||||||
func (repo *Repository) ReachableFromAny(commit *Oid, descendants []*Oid) (bool, error) {
|
|
||||||
if len(descendants) == 0 {
|
|
||||||
return false, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
coids := make([]C.git_oid, len(descendants))
|
|
||||||
for i := 0; i < len(descendants); i++ {
|
|
||||||
coids[i] = *descendants[i].toC()
|
|
||||||
}
|
|
||||||
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_graph_reachable_from_any(repo.ptr, commit.toC(), &coids[0], C.size_t(len(descendants)))
|
|
||||||
runtime.KeepAlive(repo)
|
|
||||||
runtime.KeepAlive(commit)
|
|
||||||
runtime.KeepAlive(coids)
|
|
||||||
runtime.KeepAlive(descendants)
|
|
||||||
if ret < 0 {
|
|
||||||
return false, MakeGitError(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (ret > 0), nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
package git
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestReachableFromAny(t *testing.T) {
|
|
||||||
repo, err := OpenRepository("testdata/TestGitRepository.git")
|
|
||||||
checkFatal(t, err)
|
|
||||||
defer repo.Free()
|
|
||||||
|
|
||||||
for name, tc := range map[string]struct {
|
|
||||||
reachable bool
|
|
||||||
commit string
|
|
||||||
descendants []string
|
|
||||||
}{
|
|
||||||
"empty": {
|
|
||||||
reachable: false,
|
|
||||||
commit: "49322bb17d3acc9146f98c97d078513228bbf3c0",
|
|
||||||
},
|
|
||||||
"same": {
|
|
||||||
reachable: true,
|
|
||||||
commit: "49322bb17d3acc9146f98c97d078513228bbf3c0",
|
|
||||||
descendants: []string{"49322bb17d3acc9146f98c97d078513228bbf3c0"},
|
|
||||||
},
|
|
||||||
"unreachable": {
|
|
||||||
reachable: false,
|
|
||||||
commit: "ac7e7e44c1885efb472ad54a78327d66bfc4ecef",
|
|
||||||
descendants: []string{"58be4659bb571194ed4562d04b359d26216f526e"},
|
|
||||||
},
|
|
||||||
"unreachable-reverse": {
|
|
||||||
reachable: false,
|
|
||||||
commit: "58be4659bb571194ed4562d04b359d26216f526e",
|
|
||||||
descendants: []string{"ac7e7e44c1885efb472ad54a78327d66bfc4ecef"},
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
reachable: false,
|
|
||||||
commit: "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1",
|
|
||||||
descendants: []string{
|
|
||||||
"ac7e7e44c1885efb472ad54a78327d66bfc4ecef",
|
|
||||||
"d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",
|
|
||||||
"f73b95671f326616d66b2afb3bdfcdbbce110b44",
|
|
||||||
"d0114ab8ac326bab30e3a657a0397578c5a1af88",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"head": {
|
|
||||||
reachable: false,
|
|
||||||
commit: "49322bb17d3acc9146f98c97d078513228bbf3c0",
|
|
||||||
descendants: []string{
|
|
||||||
"ac7e7e44c1885efb472ad54a78327d66bfc4ecef",
|
|
||||||
"d86a2aada2f5e7ccf6f11880bfb9ab404e8a8864",
|
|
||||||
"f73b95671f326616d66b2afb3bdfcdbbce110b44",
|
|
||||||
"d0114ab8ac326bab30e3a657a0397578c5a1af88",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
tc := tc
|
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
commit, err := NewOid(tc.commit)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
descendants := make([]*Oid, len(tc.descendants))
|
|
||||||
for i, o := range tc.descendants {
|
|
||||||
descendants[i], err = NewOid(o)
|
|
||||||
checkFatal(t, err)
|
|
||||||
}
|
|
||||||
reachable, err := repo.ReachableFromAny(commit, descendants)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
if reachable != tc.reachable {
|
|
||||||
t.Errorf("ReachableFromAny(%s, %v) = %v, wanted %v", tc.commit, tc.descendants, reachable, tc.reachable)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
12
http.go
12
http.go
|
@ -38,17 +38,17 @@ func registerManagedHTTP() error {
|
||||||
|
|
||||||
func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSubtransport, error) {
|
func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSubtransport, error) {
|
||||||
var proxyFn func(*http.Request) (*url.URL, error)
|
var proxyFn func(*http.Request) (*url.URL, error)
|
||||||
remoteConnectOpts, err := transport.SmartRemoteConnectOptions()
|
proxyOpts, err := transport.SmartProxyOptions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
switch remoteConnectOpts.ProxyOptions.Type {
|
switch proxyOpts.Type {
|
||||||
case ProxyTypeNone:
|
case ProxyTypeNone:
|
||||||
proxyFn = nil
|
proxyFn = nil
|
||||||
case ProxyTypeAuto:
|
case ProxyTypeAuto:
|
||||||
proxyFn = http.ProxyFromEnvironment
|
proxyFn = http.ProxyFromEnvironment
|
||||||
case ProxyTypeSpecified:
|
case ProxyTypeSpecified:
|
||||||
parsedUrl, err := url.Parse(remoteConnectOpts.ProxyOptions.Url)
|
parsedUrl, err := url.Parse(proxyOpts.Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ func (t *httpSmartSubtransport) Action(url string, action SmartServiceAction) (S
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("User-Agent", "git/2.0 (libgit2)")
|
req.Header.Set("User-Agent", "git/2.0 (git2go)")
|
||||||
|
|
||||||
stream := newManagedHttpStream(t, req)
|
stream := newManagedHttpStream(t, req)
|
||||||
if req.Method == "POST" {
|
if req.Method == "POST" {
|
||||||
|
@ -203,9 +203,7 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
|
||||||
req.ContentLength = -1
|
req.ContentLength = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if userName != "" && password != "" {
|
req.SetBasicAuth(userName, password)
|
||||||
req.SetBasicAuth(userName, password)
|
|
||||||
}
|
|
||||||
resp, err = http.DefaultClient.Do(req)
|
resp, err = http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
9
index.go
9
index.go
|
@ -10,12 +10,13 @@ extern int _go_git_index_remove_all(git_index*, const git_strarray*, void*);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexMatchedPathCallback func(string, string) error
|
type IndexMatchedPathCallback func(string, string) int
|
||||||
type indexMatchedPathCallbackData struct {
|
type indexMatchedPathCallbackData struct {
|
||||||
callback IndexMatchedPathCallback
|
callback IndexMatchedPathCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -342,9 +343,9 @@ func indexMatchedPathCallback(cPath, cMatchedPathspec *C.char, payload unsafe.Po
|
||||||
panic("invalid matched path callback")
|
panic("invalid matched path callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callback(C.GoString(cPath), C.GoString(cMatchedPathspec))
|
ret := data.callback(C.GoString(cPath), C.GoString(cMatchedPathspec))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,9 +223,9 @@ func TestIndexAddAllCallback(t *testing.T) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
cbPath := ""
|
cbPath := ""
|
||||||
err = idx.AddAll([]string{}, IndexAddDefault, func(p, mP string) error {
|
err = idx.AddAll([]string{}, IndexAddDefault, func(p, mP string) int {
|
||||||
cbPath = p
|
cbPath = p
|
||||||
return nil
|
return 0
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
if cbPath != "README" {
|
if cbPath != "README" {
|
||||||
|
|
|
@ -33,9 +33,9 @@ func TestIndexerOutOfOrder(t *testing.T) {
|
||||||
defer os.RemoveAll(tmpPath)
|
defer os.RemoveAll(tmpPath)
|
||||||
|
|
||||||
var finalStats TransferProgress
|
var finalStats TransferProgress
|
||||||
idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) error {
|
idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) ErrorCode {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return nil
|
return ErrorCodeOK
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer idx.Free()
|
defer idx.Free()
|
||||||
|
|
2
merge.go
2
merge.go
|
@ -138,6 +138,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type MergeOptions struct {
|
type MergeOptions struct {
|
||||||
|
Version uint
|
||||||
TreeFlags MergeTreeFlag
|
TreeFlags MergeTreeFlag
|
||||||
|
|
||||||
RenameThreshold uint
|
RenameThreshold uint
|
||||||
|
@ -150,6 +151,7 @@ type MergeOptions struct {
|
||||||
|
|
||||||
func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions {
|
func mergeOptionsFromC(opts *C.git_merge_options) MergeOptions {
|
||||||
return MergeOptions{
|
return MergeOptions{
|
||||||
|
Version: uint(opts.version),
|
||||||
TreeFlags: MergeTreeFlag(opts.flags),
|
TreeFlags: MergeTreeFlag(opts.flags),
|
||||||
RenameThreshold: uint(opts.rename_threshold),
|
RenameThreshold: uint(opts.rename_threshold),
|
||||||
TargetLimit: uint(opts.target_limit),
|
TargetLimit: uint(opts.target_limit),
|
||||||
|
|
26
odb.go
26
odb.go
|
@ -176,32 +176,6 @@ func (v *Odb) Read(oid *Oid) (obj *OdbObject, err error) {
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (odb *Odb) Refresh() error {
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_odb_refresh(odb.ptr)
|
|
||||||
runtime.KeepAlive(odb)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (odb *Odb) WriteMultiPackIndex() error {
|
|
||||||
runtime.LockOSThread()
|
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
ret := C.git_odb_write_multi_pack_index(odb.ptr)
|
|
||||||
runtime.KeepAlive(odb)
|
|
||||||
if ret < 0 {
|
|
||||||
return MakeGitError(ret)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type OdbForEachCallback func(id *Oid) error
|
type OdbForEachCallback func(id *Oid) error
|
||||||
type odbForEachCallbackData struct {
|
type odbForEachCallbackData struct {
|
||||||
callback OdbForEachCallback
|
callback OdbForEachCallback
|
||||||
|
|
|
@ -167,9 +167,9 @@ func TestOdbWritepack(t *testing.T) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
var finalStats TransferProgress
|
var finalStats TransferProgress
|
||||||
writepack, err := odb.NewWritePack(func(stats TransferProgress) error {
|
writepack, err := odb.NewWritePack(func(stats TransferProgress) ErrorCode {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return nil
|
return ErrorCodeOK
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer writepack.Free()
|
defer writepack.Free()
|
||||||
|
|
149
rebase.go
149
rebase.go
|
@ -9,7 +9,6 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -72,140 +71,76 @@ func newRebaseOperationFromC(c *C.git_rebase_operation) *RebaseOperation {
|
||||||
return operation
|
return operation
|
||||||
}
|
}
|
||||||
|
|
||||||
//export commitCreateCallback
|
//export commitSigningCallback
|
||||||
func commitCreateCallback(
|
func commitSigningCallback(errorMessage **C.char, _signature *C.git_buf, _signature_field *C.git_buf, _commit_content *C.char, handle unsafe.Pointer) C.int {
|
||||||
errorMessage **C.char,
|
|
||||||
_out *C.git_oid,
|
|
||||||
_author, _committer *C.git_signature,
|
|
||||||
_message_encoding, _message *C.char,
|
|
||||||
_tree *C.git_tree,
|
|
||||||
_parent_count C.size_t,
|
|
||||||
_parents **C.git_commit,
|
|
||||||
handle unsafe.Pointer,
|
|
||||||
) C.int {
|
|
||||||
data, ok := pointerHandles.Get(handle).(*rebaseOptionsData)
|
data, ok := pointerHandles.Get(handle).(*rebaseOptionsData)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("invalid sign payload")
|
panic("invalid sign payload")
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.options.CommitCreateCallback == nil && data.options.CommitSigningCallback == nil {
|
if data.options.CommitSigningCallback == nil {
|
||||||
return C.int(ErrorCodePassthrough)
|
return C.int(ErrorCodePassthrough)
|
||||||
}
|
}
|
||||||
|
|
||||||
messageEncoding := MessageEncodingUTF8
|
commitContent := C.GoString(_commit_content)
|
||||||
if _message_encoding != nil {
|
|
||||||
messageEncoding = MessageEncoding(C.GoString(_message_encoding))
|
|
||||||
}
|
|
||||||
tree := &Tree{
|
|
||||||
Object: Object{
|
|
||||||
ptr: (*C.git_object)(_tree),
|
|
||||||
repo: data.repo,
|
|
||||||
},
|
|
||||||
cast_ptr: _tree,
|
|
||||||
}
|
|
||||||
|
|
||||||
var goParents []*C.git_commit
|
signature, signatureField, err := data.options.CommitSigningCallback(commitContent)
|
||||||
if _parent_count > 0 {
|
if err != nil {
|
||||||
hdr := reflect.SliceHeader{
|
if data.errorTarget != nil {
|
||||||
Data: uintptr(unsafe.Pointer(_parents)),
|
*data.errorTarget = err
|
||||||
Len: int(_parent_count),
|
|
||||||
Cap: int(_parent_count),
|
|
||||||
}
|
}
|
||||||
goParents = *(*[]*C.git_commit)(unsafe.Pointer(&hdr))
|
return setCallbackError(errorMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
parents := make([]*Commit, int(_parent_count))
|
fillBuf := func(bufData string, buf *C.git_buf) error {
|
||||||
for i, p := range goParents {
|
clen := C.size_t(len(bufData))
|
||||||
parents[i] = &Commit{
|
cstr := unsafe.Pointer(C.CString(bufData))
|
||||||
Object: Object{
|
defer C.free(cstr)
|
||||||
ptr: (*C.git_object)(p),
|
|
||||||
repo: data.repo,
|
// libgit2 requires the contents of the buffer to be NULL-terminated.
|
||||||
},
|
// C.CString() guarantees that the returned buffer will be
|
||||||
cast_ptr: p,
|
// NULL-terminated, so we can safely copy the terminator.
|
||||||
|
if int(C.git_buf_set(buf, cstr, clen+1)) != 0 {
|
||||||
|
return errors.New("could not set buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.options.CommitCreateCallback != nil {
|
if signatureField != "" {
|
||||||
oid, err := data.options.CommitCreateCallback(
|
err := fillBuf(signatureField, _signature_field)
|
||||||
newSignatureFromC(_author),
|
|
||||||
newSignatureFromC(_committer),
|
|
||||||
messageEncoding,
|
|
||||||
C.GoString(_message),
|
|
||||||
tree,
|
|
||||||
parents...,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
if data.errorTarget != nil {
|
|
||||||
*data.errorTarget = err
|
|
||||||
}
|
|
||||||
return setCallbackError(errorMessage, err)
|
|
||||||
}
|
|
||||||
if oid == nil {
|
|
||||||
return C.int(ErrorCodePassthrough)
|
|
||||||
}
|
|
||||||
*_out = *oid.toC()
|
|
||||||
} else if data.options.CommitSigningCallback != nil {
|
|
||||||
commitContent, err := data.repo.CreateCommitBuffer(
|
|
||||||
newSignatureFromC(_author),
|
|
||||||
newSignatureFromC(_committer),
|
|
||||||
messageEncoding,
|
|
||||||
C.GoString(_message),
|
|
||||||
tree,
|
|
||||||
parents...,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
return setCallbackError(errorMessage, err)
|
return setCallbackError(errorMessage, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
signature, signatureField, err := data.options.CommitSigningCallback(string(commitContent))
|
err = fillBuf(signature, _signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
|
||||||
return setCallbackError(errorMessage, err)
|
|
||||||
}
|
}
|
||||||
|
return setCallbackError(errorMessage, err)
|
||||||
oid, err := data.repo.CreateCommitWithSignature(string(commitContent), signature, signatureField)
|
|
||||||
if err != nil {
|
|
||||||
if data.errorTarget != nil {
|
|
||||||
*data.errorTarget = err
|
|
||||||
}
|
|
||||||
return setCallbackError(errorMessage, err)
|
|
||||||
}
|
|
||||||
*_out = *oid.toC()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebaseOptions are used to tell the rebase machinery how to operate.
|
// RebaseOptions are used to tell the rebase machinery how to operate
|
||||||
type RebaseOptions struct {
|
type RebaseOptions struct {
|
||||||
Quiet int
|
Version uint
|
||||||
InMemory int
|
Quiet int
|
||||||
RewriteNotesRef string
|
InMemory int
|
||||||
MergeOptions MergeOptions
|
RewriteNotesRef string
|
||||||
CheckoutOptions CheckoutOptions
|
MergeOptions MergeOptions
|
||||||
// CommitCreateCallback is an optional callback that allows users to override
|
CheckoutOptions CheckoutOptions
|
||||||
// commit creation when rebasing. If specified, users can create
|
|
||||||
// their own commit and provide the commit ID, which may be useful for
|
|
||||||
// signing commits or otherwise customizing the commit creation. If this
|
|
||||||
// callback returns a nil Oid, then the rebase will continue to create the
|
|
||||||
// commit.
|
|
||||||
CommitCreateCallback CommitCreateCallback
|
|
||||||
// Deprecated: CommitSigningCallback is an optional callback that will be
|
|
||||||
// called with the commit content, allowing a signature to be added to the
|
|
||||||
// rebase commit. This field is only used when rebasing. This callback is
|
|
||||||
// not invoked if a CommitCreateCallback is specified. CommitCreateCallback
|
|
||||||
// should be used instead of this.
|
|
||||||
CommitSigningCallback CommitSigningCallback
|
CommitSigningCallback CommitSigningCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
type rebaseOptionsData struct {
|
type rebaseOptionsData struct {
|
||||||
options *RebaseOptions
|
options *RebaseOptions
|
||||||
repo *Repository
|
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +160,7 @@ func DefaultRebaseOptions() (RebaseOptions, error) {
|
||||||
|
|
||||||
func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
|
func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
|
||||||
return RebaseOptions{
|
return RebaseOptions{
|
||||||
|
Version: uint(opts.version),
|
||||||
Quiet: int(opts.quiet),
|
Quiet: int(opts.quiet),
|
||||||
InMemory: int(opts.inmemory),
|
InMemory: int(opts.inmemory),
|
||||||
RewriteNotesRef: C.GoString(opts.rewrite_notes_ref),
|
RewriteNotesRef: C.GoString(opts.rewrite_notes_ref),
|
||||||
|
@ -233,7 +169,7 @@ func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, repo *Repository, errorTarget *error) *C.git_rebase_options {
|
func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, errorTarget *error) *C.git_rebase_options {
|
||||||
C.git_rebase_options_init(copts, C.GIT_REBASE_OPTIONS_VERSION)
|
C.git_rebase_options_init(copts, C.GIT_REBASE_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -245,10 +181,9 @@ func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, rep
|
||||||
populateMergeOptions(&copts.merge_options, &opts.MergeOptions)
|
populateMergeOptions(&copts.merge_options, &opts.MergeOptions)
|
||||||
populateCheckoutOptions(&copts.checkout_options, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_options, &opts.CheckoutOptions, errorTarget)
|
||||||
|
|
||||||
if opts.CommitCreateCallback != nil || opts.CommitSigningCallback != nil {
|
if opts.CommitSigningCallback != nil {
|
||||||
data := &rebaseOptionsData{
|
data := &rebaseOptionsData{
|
||||||
options: opts,
|
options: opts,
|
||||||
repo: repo,
|
|
||||||
errorTarget: errorTarget,
|
errorTarget: errorTarget,
|
||||||
}
|
}
|
||||||
C._go_git_populate_rebase_callbacks(copts)
|
C._go_git_populate_rebase_callbacks(copts)
|
||||||
|
@ -304,7 +239,7 @@ func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedComm
|
||||||
|
|
||||||
var ptr *C.git_rebase
|
var ptr *C.git_rebase
|
||||||
var err error
|
var err error
|
||||||
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, r, &err)
|
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, &err)
|
||||||
ret := C.git_rebase_init(&ptr, r.ptr, branch.ptr, upstream.ptr, onto.ptr, cOpts)
|
ret := C.git_rebase_init(&ptr, r.ptr, branch.ptr, upstream.ptr, onto.ptr, cOpts)
|
||||||
runtime.KeepAlive(branch)
|
runtime.KeepAlive(branch)
|
||||||
runtime.KeepAlive(upstream)
|
runtime.KeepAlive(upstream)
|
||||||
|
@ -328,7 +263,7 @@ func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
|
||||||
|
|
||||||
var ptr *C.git_rebase
|
var ptr *C.git_rebase
|
||||||
var err error
|
var err error
|
||||||
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, r, &err)
|
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, &err)
|
||||||
ret := C.git_rebase_open(&ptr, r.ptr, cOpts)
|
ret := C.git_rebase_open(&ptr, r.ptr, cOpts)
|
||||||
runtime.KeepAlive(r)
|
runtime.KeepAlive(r)
|
||||||
if ret == C.int(ErrorCodeUser) && err != nil {
|
if ret == C.int(ErrorCodeUser) && err != nil {
|
||||||
|
@ -479,7 +414,7 @@ func (r *Rebase) Free() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRebaseFromC(ptr *C.git_rebase, repo *Repository, opts *C.git_rebase_options) *Rebase {
|
func newRebaseFromC(ptr *C.git_rebase, repo *Repository, opts *C.git_rebase_options) *Rebase {
|
||||||
rebase := &Rebase{ptr: ptr, r: repo, options: opts}
|
rebase := &Rebase{ptr: ptr, r: repo, options: opts}
|
||||||
runtime.SetFinalizer(rebase, (*Rebase).Free)
|
runtime.SetFinalizer(rebase, (*Rebase).Free)
|
||||||
return rebase
|
return rebase
|
||||||
}
|
}
|
||||||
|
|
100
rebase_test.go
100
rebase_test.go
|
@ -8,8 +8,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ProtonMail/go-crypto/openpgp"
|
"golang.org/x/crypto/openpgp"
|
||||||
"github.com/ProtonMail/go-crypto/openpgp/packet"
|
"golang.org/x/crypto/openpgp/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
@ -19,73 +19,73 @@ func TestRebaseInMemoryWithConflict(t *testing.T) {
|
||||||
defer cleanupTestRepo(t, repo)
|
defer cleanupTestRepo(t, repo)
|
||||||
seedTestRepo(t, repo)
|
seedTestRepo(t, repo)
|
||||||
|
|
||||||
// Create two branches with common history, where both modify "common-file"
|
// Create two branches with common history, where both modify "common-file"
|
||||||
// in a conflicting way.
|
// in a conflicting way.
|
||||||
_, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{})
|
_, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
checkFatal(t, createBranch(repo, "branch-a"))
|
checkFatal(t, createBranch(repo, "branch-a"))
|
||||||
checkFatal(t, createBranch(repo, "branch-b"))
|
checkFatal(t, createBranch(repo, "branch-b"))
|
||||||
|
|
||||||
checkFatal(t, repo.SetHead("refs/heads/branch-a"))
|
checkFatal(t, repo.SetHead("refs/heads/branch-a"))
|
||||||
_, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{})
|
_, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
checkFatal(t, repo.SetHead("refs/heads/branch-b"))
|
checkFatal(t, repo.SetHead("refs/heads/branch-b"))
|
||||||
_, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{})
|
_, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
branchA, err := repo.LookupBranch("branch-a", BranchLocal)
|
branchA, err := repo.LookupBranch("branch-a", BranchLocal)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
onto, err := repo.AnnotatedCommitFromRef(branchA.Reference)
|
onto, err := repo.AnnotatedCommitFromRef(branchA.Reference)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
// We then rebase "branch-b" onto "branch-a" in-memory, which should result
|
||||||
|
// in a conflict.
|
||||||
|
rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
_, err = rebase.Next()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
// We then rebase "branch-b" onto "branch-a" in-memory, which should result
|
index, err := rebase.InmemoryIndex()
|
||||||
// in a conflict.
|
|
||||||
rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1})
|
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
_, err = rebase.Next()
|
// We simply resolve the conflict and commit the rebase.
|
||||||
checkFatal(t, err)
|
if !index.HasConflicts() {
|
||||||
|
t.Fatal("expected index to have conflicts")
|
||||||
|
}
|
||||||
|
|
||||||
index, err := rebase.InmemoryIndex()
|
conflict, err := index.Conflict("common-file")
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
// We simply resolve the conflict and commit the rebase.
|
resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents"))
|
||||||
if !index.HasConflicts() {
|
checkFatal(t, err)
|
||||||
t.Fatal("expected index to have conflicts")
|
|
||||||
}
|
|
||||||
|
|
||||||
conflict, err := index.Conflict("common-file")
|
resolvedEntry := *conflict.Our
|
||||||
checkFatal(t, err)
|
resolvedEntry.Id = resolvedBlobID
|
||||||
|
checkFatal(t, index.Add(&resolvedEntry))
|
||||||
|
checkFatal(t, index.RemoveConflict("common-file"))
|
||||||
|
|
||||||
resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents"))
|
var commitID Oid
|
||||||
checkFatal(t, err)
|
checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message"))
|
||||||
|
checkFatal(t, rebase.Finish())
|
||||||
|
|
||||||
resolvedEntry := *conflict.Our
|
// And then assert that we can look up the new merge commit, and that the
|
||||||
resolvedEntry.Id = resolvedBlobID
|
// "common-file" has the expected contents.
|
||||||
checkFatal(t, index.Add(&resolvedEntry))
|
commit, err := repo.LookupCommit(&commitID)
|
||||||
checkFatal(t, index.RemoveConflict("common-file"))
|
checkFatal(t, err)
|
||||||
|
if commit.Message() != "rebased message" {
|
||||||
|
t.Fatalf("unexpected commit message %q", commit.Message())
|
||||||
|
}
|
||||||
|
|
||||||
var commitID Oid
|
tree, err := commit.Tree()
|
||||||
checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message"))
|
checkFatal(t, err)
|
||||||
checkFatal(t, rebase.Finish())
|
|
||||||
|
|
||||||
// And then assert that we can look up the new merge commit, and that the
|
blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id)
|
||||||
// "common-file" has the expected contents.
|
checkFatal(t, err)
|
||||||
commit, err := repo.LookupCommit(&commitID)
|
if string(blob.Contents()) != "resolved contents" {
|
||||||
checkFatal(t, err)
|
t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents()))
|
||||||
if commit.Message() != "rebased message" {
|
}
|
||||||
t.Fatalf("unexpected commit message %q", commit.Message())
|
|
||||||
}
|
|
||||||
|
|
||||||
tree, err := commit.Tree()
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id)
|
|
||||||
checkFatal(t, err)
|
|
||||||
if string(blob.Contents()) != "resolved contents" {
|
|
||||||
t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents()))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRebaseAbort(t *testing.T) {
|
func TestRebaseAbort(t *testing.T) {
|
||||||
|
@ -319,7 +319,7 @@ func checkCommitSigned(t *testing.T, entity *openpgp.Entity, commit *Commit) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature), nil)
|
_, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign())
|
t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign())
|
||||||
return err
|
return err
|
||||||
|
|
14
reference.go
14
reference.go
|
@ -476,7 +476,7 @@ func (v *ReferenceIterator) Free() {
|
||||||
C.git_reference_iterator_free(v.ptr)
|
C.git_reference_iterator_free(v.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReferenceNameIsValid returns whether the reference name is well-formed.
|
// ReferenceIsValidName returns whether the reference name is well-formed.
|
||||||
//
|
//
|
||||||
// Valid reference names must follow one of two patterns:
|
// Valid reference names must follow one of two patterns:
|
||||||
//
|
//
|
||||||
|
@ -486,19 +486,11 @@ func (v *ReferenceIterator) Free() {
|
||||||
// 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
// 2. Names prefixed with "refs/" can be almost anything. You must avoid
|
||||||
// the characters '~', '^', ':', ' \ ', '?', '[', and '*', and the sequences
|
// the characters '~', '^', ':', ' \ ', '?', '[', and '*', and the sequences
|
||||||
// ".." and " @ {" which have special meaning to revparse.
|
// ".." and " @ {" which have special meaning to revparse.
|
||||||
func ReferenceNameIsValid(name string) (bool, error) {
|
func ReferenceIsValidName(name string) bool {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
return C.git_reference_is_valid_name(cname) == 1
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
var valid C.int
|
|
||||||
ret := C.git_reference_name_is_valid(&valid, cname)
|
|
||||||
if ret < 0 {
|
|
||||||
return false, MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return valid == 1, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -214,16 +214,12 @@ func TestIsNote(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReferenceNameIsValid(t *testing.T) {
|
func TestReferenceIsValidName(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
valid, err := ReferenceNameIsValid("HEAD")
|
if !ReferenceIsValidName("HEAD") {
|
||||||
checkFatal(t, err)
|
|
||||||
if !valid {
|
|
||||||
t.Errorf("HEAD should be a valid reference name")
|
t.Errorf("HEAD should be a valid reference name")
|
||||||
}
|
}
|
||||||
valid, err = ReferenceNameIsValid("HEAD1")
|
if ReferenceIsValidName("HEAD1") {
|
||||||
checkFatal(t, err)
|
|
||||||
if valid {
|
|
||||||
t.Errorf("HEAD1 should not be a valid reference name")
|
t.Errorf("HEAD1 should not be a valid reference name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
116
remote.go
116
remote.go
|
@ -12,7 +12,6 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -70,15 +69,15 @@ const (
|
||||||
ConnectDirectionPush ConnectDirection = C.GIT_DIRECTION_PUSH
|
ConnectDirectionPush ConnectDirection = C.GIT_DIRECTION_PUSH
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransportMessageCallback func(str string) error
|
type TransportMessageCallback func(str string) ErrorCode
|
||||||
type CompletionCallback func(RemoteCompletion) error
|
type CompletionCallback func(RemoteCompletion) ErrorCode
|
||||||
type CredentialsCallback func(url string, username_from_url string, allowed_types CredentialType) (*Credential, error)
|
type CredentialsCallback func(url string, username_from_url string, allowed_types CredentialType) (*Credential, error)
|
||||||
type TransferProgressCallback func(stats TransferProgress) error
|
type TransferProgressCallback func(stats TransferProgress) ErrorCode
|
||||||
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) error
|
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
|
||||||
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) error
|
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
|
||||||
type PackbuilderProgressCallback func(stage int32, current, total uint32) error
|
type PackbuilderProgressCallback func(stage int32, current, total uint32) ErrorCode
|
||||||
type PushTransferProgressCallback func(current, total uint32, bytes uint) error
|
type PushTransferProgressCallback func(current, total uint32, bytes uint) ErrorCode
|
||||||
type PushUpdateReferenceCallback func(refname, status string) error
|
type PushUpdateReferenceCallback func(refname, status string) ErrorCode
|
||||||
|
|
||||||
type RemoteCallbacks struct {
|
type RemoteCallbacks struct {
|
||||||
SidebandProgressCallback TransportMessageCallback
|
SidebandProgressCallback TransportMessageCallback
|
||||||
|
@ -147,17 +146,6 @@ type FetchOptions struct {
|
||||||
ProxyOptions ProxyOptions
|
ProxyOptions ProxyOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteConnectOptions struct {
|
|
||||||
// Proxy options to use for this fetch operation
|
|
||||||
ProxyOptions ProxyOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
func remoteConnectOptionsFromC(copts *C.git_remote_connect_options) *RemoteConnectOptions {
|
|
||||||
return &RemoteConnectOptions{
|
|
||||||
ProxyOptions: proxyOptionsFromC(&copts.proxy_opts),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProxyType uint
|
type ProxyType uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -182,8 +170,8 @@ type ProxyOptions struct {
|
||||||
Url string
|
Url string
|
||||||
}
|
}
|
||||||
|
|
||||||
func proxyOptionsFromC(copts *C.git_proxy_options) ProxyOptions {
|
func proxyOptionsFromC(copts *C.git_proxy_options) *ProxyOptions {
|
||||||
return ProxyOptions{
|
return &ProxyOptions{
|
||||||
Type: ProxyType(copts._type),
|
Type: ProxyType(copts._type),
|
||||||
Url: C.GoString(copts.url),
|
Url: C.GoString(copts.url),
|
||||||
}
|
}
|
||||||
|
@ -267,7 +255,7 @@ const (
|
||||||
// Certificate represents the two possible certificates which libgit2
|
// Certificate represents the two possible certificates which libgit2
|
||||||
// knows it might find. If Kind is CertficateX509 then the X509 field
|
// knows it might find. If Kind is CertficateX509 then the X509 field
|
||||||
// will be filled. If Kind is CertificateHostkey then the Hostkey
|
// will be filled. If Kind is CertificateHostkey then the Hostkey
|
||||||
// field will be filled.
|
// field will be fille.d
|
||||||
type Certificate struct {
|
type Certificate struct {
|
||||||
Kind CertificateKind
|
Kind CertificateKind
|
||||||
X509 *x509.Certificate
|
X509 *x509.Certificate
|
||||||
|
@ -281,7 +269,7 @@ const (
|
||||||
HostkeyMD5 HostkeyKind = C.GIT_CERT_SSH_MD5
|
HostkeyMD5 HostkeyKind = C.GIT_CERT_SSH_MD5
|
||||||
HostkeySHA1 HostkeyKind = C.GIT_CERT_SSH_SHA1
|
HostkeySHA1 HostkeyKind = C.GIT_CERT_SSH_SHA1
|
||||||
HostkeySHA256 HostkeyKind = C.GIT_CERT_SSH_SHA256
|
HostkeySHA256 HostkeyKind = C.GIT_CERT_SSH_SHA256
|
||||||
HostkeyRaw HostkeyKind = C.GIT_CERT_SSH_RAW
|
HostkeyRaw HostkeyKind = 1 << 3
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server host key information. A bitmask containing the available fields.
|
// Server host key information. A bitmask containing the available fields.
|
||||||
|
@ -347,8 +335,10 @@ func sidebandProgressCallback(errorMessage **C.char, _str *C.char, _len C.int, h
|
||||||
if data.callbacks.SidebandProgressCallback == nil {
|
if data.callbacks.SidebandProgressCallback == nil {
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
err := data.callbacks.SidebandProgressCallback(C.GoStringN(_str, _len))
|
str := C.GoStringN(_str, _len)
|
||||||
if err != nil {
|
ret := data.callbacks.SidebandProgressCallback(str)
|
||||||
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -358,13 +348,14 @@ func sidebandProgressCallback(errorMessage **C.char, _str *C.char, _len C.int, h
|
||||||
}
|
}
|
||||||
|
|
||||||
//export completionCallback
|
//export completionCallback
|
||||||
func completionCallback(errorMessage **C.char, completionType C.git_remote_completion_type, handle unsafe.Pointer) C.int {
|
func completionCallback(errorMessage **C.char, completion_type C.git_remote_completion_type, handle unsafe.Pointer) C.int {
|
||||||
data := pointerHandles.Get(handle).(*remoteCallbacksData)
|
data := pointerHandles.Get(handle).(*remoteCallbacksData)
|
||||||
if data.callbacks.CompletionCallback == nil {
|
if data.callbacks.CompletionCallback == nil {
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
err := data.callbacks.CompletionCallback(RemoteCompletion(completionType))
|
ret := data.callbacks.CompletionCallback(RemoteCompletion(completion_type))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -411,8 +402,9 @@ func transferProgressCallback(errorMessage **C.char, stats *C.git_transfer_progr
|
||||||
if data.callbacks.TransferProgressCallback == nil {
|
if data.callbacks.TransferProgressCallback == nil {
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
err := data.callbacks.TransferProgressCallback(newTransferProgressFromC(stats))
|
ret := data.callbacks.TransferProgressCallback(newTransferProgressFromC(stats))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -436,8 +428,9 @@ func updateTipsCallback(
|
||||||
refname := C.GoString(_refname)
|
refname := C.GoString(_refname)
|
||||||
a := newOidFromC(_a)
|
a := newOidFromC(_a)
|
||||||
b := newOidFromC(_b)
|
b := newOidFromC(_b)
|
||||||
err := data.callbacks.UpdateTipsCallback(refname, a, b)
|
ret := data.callbacks.UpdateTipsCallback(refname, a, b)
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -494,17 +487,6 @@ func certificateCheckCallback(
|
||||||
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashMD5[0]), unsafe.Pointer(&ccert.hash_md5[0]), C.size_t(len(cert.Hostkey.HashMD5)))
|
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashMD5[0]), unsafe.Pointer(&ccert.hash_md5[0]), C.size_t(len(cert.Hostkey.HashMD5)))
|
||||||
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA1[0]), unsafe.Pointer(&ccert.hash_sha1[0]), C.size_t(len(cert.Hostkey.HashSHA1)))
|
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA1[0]), unsafe.Pointer(&ccert.hash_sha1[0]), C.size_t(len(cert.Hostkey.HashSHA1)))
|
||||||
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), unsafe.Pointer(&ccert.hash_sha256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
C.memcpy(unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), unsafe.Pointer(&ccert.hash_sha256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
||||||
if (cert.Hostkey.Kind & HostkeyRaw) == HostkeyRaw {
|
|
||||||
cert.Hostkey.Hostkey = C.GoBytes(unsafe.Pointer(ccert.hostkey), C.int(ccert.hostkey_len))
|
|
||||||
var err error
|
|
||||||
cert.Hostkey.SSHPublicKey, err = ssh.ParsePublicKey(cert.Hostkey.Hostkey)
|
|
||||||
if err != nil {
|
|
||||||
if data.errorTarget != nil {
|
|
||||||
*data.errorTarget = err
|
|
||||||
}
|
|
||||||
return setCallbackError(errorMessage, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
err := errors.New("unsupported certificate type")
|
err := errors.New("unsupported certificate type")
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
|
@ -513,8 +495,9 @@ func certificateCheckCallback(
|
||||||
return setCallbackError(errorMessage, err)
|
return setCallbackError(errorMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callbacks.CertificateCheckCallback(&cert, valid, host)
|
ret := data.callbacks.CertificateCheckCallback(&cert, valid, host)
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -530,8 +513,9 @@ func packProgressCallback(errorMessage **C.char, stage C.int, current, total C.u
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callbacks.PackProgressCallback(int32(stage), uint32(current), uint32(total))
|
ret := data.callbacks.PackProgressCallback(int32(stage), uint32(current), uint32(total))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -547,8 +531,9 @@ func pushTransferProgressCallback(errorMessage **C.char, current, total C.uint,
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callbacks.PushTransferProgressCallback(uint32(current), uint32(total), uint(bytes))
|
ret := data.callbacks.PushTransferProgressCallback(uint32(current), uint32(total), uint(bytes))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -564,8 +549,9 @@ func pushUpdateReferenceCallback(errorMessage **C.char, refname, status *C.char,
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callbacks.PushUpdateReferenceCallback(C.GoString(refname), C.GoString(status))
|
ret := data.callbacks.PushUpdateReferenceCallback(C.GoString(refname), C.GoString(status))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
|
err := errors.New(ErrorCode(ret).String())
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -593,20 +579,12 @@ func freeProxyOptions(copts *C.git_proxy_options) {
|
||||||
C.free(unsafe.Pointer(copts.url))
|
C.free(unsafe.Pointer(copts.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteNameIsValid returns whether the remote name is well-formed.
|
// RemoteIsValidName returns whether the remote name is well-formed.
|
||||||
func RemoteNameIsValid(name string) (bool, error) {
|
func RemoteIsValidName(name string) bool {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
runtime.LockOSThread()
|
return C.git_remote_is_valid_name(cname) == 1
|
||||||
defer runtime.UnlockOSThread()
|
|
||||||
|
|
||||||
var valid C.int
|
|
||||||
ret := C.git_remote_name_is_valid(&valid, cname)
|
|
||||||
if ret < 0 {
|
|
||||||
return false, MakeGitError(ret)
|
|
||||||
}
|
|
||||||
return valid == 1, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// free releases the resources of the Remote.
|
// free releases the resources of the Remote.
|
||||||
|
@ -661,7 +639,7 @@ func (c *RemoteCollection) List() ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_dispose(&r)
|
defer C.git_strarray_free(&r)
|
||||||
|
|
||||||
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
||||||
return remotes, nil
|
return remotes, nil
|
||||||
|
@ -686,7 +664,7 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateWithOptions Creates a repository object with extended options.
|
//CreateWithOptions Creates a repository object with extended options.
|
||||||
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
|
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
|
||||||
remote := &Remote{repo: c.repo}
|
remote := &Remote{repo: c.repo}
|
||||||
|
|
||||||
|
@ -931,7 +909,7 @@ func (o *Remote) FetchRefspecs() ([]string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_dispose(&crefspecs)
|
defer C.git_strarray_free(&crefspecs)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
return refspecs, nil
|
return refspecs, nil
|
||||||
|
@ -964,7 +942,7 @@ func (o *Remote) PushRefspecs() ([]string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_dispose(&crefspecs)
|
defer C.git_strarray_free(&crefspecs)
|
||||||
runtime.KeepAlive(o)
|
runtime.KeepAlive(o)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
|
@ -984,9 +962,7 @@ func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorT
|
||||||
}
|
}
|
||||||
populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget)
|
populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget)
|
||||||
copts.prune = C.git_fetch_prune_t(opts.Prune)
|
copts.prune = C.git_fetch_prune_t(opts.Prune)
|
||||||
fmt.Println("populateFetchOptions() is broken. fixme!")
|
copts.update_fetchhead = cbool(opts.UpdateFetchhead)
|
||||||
// fix this line: ./remote.go:988:27: cannot use cbool(opts.UpdateFetchhead) (value of type _Ctype_int) as _Ctype_uint value in assignment
|
|
||||||
// copts.update_fetchhead = cbool(opts.UpdateFetchhead)
|
|
||||||
copts.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
|
copts.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
|
||||||
|
|
||||||
copts.custom_headers = C.git_strarray{
|
copts.custom_headers = C.git_strarray{
|
||||||
|
|
|
@ -38,13 +38,13 @@ func TestListRemotes(t *testing.T) {
|
||||||
compareStringList(t, expected, actual)
|
compareStringList(t, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) error {
|
func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) ErrorCode {
|
||||||
if hostname != "github.com" {
|
if hostname != "github.com" {
|
||||||
t.Fatal("hostname does not match")
|
t.Fatal("Hostname does not match")
|
||||||
return errors.New("hostname does not match")
|
return ErrorCodeUser
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return ErrorCodeOK
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCertificateCheck(t *testing.T) {
|
func TestCertificateCheck(t *testing.T) {
|
||||||
|
@ -58,7 +58,7 @@ func TestCertificateCheck(t *testing.T) {
|
||||||
|
|
||||||
options := FetchOptions{
|
options := FetchOptions{
|
||||||
RemoteCallbacks: RemoteCallbacks{
|
RemoteCallbacks: RemoteCallbacks{
|
||||||
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
|
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
|
||||||
return assertHostname(cert, valid, hostname, t)
|
return assertHostname(cert, valid, hostname, t)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -479,13 +479,14 @@ func TestRemoteSSH(t *testing.T) {
|
||||||
certificateCheckCallbackCalled := false
|
certificateCheckCallbackCalled := false
|
||||||
fetchOpts := FetchOptions{
|
fetchOpts := FetchOptions{
|
||||||
RemoteCallbacks: RemoteCallbacks{
|
RemoteCallbacks: RemoteCallbacks{
|
||||||
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
|
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
|
||||||
hostkeyFingerprint := fmt.Sprintf("%x", cert.Hostkey.HashMD5[:])
|
hostkeyFingerprint := fmt.Sprintf("%x", cert.Hostkey.HashMD5[:])
|
||||||
if hostkeyFingerprint != publicKeyFingerprint {
|
if hostkeyFingerprint != publicKeyFingerprint {
|
||||||
return fmt.Errorf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
|
t.Logf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
|
||||||
|
return ErrorCodeAuth
|
||||||
}
|
}
|
||||||
certificateCheckCallbackCalled = true
|
certificateCheckCallbackCalled = true
|
||||||
return nil
|
return ErrorCodeOK
|
||||||
},
|
},
|
||||||
CredentialsCallback: func(url, username string, allowedTypes CredentialType) (*Credential, error) {
|
CredentialsCallback: func(url, username string, allowedTypes CredentialType) (*Credential, error) {
|
||||||
if allowedTypes&(CredentialTypeSSHKey|CredentialTypeSSHCustom|CredentialTypeSSHMemory) != 0 {
|
if allowedTypes&(CredentialTypeSSHKey|CredentialTypeSSHCustom|CredentialTypeSSHMemory) != 0 {
|
||||||
|
|
16
revert.go
16
revert.go
|
@ -10,9 +10,9 @@ import (
|
||||||
|
|
||||||
// RevertOptions contains options for performing a revert
|
// RevertOptions contains options for performing a revert
|
||||||
type RevertOptions struct {
|
type RevertOptions struct {
|
||||||
Mainline uint
|
Mainline uint
|
||||||
MergeOptions MergeOptions
|
MergeOpts MergeOptions
|
||||||
CheckoutOptions CheckoutOptions
|
CheckoutOpts CheckoutOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, errorTarget *error) *C.git_revert_options {
|
func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, errorTarget *error) *C.git_revert_options {
|
||||||
|
@ -21,16 +21,16 @@ func populateRevertOptions(copts *C.git_revert_options, opts *RevertOptions, err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.mainline = C.uint(opts.Mainline)
|
copts.mainline = C.uint(opts.Mainline)
|
||||||
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
|
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
|
||||||
func revertOptionsFromC(copts *C.git_revert_options) RevertOptions {
|
func revertOptionsFromC(copts *C.git_revert_options) RevertOptions {
|
||||||
return RevertOptions{
|
return RevertOptions{
|
||||||
Mainline: uint(copts.mainline),
|
Mainline: uint(copts.mainline),
|
||||||
MergeOptions: mergeOptionsFromC(&copts.merge_opts),
|
MergeOpts: mergeOptionsFromC(&copts.merge_opts),
|
||||||
CheckoutOptions: checkoutOptionsFromC(&copts.checkout_opts),
|
CheckoutOpts: checkoutOptionsFromC(&copts.checkout_opts),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,11 +60,11 @@ func TestRevertCommit(t *testing.T) {
|
||||||
revertOptions, err := DefaultRevertOptions()
|
revertOptions, err := DefaultRevertOptions()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOptions)
|
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOpts)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer index.Free()
|
defer index.Free()
|
||||||
|
|
||||||
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOptions)
|
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOpts)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
actualReadmeContents := readReadme(t, repo)
|
actualReadmeContents := readReadme(t, repo)
|
||||||
|
|
|
@ -51,11 +51,8 @@ if [ -n "${BUILD_LIBGIT_REF}" ]; then
|
||||||
trap "git submodule update --init" EXIT
|
trap "git submodule update --init" EXIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BUILD_DEPRECATED_HARD="ON"
|
|
||||||
if [ "${BUILD_SYSTEM}" = "ON" ]; then
|
if [ "${BUILD_SYSTEM}" = "ON" ]; then
|
||||||
BUILD_INSTALL_PREFIX=${SYSTEM_INSTALL_PREFIX-"/usr"}
|
BUILD_INSTALL_PREFIX=${SYSTEM_INSTALL_PREFIX-"/usr"}
|
||||||
# Most system-wide installations won't intentionally omit deprecated symbols.
|
|
||||||
BUILD_DEPRECATED_HARD="OFF"
|
|
||||||
else
|
else
|
||||||
BUILD_INSTALL_PREFIX="${BUILD_PATH}/install"
|
BUILD_INSTALL_PREFIX="${BUILD_PATH}/install"
|
||||||
mkdir -p "${BUILD_PATH}/install/lib"
|
mkdir -p "${BUILD_PATH}/install/lib"
|
||||||
|
@ -79,7 +76,6 @@ cmake -DTHREADSAFE=ON \
|
||||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||||
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
||||||
-DCMAKE_INSTALL_LIBDIR="lib" \
|
-DCMAKE_INSTALL_LIBDIR="lib" \
|
||||||
-DDEPRECATE_HARD="${BUILD_DEPRECATE_HARD}" \
|
|
||||||
"${VENDORED_PATH}"
|
"${VENDORED_PATH}"
|
||||||
|
|
||||||
if which make nproc >/dev/null && [ -f Makefile ]; then
|
if which make nproc >/dev/null && [ -f Makefile ]; then
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Install libgit2 to go libgit2 in dynamic mode on Travis
|
# Install libgit2 to git2go in dynamic mode on Travis
|
||||||
#
|
#
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
17
submodule.go
17
submodule.go
|
@ -8,14 +8,15 @@ extern int _go_git_visit_submodule(git_repository *repo, void *fct);
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SubmoduleUpdateOptions
|
// SubmoduleUpdateOptions
|
||||||
type SubmoduleUpdateOptions struct {
|
type SubmoduleUpdateOptions struct {
|
||||||
CheckoutOptions CheckoutOptions
|
*CheckoutOpts
|
||||||
FetchOptions FetchOptions
|
*FetchOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submodule
|
// Submodule
|
||||||
|
@ -110,7 +111,7 @@ func (c *SubmoduleCollection) Lookup(name string) (*Submodule, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmoduleCallback is a function that is called for every submodule found in SubmoduleCollection.Foreach.
|
// SubmoduleCallback is a function that is called for every submodule found in SubmoduleCollection.Foreach.
|
||||||
type SubmoduleCallback func(sub *Submodule, name string) error
|
type SubmoduleCallback func(sub *Submodule, name string) int
|
||||||
type submoduleCallbackData struct {
|
type submoduleCallbackData struct {
|
||||||
callback SubmoduleCallback
|
callback SubmoduleCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -125,9 +126,9 @@ func submoduleCallback(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer)
|
||||||
panic("invalid submodule visitor callback")
|
panic("invalid submodule visitor callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callback(sub, C.GoString(name))
|
ret := data.callback(sub, C.GoString(name))
|
||||||
if err != nil {
|
if ret < 0 {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,8 +391,8 @@ func populateSubmoduleUpdateOptions(copts *C.git_submodule_update_options, opts
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
|
||||||
populateFetchOptions(&copts.fetch_opts, &opts.FetchOptions, errorTarget)
|
populateFetchOptions(&copts.fetch_opts, opts.FetchOptions, errorTarget)
|
||||||
|
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,9 @@ func TestSubmoduleForeach(t *testing.T) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
i := 0
|
i := 0
|
||||||
err = repo.Submodules.Foreach(func(sub *Submodule, name string) error {
|
err = repo.Submodules.Foreach(func(sub *Submodule, name string) int {
|
||||||
i++
|
i++
|
||||||
return nil
|
return 0
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
|
4
tag.go
4
tag.go
|
@ -161,7 +161,7 @@ func (c *TagsCollection) List() ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_dispose(&strC)
|
defer C.git_strarray_free(&strC)
|
||||||
|
|
||||||
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
||||||
return tags, nil
|
return tags, nil
|
||||||
|
@ -185,7 +185,7 @@ func (c *TagsCollection) ListWithMatch(pattern string) ([]string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_strarray_dispose(&strC)
|
defer C.git_strarray_free(&strC)
|
||||||
|
|
||||||
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
||||||
return tags, nil
|
return tags, nil
|
||||||
|
|
26
transport.go
26
transport.go
|
@ -31,7 +31,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// globalRegisteredSmartTransports is a mapping of global, libgit2 go-managed
|
// globalRegisteredSmartTransports is a mapping of global, git2go-managed
|
||||||
// transports.
|
// transports.
|
||||||
globalRegisteredSmartTransports = struct {
|
globalRegisteredSmartTransports = struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
@ -41,7 +41,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// unregisterManagedTransports unregisters all libgit2 go-managed transports.
|
// unregisterManagedTransports unregisters all git2go-managed transports.
|
||||||
func unregisterManagedTransports() error {
|
func unregisterManagedTransports() error {
|
||||||
globalRegisteredSmartTransports.Lock()
|
globalRegisteredSmartTransports.Lock()
|
||||||
originalTransports := globalRegisteredSmartTransports.transports
|
originalTransports := globalRegisteredSmartTransports.transports
|
||||||
|
@ -84,17 +84,17 @@ type Transport struct {
|
||||||
ptr *C.git_transport
|
ptr *C.git_transport
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmartRemoteConnectOptions gets a copy of the proxy options for this transport.
|
// SmartProxyOptions gets a copy of the proxy options for this transport.
|
||||||
func (t *Transport) SmartRemoteConnectOptions() (*RemoteConnectOptions, error) {
|
func (t *Transport) SmartProxyOptions() (*ProxyOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
var copts C.git_remote_connect_options
|
var cpopts C.git_proxy_options
|
||||||
if ret := C.git_transport_remote_connect_options(&copts, t.ptr); ret < 0 {
|
if ret := C.git_transport_smart_proxy_options(&cpopts, t.ptr); ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
return remoteConnectOptionsFromC(&copts), nil
|
return proxyOptionsFromC(&cpopts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmartCredentials calls the credentials callback for this transport.
|
// SmartCredentials calls the credentials callback for this transport.
|
||||||
|
@ -127,21 +127,11 @@ func (t *Transport) SmartCertificateCheck(cert *Certificate, valid bool, hostnam
|
||||||
parent: C.git_cert{
|
parent: C.git_cert{
|
||||||
cert_type: C.GIT_CERT_HOSTKEY_LIBSSH2,
|
cert_type: C.GIT_CERT_HOSTKEY_LIBSSH2,
|
||||||
},
|
},
|
||||||
_type: C.git_cert_ssh_t(cert.Kind),
|
_type: C.git_cert_ssh_t(cert.Kind),
|
||||||
hostkey: (*C.char)(C.CBytes(cert.Hostkey.Hostkey)),
|
|
||||||
hostkey_len: C.size_t(len(cert.Hostkey.Hostkey)),
|
|
||||||
}
|
}
|
||||||
defer C.free(unsafe.Pointer(chostkeyCert.hostkey))
|
|
||||||
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_md5[0]), unsafe.Pointer(&cert.Hostkey.HashMD5[0]), C.size_t(len(cert.Hostkey.HashMD5)))
|
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_md5[0]), unsafe.Pointer(&cert.Hostkey.HashMD5[0]), C.size_t(len(cert.Hostkey.HashMD5)))
|
||||||
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha1[0]), unsafe.Pointer(&cert.Hostkey.HashSHA1[0]), C.size_t(len(cert.Hostkey.HashSHA1)))
|
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha1[0]), unsafe.Pointer(&cert.Hostkey.HashSHA1[0]), C.size_t(len(cert.Hostkey.HashSHA1)))
|
||||||
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha256[0]), unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
C.memcpy(unsafe.Pointer(&chostkeyCert.hash_sha256[0]), unsafe.Pointer(&cert.Hostkey.HashSHA256[0]), C.size_t(len(cert.Hostkey.HashSHA256)))
|
||||||
if cert.Hostkey.SSHPublicKey.Type() == "ssh-rsa" {
|
|
||||||
chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_RSA
|
|
||||||
} else if cert.Hostkey.SSHPublicKey.Type() == "ssh-dss" {
|
|
||||||
chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_DSS
|
|
||||||
} else {
|
|
||||||
chostkeyCert.raw_type = C.GIT_CERT_SSH_RAW_TYPE_UNKNOWN
|
|
||||||
}
|
|
||||||
ccert = (*C.git_cert)(unsafe.Pointer(&chostkeyCert))
|
ccert = (*C.git_cert)(unsafe.Pointer(&chostkeyCert))
|
||||||
|
|
||||||
case CertificateX509:
|
case CertificateX509:
|
||||||
|
|
23
tree.go
23
tree.go
|
@ -121,7 +121,7 @@ func (t *Tree) EntryCount() uint64 {
|
||||||
return uint64(num)
|
return uint64(num)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TreeWalkCallback func(string, *TreeEntry) error
|
type TreeWalkCallback func(string, *TreeEntry) int
|
||||||
type treeWalkCallbackData struct {
|
type treeWalkCallbackData struct {
|
||||||
callback TreeWalkCallback
|
callback TreeWalkCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -134,30 +134,15 @@ func treeWalkCallback(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer
|
||||||
panic("invalid treewalk callback")
|
panic("invalid treewalk callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := data.callback(C.GoString(_root), newTreeEntry(entry))
|
ret := data.callback(C.GoString(_root), newTreeEntry(entry))
|
||||||
if err == TreeWalkSkip {
|
if ret < 0 {
|
||||||
return C.int(1)
|
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
||||||
} else if err != nil {
|
|
||||||
*data.errorTarget = err
|
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TreeWalkSkip is an error that can be returned form TreeWalkCallback to skip
|
|
||||||
// a subtree from being expanded.
|
|
||||||
var TreeWalkSkip = errors.New("skip")
|
|
||||||
|
|
||||||
// Walk traverses the entries in a tree and its subtrees in pre order.
|
|
||||||
//
|
|
||||||
// The entries will be traversed in the pre order, children subtrees will be
|
|
||||||
// automatically loaded as required, and the callback will be called once per
|
|
||||||
// entry with the current (relative) root for the entry and the entry data
|
|
||||||
// itself.
|
|
||||||
//
|
|
||||||
// If the callback returns TreeWalkSkip, the passed entry will be skipped on
|
|
||||||
// the traversal. Any other non-nil error stops the walk.
|
|
||||||
func (t *Tree) Walk(callback TreeWalkCallback) error {
|
func (t *Tree) Walk(callback TreeWalkCallback) error {
|
||||||
var err error
|
var err error
|
||||||
data := treeWalkCallbackData{
|
data := treeWalkCallbackData{
|
||||||
|
|
74
tree_test.go
74
tree_test.go
|
@ -1,9 +1,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"errors"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTreeEntryById(t *testing.T) {
|
func TestTreeEntryById(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -66,72 +63,3 @@ func TestTreeBuilderInsert(t *testing.T) {
|
||||||
t.Fatalf("got oid %v, want %v", entry.Id, blobId)
|
t.Fatalf("got oid %v, want %v", entry.Id, blobId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTreeWalk(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
repo, err := OpenRepository("testdata/TestGitRepository.git")
|
|
||||||
checkFatal(t, err)
|
|
||||||
treeID, err := NewOid("6020a3b8d5d636e549ccbd0c53e2764684bb3125")
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
tree, err := repo.LookupTree(treeID)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
var callCount int
|
|
||||||
err = tree.Walk(func(name string, entry *TreeEntry) error {
|
|
||||||
callCount++
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
checkFatal(t, err)
|
|
||||||
if callCount != 11 {
|
|
||||||
t.Fatalf("got called %v times, want %v", callCount, 11)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTreeWalkSkip(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
repo, err := OpenRepository("testdata/TestGitRepository.git")
|
|
||||||
checkFatal(t, err)
|
|
||||||
treeID, err := NewOid("6020a3b8d5d636e549ccbd0c53e2764684bb3125")
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
tree, err := repo.LookupTree(treeID)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
var callCount int
|
|
||||||
err = tree.Walk(func(name string, entry *TreeEntry) error {
|
|
||||||
callCount++
|
|
||||||
|
|
||||||
return TreeWalkSkip
|
|
||||||
})
|
|
||||||
checkFatal(t, err)
|
|
||||||
if callCount != 4 {
|
|
||||||
t.Fatalf("got called %v times, want %v", callCount, 4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTreeWalkStop(t *testing.T) {
|
|
||||||
t.Parallel()
|
|
||||||
repo, err := OpenRepository("testdata/TestGitRepository.git")
|
|
||||||
checkFatal(t, err)
|
|
||||||
treeID, err := NewOid("6020a3b8d5d636e549ccbd0c53e2764684bb3125")
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
tree, err := repo.LookupTree(treeID)
|
|
||||||
checkFatal(t, err)
|
|
||||||
|
|
||||||
var callCount int
|
|
||||||
stopError := errors.New("stop")
|
|
||||||
err = tree.Walk(func(name string, entry *TreeEntry) error {
|
|
||||||
callCount++
|
|
||||||
|
|
||||||
return stopError
|
|
||||||
})
|
|
||||||
if err != stopError {
|
|
||||||
t.Fatalf("got error %v, want %v", err, stopError)
|
|
||||||
}
|
|
||||||
if callCount != 1 {
|
|
||||||
t.Fatalf("got called %v times, want %v", callCount, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7d3c7057f0e774aecd6fc4ef8333e69e5c4873e0
|
30
wrapper.c
30
wrapper.c
|
@ -104,7 +104,7 @@ static int set_callback_error(char *error_message, int ret)
|
||||||
{
|
{
|
||||||
if (error_message != NULL) {
|
if (error_message != NULL) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
giterr_set_str(GIT_ERROR_CALLBACK, error_message);
|
git_error_set_str(GIT_ERROR_CALLBACK, error_message);
|
||||||
free(error_message);
|
free(error_message);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -116,28 +116,18 @@ void _go_git_populate_apply_callbacks(git_apply_options *options)
|
||||||
options->hunk_cb = (git_apply_hunk_cb)&hunkApplyCallback;
|
options->hunk_cb = (git_apply_hunk_cb)&hunkApplyCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int commit_create_callback(
|
static int commit_signing_callback(
|
||||||
git_oid *out,
|
git_buf *signature,
|
||||||
const git_signature *author,
|
git_buf *signature_field,
|
||||||
const git_signature *committer,
|
const char *commit_contents,
|
||||||
const char *message_encoding,
|
|
||||||
const char *message,
|
|
||||||
const git_tree *tree,
|
|
||||||
size_t parent_count,
|
|
||||||
const git_commit *parents[],
|
|
||||||
void *payload)
|
void *payload)
|
||||||
{
|
{
|
||||||
char *error_message = NULL;
|
char *error_message = NULL;
|
||||||
const int ret = commitCreateCallback(
|
const int ret = commitSigningCallback(
|
||||||
&error_message,
|
&error_message,
|
||||||
out,
|
signature,
|
||||||
(git_signature *)author,
|
signature_field,
|
||||||
(git_signature *)committer,
|
(char *)commit_contents,
|
||||||
(char *)message_encoding,
|
|
||||||
(char *)message,
|
|
||||||
(git_tree *)tree,
|
|
||||||
parent_count,
|
|
||||||
(git_commit **)parents,
|
|
||||||
payload
|
payload
|
||||||
);
|
);
|
||||||
return set_callback_error(error_message, ret);
|
return set_callback_error(error_message, ret);
|
||||||
|
@ -145,7 +135,7 @@ static int commit_create_callback(
|
||||||
|
|
||||||
void _go_git_populate_rebase_callbacks(git_rebase_options *opts)
|
void _go_git_populate_rebase_callbacks(git_rebase_options *opts)
|
||||||
{
|
{
|
||||||
opts->commit_create_cb = commit_create_callback;
|
opts->signing_cb = commit_signing_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _go_git_populate_clone_callbacks(git_clone_options *opts)
|
void _go_git_populate_clone_callbacks(git_clone_options *opts)
|
||||||
|
|
Loading…
Reference in New Issue