Compare commits
213 Commits
cherry-pic
...
main
Author | SHA1 | Date |
---|---|---|
|
9c30d41e40 | |
|
c9a7e84e5b | |
|
a4ee4aafbc | |
|
cf84056045 | |
|
585a8dbbe5 | |
|
d5a0e0056f | |
|
530f3618a8 | |
|
e65b1c188c | |
|
4b14d29c20 | |
|
c1ec21d89c | |
|
9db5de109c | |
|
7bff4ca7ad | |
|
eae00773cc | |
|
e7d1b2b69f | |
|
c598ea5718 | |
|
5eca48cda9 | |
|
1fcc9d8743 | |
|
5e35338d58 | |
|
533c82f270 | |
|
6cea7a7a59 | |
|
0e8009f00a | |
|
6eae74c128 | |
|
9b155184fe | |
|
c6da3b97a8 | |
|
c8ce59d4eb | |
|
922f2f7487 | |
|
dcc9331226 | |
|
018647fd48 | |
|
b78bde3d74 | |
|
5def02a589 | |
|
70e5e419cf | |
|
b983e1daeb | |
|
f1fa96c7b7 | |
|
dbe032c347 | |
|
549706bb57 | |
|
2077003fa5 | |
|
d4524761d9 | |
|
15434610fe | |
|
be5a99a807 | |
|
fbaf9d1d1a | |
|
df7084d36a | |
|
1e2cb92b48 | |
|
0d7c8dadb4 | |
|
a4d202ed7b | |
|
aeb22bcf7d | |
|
f6c5753df8 | |
|
2fd0495c43 | |
|
73d97b9bbe | |
|
07147a8ea8 | |
|
4b2ac7c998 | |
|
698ddfb4ac | |
|
10c67474a8 | |
|
e28cce87c7 | |
|
abf02bc7d7 | |
|
54afccfa0f | |
|
5d8eaf7e65 | |
|
137c05e802 | |
|
1fabe95fb7 | |
|
7497529f70 | |
|
2bd574b6bd | |
|
2d639d8e49 | |
|
ccbe4719bd | |
|
b46ebfab8c | |
|
77460dd7f0 | |
|
c3664193f3 | |
|
ad3ec3664d | |
|
f83530b18d | |
|
10d5ebf231 | |
|
3a4204bd93 | |
|
5b6ce70b89 | |
|
37b81b61f1 | |
|
111185838c | |
|
f3a746d7b6 | |
|
3c5c580d78 | |
|
7e726fda6e | |
|
7d4453198b | |
|
7883ec85de | |
|
2ac9f4e69b | |
|
5314951759 | |
|
fc6eaf3638 | |
|
462ebd83e0 | |
|
d8f9990d4d | |
|
b1cad11555 | |
|
20a55cdf92 | |
|
c78ae57de6 | |
|
619a9c236b | |
|
9eaf4fed5f | |
|
1c9bef0f9f | |
|
33dac3d460 | |
|
5241c72e6e | |
|
31f877e249 | |
|
cf6522c7fe | |
|
8b51d0db8e | |
|
862cde393c | |
|
91d08450b6 | |
|
512f37b369 | |
|
13ca96065e | |
|
0843b826d2 | |
|
89dc80bbea | |
|
033ad6e5ef | |
|
3a2102638d | |
|
2b66c0f9e7 | |
|
a32375a860 | |
|
e10c2eeef2 | |
|
30de4b2e26 | |
|
0505eef78d | |
|
93c4c5b30a | |
|
91946a5705 | |
|
05bc5e36ff | |
|
37f732a833 | |
|
45097a857c | |
|
c1903b47fe | |
|
3c88bd9f1a | |
|
21d618136f | |
|
a140f2310f | |
|
627447092f | |
|
06764f48dc | |
|
00374b39aa | |
|
c20008416a | |
|
4bca045e5a | |
|
30c3d0ffe2 | |
|
2bb5930733 | |
|
26edffd5f5 | |
|
419bac9075 | |
|
f21ecd9e74 | |
|
22d400832b | |
|
150a8c6016 | |
|
b201c503ab | |
|
75c5e41422 | |
|
11506ab070 | |
|
917d8dcb9e | |
|
aa802a90db | |
|
e2d039017f | |
|
ba1b5f0c23 | |
|
c5159e624e | |
|
ce19fa064f | |
|
97e6392d3a | |
|
790b3d2ac0 | |
|
93a1ee401f | |
|
5c79683685 | |
|
bf289c8b36 | |
|
79b2cb6ca1 | |
|
3849c7f52a | |
|
a5b3de11ae | |
|
26c983c3a2 | |
|
37e5b53f74 | |
|
57ab6bc351 | |
|
b7eeb4f405 | |
|
5cdcbf1607 | |
|
b2e2b2f71b | |
|
4fa9349942 | |
|
ad02c37e6d | |
|
fe0f562cc0 | |
|
13090d85b4 | |
|
bf1e8a4338 | |
|
5fda6dd901 | |
|
2f91268f74 | |
|
f4ea2a561d | |
|
8766f9f36c | |
|
6d67bde74a | |
|
35518c78df | |
|
f505e39c9e | |
|
a2c93a0bcf | |
|
b609c04b68 | |
|
2609f4c6f2 | |
|
b30b050c9c | |
|
e93f34cf18 | |
|
30c57ff09e | |
|
e9856f2c38 | |
|
f3c487966d | |
|
7ae106611c | |
|
fb438dbf9a | |
|
ee6dff2f8e | |
|
b06a2a6900 | |
|
f969cc900d | |
|
bcf325244c | |
|
b51a90c133 | |
|
c27981c283 | |
|
c740e1d83d | |
|
fc1230ba16 | |
|
e319b9427f | |
|
7197faee79 | |
|
7e9128bd58 | |
|
69175cb426 | |
|
ab3470030b | |
|
344dc33fae | |
|
e0ad45065e | |
|
92ebf4515c | |
|
8b368063e9 | |
|
a2ac1b9ed1 | |
|
8d27336e8a | |
|
8ff5e43711 | |
|
dd973b99ad | |
|
eec1547c20 | |
|
92501bd663 | |
|
b3256d9058 | |
|
5280ceb751 | |
|
538a05d55c | |
|
973938cbb5 | |
|
d7fd15b1e0 | |
|
bdca40d275 | |
|
14280de4da | |
|
a2de5ababa | |
|
2c42b80551 | |
|
925932a54f | |
|
b7ca4a96f5 | |
|
c75e0221d7 | |
|
9de57cc90e | |
|
03339f731a | |
|
cf2379295a | |
|
9b850d084e | |
|
21fd4ad5f6 | |
|
79fe156d30 |
|
@ -1,54 +0,0 @@
|
||||||
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)"
|
|
|
@ -1,127 +0,0 @@
|
||||||
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
|
|
||||||
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
|
|
||||||
run: |
|
|
||||||
git submodule update --init
|
|
||||||
sudo apt-get install -y --no-install-recommends libssh2-1-dev
|
|
||||||
sudo ./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)
|
|
|
@ -1,28 +0,0 @@
|
||||||
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,2 +1,4 @@
|
||||||
/static-build/
|
/static-build/
|
||||||
/dynamic-build/
|
/dynamic-build/
|
||||||
|
|
||||||
|
go.*
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
[submodule "vendor/libgit2"]
|
|
||||||
path = vendor/libgit2
|
|
||||||
url = https://github.com/libgit2/libgit2
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build static && !system_libgit2
|
||||||
// +build static,!system_libgit2
|
// +build static,!system_libgit2
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
@ -9,8 +10,8 @@ package git
|
||||||
#cgo CFLAGS: -DLIBGIT2_STATIC
|
#cgo CFLAGS: -DLIBGIT2_STATIC
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27
|
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
|
||||||
# error "Invalid libgit2 version; this git2go supports libgit2 v0.27"
|
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.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
|
#cgo CFLAGS: -DLIBGIT2_DYNAMIC -I/opt/libgit2/include
|
||||||
|
#cgo LDFLAGS: -L/opt/libgit2 -lgit2
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27
|
|
||||||
# error "Invalid libgit2 version; this git2go supports libgit2 v0.27"
|
|
||||||
#endif
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build static && system_libgit2
|
||||||
// +build static,system_libgit2
|
// +build static,system_libgit2
|
||||||
|
|
||||||
package git
|
package git
|
||||||
|
@ -7,8 +8,8 @@ package git
|
||||||
#cgo CFLAGS: -DLIBGIT2_STATIC
|
#cgo CFLAGS: -DLIBGIT2_STATIC
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
#if LIBGIT2_VER_MAJOR != 0 || LIBGIT2_VER_MINOR != 27
|
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5
|
||||||
# error "Invalid libgit2 version; this git2go supports libgit2 v0.27"
|
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.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 git2go contributors
|
Copyright (c) 2013 The libgit2 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,7 +1,11 @@
|
||||||
TEST_ARGS ?= --count=1
|
TEST_ARGS ?= --count=1
|
||||||
|
|
||||||
default: test
|
PKG_CONFIG_PATH=/opt/libgit2/
|
||||||
|
|
||||||
|
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" ./...
|
||||||
|
@ -10,12 +14,19 @@ 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
|
||||||
go test $(TEST_ARGS) ./...
|
LD_LIBRARY_PATH=/opt/libgit2 PKG_CONFIG_PATH=/opt/libgit2/ go test -v -x $(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
|
||||||
|
|
72
README.md
72
README.md
|
@ -1,86 +1,48 @@
|
||||||
git2go
|
GO libgit2
|
||||||
======
|
======
|
||||||
[](http://godoc.org/github.com/libgit2/git2go/v27) [](https://travis-ci.org/libgit2/git2go)
|
[](http://godoc.org/go.wit.com/lib/libgit2) [](https://travis-ci.org/libgit2/libgit2)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
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:
|
* This package is updated to work against libgit2 version 1.8 on Debian sid
|
||||||
|
* There is one line commented out which needs to be fixed in remote.go
|
||||||
| libgit2 | git2go |
|
* some of the tests seem to run
|
||||||
|---------|---------------|
|
|
||||||
| main | (will be 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 v0.27 installed, you'd import git2go v27 with
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go get github.com/libgit2/git2go/v27
|
go install go.wit.com/apps/go-clone@latest
|
||||||
```
|
go install go.wit.com/apps/go-mod-clean@latest
|
||||||
```go
|
go-clone --recusive go.wit.com/lib/libgit2
|
||||||
import "github.com/libgit2/git2go/v27"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
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.
|
TODO: not sure yet
|
||||||
|
|
||||||
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 git2go.
|
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.
|
||||||
|
|
||||||
|
|
||||||
### 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 v0.27
|
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
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/libgit2/git2go/v27"
|
goimports -w *.go
|
||||||
```
|
```
|
||||||
|
|
||||||
### 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/v27 => ../../libgit2/git2go
|
|
||||||
|
|
||||||
Parallelism and network operations
|
Parallelism and network operations
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
Running the tests
|
Running the tests
|
||||||
-----------------
|
-----------------
|
||||||
|
@ -102,6 +64,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 (@carlosmn)
|
- Carlos Martín (github@carlosmn)
|
||||||
- Vicent Martí (@vmg)
|
- Vicent Martí (github@vmg)
|
||||||
|
|
||||||
|
|
4
blame.go
4
blame.go
|
@ -23,7 +23,7 @@ func DefaultBlameOptions() (BlameOptions, error) {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
opts := C.git_blame_options{}
|
opts := C.git_blame_options{}
|
||||||
ecode := C.git_blame_init_options(&opts, C.GIT_BLAME_OPTIONS_VERSION)
|
ecode := C.git_blame_options_init(&opts, C.GIT_BLAME_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return BlameOptions{}, MakeGitError(ecode)
|
return BlameOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,8 @@ const (
|
||||||
BlameTrackCopiesSameCommitCopies BlameOptionsFlag = C.GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES
|
BlameTrackCopiesSameCommitCopies BlameOptionsFlag = C.GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES
|
||||||
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
|
||||||
|
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) {
|
||||||
|
|
6
blob.go
6
blob.go
|
@ -68,7 +68,7 @@ func (repo *Repository) CreateBlobFromBuffer(data []byte) (*Oid, error) {
|
||||||
size = C.size_t(0)
|
size = C.size_t(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
ecode := C.git_blob_create_frombuffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
|
ecode := C.git_blob_create_from_buffer(&id, repo.ptr, unsafe.Pointer(&data[0]), size)
|
||||||
runtime.KeepAlive(repo)
|
runtime.KeepAlive(repo)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
|
@ -88,7 +88,7 @@ func (repo *Repository) CreateFromStream(hintPath string) (*BlobWriteStream, err
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_blob_create_fromstream(&stream, repo.ptr, chintPath)
|
ecode := C.git_blob_create_from_stream(&stream, repo.ptr, chintPath)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func (stream *BlobWriteStream) Commit() (*Oid, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_blob_create_fromstream_commit(&oid, stream.ptr)
|
ecode := C.git_blob_create_from_stream_commit(&oid, stream.ptr)
|
||||||
runtime.KeepAlive(stream)
|
runtime.KeepAlive(stream)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
|
|
|
@ -210,7 +210,7 @@ func (repo *Repository) RemoteName(canonicalBranchName string) (string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return "", MakeGitError(ret)
|
return "", MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&nameBuf)
|
defer C.git_buf_dispose(&nameBuf)
|
||||||
|
|
||||||
return C.GoString(nameBuf.ptr), nil
|
return C.GoString(nameBuf.ptr), nil
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ func (repo *Repository) UpstreamName(canonicalBranchName string) (string, error)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return "", MakeGitError(ret)
|
return "", MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&nameBuf)
|
defer C.git_buf_dispose(&nameBuf)
|
||||||
|
|
||||||
return C.GoString(nameBuf.ptr), nil
|
return C.GoString(nameBuf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
14
checkout.go
14
checkout.go
|
@ -7,7 +7,6 @@ extern void _go_git_populate_checkout_callbacks(git_checkout_options *opts);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -36,7 +35,6 @@ const (
|
||||||
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
|
CheckoutDontUpdateIndex CheckoutStrategy = C.GIT_CHECKOUT_DONT_UPDATE_INDEX // Normally checkout updates index entries as it goes; this stops that
|
||||||
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
|
CheckoutNoRefresh CheckoutStrategy = C.GIT_CHECKOUT_NO_REFRESH // Don't refresh index/config/etc before doing checkout
|
||||||
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files
|
CheckoutSkipUnmerged CheckoutStrategy = C.GIT_CHECKOUT_SKIP_UNMERGED // Allow checkout to skip unmerged files
|
||||||
CheckoutUserOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
|
|
||||||
CheckoutUseOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
|
CheckoutUseOurs CheckoutStrategy = C.GIT_CHECKOUT_USE_OURS // For unmerged files, checkout stage 2 from index
|
||||||
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index
|
CheckoutUseTheirs CheckoutStrategy = C.GIT_CHECKOUT_USE_THEIRS // For unmerged files, checkout stage 3 from index
|
||||||
CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
|
CheckoutDisablePathspecMatch CheckoutStrategy = C.GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH // Treat pathspec as simple list of exact match file paths
|
||||||
|
@ -50,8 +48,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) ErrorCode
|
type CheckoutNotifyCallback func(why CheckoutNotifyType, path string, baseline, target, workdir DiffFile) error
|
||||||
type CheckoutProgressCallback func(path string, completed, total uint) ErrorCode
|
type CheckoutProgressCallback func(path string, completed, total uint)
|
||||||
|
|
||||||
type CheckoutOptions struct {
|
type CheckoutOptions struct {
|
||||||
Strategy CheckoutStrategy // Default will be a dry run
|
Strategy CheckoutStrategy // Default will be a dry run
|
||||||
|
@ -117,9 +115,9 @@ func checkoutNotifyCallback(
|
||||||
if data.options.NotifyCallback == nil {
|
if data.options.NotifyCallback == nil {
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
ret := data.options.NotifyCallback(CheckoutNotifyType(why), path, baseline, target, workdir)
|
err := data.options.NotifyCallback(CheckoutNotifyType(why), path, baseline, target, workdir)
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
*data.errorTarget = err
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
|
@ -142,7 +140,7 @@ func checkoutProgressCallback(
|
||||||
// the provided CheckoutOptions struct. Returns copts, or nil if opts is nil,
|
// the provided CheckoutOptions struct. Returns copts, or nil if opts is nil,
|
||||||
// in order to help with what to pass.
|
// in order to help with what to pass.
|
||||||
func populateCheckoutOptions(copts *C.git_checkout_options, opts *CheckoutOptions, errorTarget *error) *C.git_checkout_options {
|
func populateCheckoutOptions(copts *C.git_checkout_options, opts *CheckoutOptions, errorTarget *error) *C.git_checkout_options {
|
||||||
C.git_checkout_init_options(copts, C.GIT_CHECKOUT_OPTIONS_VERSION)
|
C.git_checkout_options_init(copts, C.GIT_CHECKOUT_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,30 +9,28 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type CherrypickOptions struct {
|
type CherrypickOptions struct {
|
||||||
Version uint
|
|
||||||
Mainline uint
|
Mainline uint
|
||||||
MergeOpts MergeOptions
|
MergeOptions MergeOptions
|
||||||
CheckoutOpts CheckoutOptions
|
CheckoutOptions CheckoutOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
func cherrypickOptionsFromC(c *C.git_cherrypick_options) CherrypickOptions {
|
||||||
opts := CherrypickOptions{
|
opts := CherrypickOptions{
|
||||||
Version: uint(c.version),
|
|
||||||
Mainline: uint(c.mainline),
|
Mainline: uint(c.mainline),
|
||||||
MergeOpts: mergeOptionsFromC(&c.merge_opts),
|
MergeOptions: mergeOptionsFromC(&c.merge_opts),
|
||||||
CheckoutOpts: checkoutOptionsFromC(&c.checkout_opts),
|
CheckoutOptions: checkoutOptionsFromC(&c.checkout_opts),
|
||||||
}
|
}
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateCherrypickOptions(copts *C.git_cherrypick_options, opts *CherrypickOptions, errorTarget *error) *C.git_cherrypick_options {
|
func populateCherrypickOptions(copts *C.git_cherrypick_options, opts *CherrypickOptions, errorTarget *error) *C.git_cherrypick_options {
|
||||||
C.git_cherrypick_init_options(copts, C.GIT_CHERRYPICK_OPTIONS_VERSION)
|
C.git_cherrypick_options_init(copts, C.GIT_CHERRYPICK_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.mainline = C.uint(opts.Mainline)
|
copts.mainline = C.uint(opts.Mainline)
|
||||||
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
|
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, errorTarget)
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ func DefaultCherrypickOptions() (CherrypickOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_cherrypick_init_options(&c, C.GIT_CHERRYPICK_OPTIONS_VERSION)
|
ecode := C.git_cherrypick_options_init(&c, C.GIT_CHERRYPICK_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return CherrypickOptions{}, MakeGitError(ecode)
|
return CherrypickOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -82,7 +80,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.MergeOpts)
|
cOpts := populateMergeOptions(&C.git_merge_options{}, &opts.MergeOptions)
|
||||||
defer freeMergeOptions(cOpts)
|
defer freeMergeOptions(cOpts)
|
||||||
|
|
||||||
var ptr *C.git_index
|
var ptr *C.git_index
|
||||||
|
|
20
clone.go
20
clone.go
|
@ -7,16 +7,15 @@ 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, ErrorCode)
|
type RemoteCreateCallback func(repo *Repository, name, url string) (*Remote, error)
|
||||||
|
|
||||||
type CloneOptions struct {
|
type CloneOptions struct {
|
||||||
*CheckoutOpts
|
CheckoutOptions CheckoutOptions
|
||||||
*FetchOptions
|
FetchOptions FetchOptions
|
||||||
Bare bool
|
Bare bool
|
||||||
CheckoutBranch string
|
CheckoutBranch string
|
||||||
RemoteCreateCallback RemoteCreateCallback
|
RemoteCreateCallback RemoteCreateCallback
|
||||||
|
@ -71,9 +70,10 @@ func remoteCreateCallback(
|
||||||
panic("invalid remote create callback")
|
panic("invalid remote create callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
remote, ret := data.options.RemoteCreateCallback(repo, name, url)
|
remote, err := data.options.RemoteCreateCallback(repo, name, url)
|
||||||
if ret < 0 {
|
|
||||||
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
if err != nil {
|
||||||
|
*data.errorTarget = err
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
if remote == nil {
|
if remote == nil {
|
||||||
|
@ -96,12 +96,12 @@ type cloneCallbackData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateCloneOptions(copts *C.git_clone_options, opts *CloneOptions, errorTarget *error) *C.git_clone_options {
|
func populateCloneOptions(copts *C.git_clone_options, opts *CloneOptions, errorTarget *error) *C.git_clone_options {
|
||||||
C.git_clone_init_options(copts, C.GIT_CLONE_OPTIONS_VERSION)
|
C.git_clone_options_init(copts, C.GIT_CLONE_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, 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 {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,15 +50,9 @@ func TestCloneWithCallback(t *testing.T) {
|
||||||
|
|
||||||
opts := CloneOptions{
|
opts := CloneOptions{
|
||||||
Bare: true,
|
Bare: true,
|
||||||
RemoteCreateCallback: func(r *Repository, name, url string) (*Remote, ErrorCode) {
|
RemoteCreateCallback: func(r *Repository, name, url string) (*Remote, error) {
|
||||||
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
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,3 +71,17 @@ func TestCloneWithCallback(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer remote.Free()
|
defer remote.Free()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCloneWithExternalHTTPUrl
|
||||||
|
func TestCloneWithExternalHTTPUrl(t *testing.T) {
|
||||||
|
|
||||||
|
path, err := ioutil.TempDir("", "git2go")
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
// clone the repo
|
||||||
|
url := "https://github.com/libgit2/TestGitRepository"
|
||||||
|
_, err = Clone(url, path, &CloneOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("cannot clone remote repo via https, error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
27
commit.go
27
commit.go
|
@ -37,10 +37,14 @@ func (c *Commit) Message() string {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) MessageEncoding() string {
|
func (c *Commit) MessageEncoding() MessageEncoding {
|
||||||
ret := C.GoString(C.git_commit_message_encoding(c.cast_ptr))
|
ptr := C.git_commit_message_encoding(c.cast_ptr)
|
||||||
|
if ptr == nil {
|
||||||
|
return MessageEncodingUTF8
|
||||||
|
}
|
||||||
|
ret := C.GoString(ptr)
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
return ret
|
return MessageEncoding(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Commit) RawMessage() string {
|
func (c *Commit) RawMessage() string {
|
||||||
|
@ -64,6 +68,19 @@ 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())
|
||||||
|
@ -86,10 +103,10 @@ func (c *Commit) WithSignature(signature string, signatureField string) (*Oid, e
|
||||||
func (c *Commit) ExtractSignature() (string, string, error) {
|
func (c *Commit) ExtractSignature() (string, string, error) {
|
||||||
|
|
||||||
var c_signed C.git_buf
|
var c_signed C.git_buf
|
||||||
defer C.git_buf_free(&c_signed)
|
defer C.git_buf_dispose(&c_signed)
|
||||||
|
|
||||||
var c_signature C.git_buf
|
var c_signature C.git_buf
|
||||||
defer C.git_buf_free(&c_signature)
|
defer C.git_buf_dispose(&c_signature)
|
||||||
|
|
||||||
oid := c.Id()
|
oid := c.Id()
|
||||||
repo := C.git_commit_owner(c.cast_ptr)
|
repo := C.git_commit_owner(c.cast_ptr)
|
||||||
|
|
12
config.go
12
config.go
|
@ -135,7 +135,7 @@ func (c *Config) LookupString(name string) (string, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return "", MakeGitError(ret)
|
return "", MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&valBuf)
|
defer C.git_buf_dispose(&valBuf)
|
||||||
|
|
||||||
return C.GoString(valBuf.ptr), nil
|
return C.GoString(valBuf.ptr), nil
|
||||||
}
|
}
|
||||||
|
@ -345,7 +345,7 @@ func (c *Config) OpenLevel(parent *Config, level ConfigLevel) (*Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenOndisk creates a new config instance containing a single on-disk file
|
// OpenOndisk creates a new config instance containing a single on-disk file
|
||||||
func OpenOndisk(parent *Config, path string) (*Config, error) {
|
func OpenOndisk(path string) (*Config, error) {
|
||||||
cpath := C.CString(path)
|
cpath := C.CString(path)
|
||||||
defer C.free(unsafe.Pointer(cpath))
|
defer C.free(unsafe.Pointer(cpath))
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ func (iter *ConfigIterator) Free() {
|
||||||
|
|
||||||
func ConfigFindGlobal() (string, error) {
|
func ConfigFindGlobal() (string, error) {
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -407,7 +407,7 @@ func ConfigFindGlobal() (string, error) {
|
||||||
|
|
||||||
func ConfigFindSystem() (string, error) {
|
func ConfigFindSystem() (string, error) {
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -422,7 +422,7 @@ func ConfigFindSystem() (string, error) {
|
||||||
|
|
||||||
func ConfigFindXDG() (string, error) {
|
func ConfigFindXDG() (string, error) {
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -440,7 +440,7 @@ func ConfigFindXDG() (string, error) {
|
||||||
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
|
// Look for the file in %PROGRAMDATA%\Git\config used by portable git.
|
||||||
func ConfigFindProgramdata() (string, error) {
|
func ConfigFindProgramdata() (string, error) {
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
|
@ -13,7 +13,7 @@ func setupConfig() (*Config, error) {
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
c, err = OpenOndisk(nil, tempConfig)
|
c, err = OpenOndisk(tempConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
210
credentials.go
210
credentials.go
|
@ -2,51 +2,114 @@ package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
#include <git2/credential.h>
|
||||||
|
#include <git2/sys/credential.h>
|
||||||
|
|
||||||
void _go_git_populate_credential_ssh_custom(git_cred_ssh_custom *cred);
|
git_credential_t _go_git_credential_credtype(git_credential *cred);
|
||||||
|
void _go_git_populate_credential_ssh_custom(git_credential_ssh_custom *cred);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CredType uint
|
// CredentialType is a bitmask of supported credential types.
|
||||||
|
//
|
||||||
|
// This represents the various types of authentication methods supported by the
|
||||||
|
// library.
|
||||||
|
type CredentialType uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CredTypeUserpassPlaintext CredType = C.GIT_CREDTYPE_USERPASS_PLAINTEXT
|
CredentialTypeUserpassPlaintext CredentialType = C.GIT_CREDENTIAL_USERPASS_PLAINTEXT
|
||||||
CredTypeSshKey CredType = C.GIT_CREDTYPE_SSH_KEY
|
CredentialTypeSSHKey CredentialType = C.GIT_CREDENTIAL_SSH_KEY
|
||||||
CredTypeSshCustom CredType = C.GIT_CREDTYPE_SSH_CUSTOM
|
CredentialTypeSSHCustom CredentialType = C.GIT_CREDENTIAL_SSH_CUSTOM
|
||||||
CredTypeDefault CredType = C.GIT_CREDTYPE_DEFAULT
|
CredentialTypeDefault CredentialType = C.GIT_CREDENTIAL_DEFAULT
|
||||||
|
CredentialTypeSSHInteractive CredentialType = C.GIT_CREDENTIAL_SSH_INTERACTIVE
|
||||||
|
CredentialTypeUsername CredentialType = C.GIT_CREDENTIAL_USERNAME
|
||||||
|
CredentialTypeSSHMemory CredentialType = C.GIT_CREDENTIAL_SSH_MEMORY
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cred struct {
|
func (t CredentialType) String() string {
|
||||||
doNotCompare
|
if t == 0 {
|
||||||
ptr *C.git_cred
|
return "CredentialType(0)"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Cred) HasUsername() bool {
|
var parts []string
|
||||||
if C.git_cred_has_username(o.ptr) == 1 {
|
|
||||||
|
if (t & CredentialTypeUserpassPlaintext) != 0 {
|
||||||
|
parts = append(parts, "UserpassPlaintext")
|
||||||
|
t &= ^CredentialTypeUserpassPlaintext
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHKey) != 0 {
|
||||||
|
parts = append(parts, "SSHKey")
|
||||||
|
t &= ^CredentialTypeSSHKey
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHCustom) != 0 {
|
||||||
|
parts = append(parts, "SSHCustom")
|
||||||
|
t &= ^CredentialTypeSSHCustom
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeDefault) != 0 {
|
||||||
|
parts = append(parts, "Default")
|
||||||
|
t &= ^CredentialTypeDefault
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHInteractive) != 0 {
|
||||||
|
parts = append(parts, "SSHInteractive")
|
||||||
|
t &= ^CredentialTypeSSHInteractive
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeUsername) != 0 {
|
||||||
|
parts = append(parts, "Username")
|
||||||
|
t &= ^CredentialTypeUsername
|
||||||
|
}
|
||||||
|
if (t & CredentialTypeSSHMemory) != 0 {
|
||||||
|
parts = append(parts, "SSHMemory")
|
||||||
|
t &= ^CredentialTypeSSHMemory
|
||||||
|
}
|
||||||
|
|
||||||
|
if t != 0 {
|
||||||
|
parts = append(parts, fmt.Sprintf("CredentialType(%#x)", t))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(parts, "|")
|
||||||
|
}
|
||||||
|
|
||||||
|
type Credential struct {
|
||||||
|
doNotCompare
|
||||||
|
ptr *C.git_credential
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCredential() *Credential {
|
||||||
|
cred := &Credential{}
|
||||||
|
runtime.SetFinalizer(cred, (*Credential).Free)
|
||||||
|
return cred
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *Credential) HasUsername() bool {
|
||||||
|
if C.git_credential_has_username(o.ptr) == 1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Cred) Type() CredType {
|
func (o *Credential) Type() CredentialType {
|
||||||
return (CredType)(o.ptr.credtype)
|
return (CredentialType)(C._go_git_credential_credtype(o.ptr))
|
||||||
}
|
}
|
||||||
|
|
||||||
func credFromC(ptr *C.git_cred) *Cred {
|
func (o *Credential) Free() {
|
||||||
return &Cred{ptr: ptr}
|
C.git_credential_free(o.ptr)
|
||||||
|
runtime.SetFinalizer(o, nil)
|
||||||
|
o.ptr = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserpassPlaintext returns the plaintext username/password combination stored in the Cred.
|
// GetUserpassPlaintext returns the plaintext username/password combination stored in the Cred.
|
||||||
func (o *Cred) GetUserpassPlaintext() (username, password string, err error) {
|
func (o *Credential) GetUserpassPlaintext() (username, password string, err error) {
|
||||||
if o.Type() != CredTypeUserpassPlaintext {
|
if o.Type() != CredentialTypeUserpassPlaintext {
|
||||||
err = errors.New("credential is not userpass plaintext")
|
err = errors.New("credential is not userpass plaintext")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -58,8 +121,8 @@ func (o *Cred) GetUserpassPlaintext() (username, password string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSSHKey returns the SSH-specific key information from the Cred object.
|
// GetSSHKey returns the SSH-specific key information from the Cred object.
|
||||||
func (o *Cred) GetSSHKey() (username, publickey, privatekey, passphrase string, err error) {
|
func (o *Credential) GetSSHKey() (username, publickey, privatekey, passphrase string, err error) {
|
||||||
if o.Type() != CredTypeSshKey {
|
if o.Type() != CredentialTypeSSHKey && o.Type() != CredentialTypeSSHMemory {
|
||||||
err = fmt.Errorf("credential is not an SSH key: %v", o.Type())
|
err = fmt.Errorf("credential is not an SSH key: %v", o.Type())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,27 +135,44 @@ func (o *Cred) GetSSHKey() (username, publickey, privatekey, passphrase string,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredUsername(username string) (int, Cred) {
|
func NewCredentialUsername(username string) (*Credential, error) {
|
||||||
cred := Cred{}
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
ret := C.git_cred_username_new(&cred.ptr, cusername)
|
ret := C.git_credential_username_new(&cred.ptr, cusername)
|
||||||
return int(ret), cred
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredUserpassPlaintext(username string, password string) (int, Cred) {
|
func NewCredentialUserpassPlaintext(username string, password string) (*Credential, error) {
|
||||||
cred := Cred{}
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpassword := C.CString(password)
|
cpassword := C.CString(password)
|
||||||
defer C.free(unsafe.Pointer(cpassword))
|
defer C.free(unsafe.Pointer(cpassword))
|
||||||
ret := C.git_cred_userpass_plaintext_new(&cred.ptr, cusername, cpassword)
|
ret := C.git_credential_userpass_plaintext_new(&cred.ptr, cusername, cpassword)
|
||||||
return int(ret), cred
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCredSshKey creates new ssh credentials reading the public and private keys
|
// NewCredentialSSHKey creates new ssh credentials reading the public and private keys
|
||||||
// from the file system.
|
// from the file system.
|
||||||
func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (int, Cred) {
|
func NewCredentialSSHKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (*Credential, error) {
|
||||||
cred := Cred{}
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpublickey := C.CString(publicKeyPath)
|
cpublickey := C.CString(publicKeyPath)
|
||||||
|
@ -101,14 +181,21 @@ func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string,
|
||||||
defer C.free(unsafe.Pointer(cprivatekey))
|
defer C.free(unsafe.Pointer(cprivatekey))
|
||||||
cpassphrase := C.CString(passphrase)
|
cpassphrase := C.CString(passphrase)
|
||||||
defer C.free(unsafe.Pointer(cpassphrase))
|
defer C.free(unsafe.Pointer(cpassphrase))
|
||||||
ret := C.git_cred_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
ret := C.git_credential_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
||||||
return int(ret), cred
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCredSshKeyFromMemory creates new ssh credentials using the publicKey and privateKey
|
// NewCredentialSSHKeyFromMemory creates new ssh credentials using the publicKey and privateKey
|
||||||
// arguments as the values for the public and private keys.
|
// arguments as the values for the public and private keys.
|
||||||
func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (int, Cred) {
|
func NewCredentialSSHKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (*Credential, error) {
|
||||||
cred := Cred{}
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpublickey := C.CString(publicKey)
|
cpublickey := C.CString(publicKey)
|
||||||
|
@ -117,22 +204,27 @@ func NewCredSshKeyFromMemory(username string, publicKey string, privateKey strin
|
||||||
defer C.free(unsafe.Pointer(cprivatekey))
|
defer C.free(unsafe.Pointer(cprivatekey))
|
||||||
cpassphrase := C.CString(passphrase)
|
cpassphrase := C.CString(passphrase)
|
||||||
defer C.free(unsafe.Pointer(cpassphrase))
|
defer C.free(unsafe.Pointer(cpassphrase))
|
||||||
ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
ret := C.git_credential_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
|
||||||
return int(ret), cred
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCredSshKeyFromAgent(username string) (int, Cred) {
|
func NewCredentialSSHKeyFromAgent(username string) (*Credential, error) {
|
||||||
cred := Cred{}
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
ret := C.git_cred_ssh_key_from_agent(&cred.ptr, cusername)
|
ret := C.git_credential_ssh_key_from_agent(&cred.ptr, cusername)
|
||||||
return int(ret), cred
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
return cred, nil
|
||||||
func NewCredDefault() (int, Cred) {
|
|
||||||
cred := Cred{}
|
|
||||||
ret := C.git_cred_default_new(&cred.ptr)
|
|
||||||
return int(ret), cred
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type credentialSSHCustomData struct {
|
type credentialSSHCustomData struct {
|
||||||
|
@ -140,7 +232,7 @@ type credentialSSHCustomData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//export credentialSSHCustomFree
|
//export credentialSSHCustomFree
|
||||||
func credentialSSHCustomFree(cred *C.git_cred_ssh_custom) {
|
func credentialSSHCustomFree(cred *C.git_credential_ssh_custom) {
|
||||||
if cred == nil {
|
if cred == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -171,11 +263,11 @@ func credentialSSHSignCallback(
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCredentialSSHKeyFromSigner creates new SSH credentials using the provided signer.
|
// NewCredentialSSHKeyFromSigner creates new SSH credentials using the provided signer.
|
||||||
func NewCredentialSSHKeyFromSigner(username string, signer ssh.Signer) (*Cred, error) {
|
func NewCredentialSSHKeyFromSigner(username string, signer ssh.Signer) (*Credential, error) {
|
||||||
publicKey := signer.PublicKey().Marshal()
|
publicKey := signer.PublicKey().Marshal()
|
||||||
|
|
||||||
ccred := (*C.git_cred_ssh_custom)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_cred_ssh_custom{}))))
|
ccred := (*C.git_credential_ssh_custom)(C.calloc(1, C.size_t(unsafe.Sizeof(C.git_credential_ssh_custom{}))))
|
||||||
ccred.parent.credtype = C.GIT_CREDTYPE_SSH_CUSTOM
|
ccred.parent.credtype = C.GIT_CREDENTIAL_SSH_CUSTOM
|
||||||
ccred.username = C.CString(username)
|
ccred.username = C.CString(username)
|
||||||
ccred.publickey = (*C.char)(C.CBytes(publicKey))
|
ccred.publickey = (*C.char)(C.CBytes(publicKey))
|
||||||
ccred.publickey_len = C.size_t(len(publicKey))
|
ccred.publickey_len = C.size_t(len(publicKey))
|
||||||
|
@ -186,9 +278,21 @@ func NewCredentialSSHKeyFromSigner(username string, signer ssh.Signer) (*Cred, e
|
||||||
}
|
}
|
||||||
ccred.payload = pointerHandles.Track(&data)
|
ccred.payload = pointerHandles.Track(&data)
|
||||||
|
|
||||||
cred := Cred{
|
cred := newCredential()
|
||||||
ptr: &ccred.parent,
|
cred.ptr = &ccred.parent
|
||||||
|
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cred, nil
|
func NewCredentialDefault() (*Credential, error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
cred := newCredential()
|
||||||
|
ret := C.git_credential_default_new(&cred.ptr)
|
||||||
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return cred, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,51 @@ type BlobCallbackData struct {
|
||||||
// Deprecated: CheckoutOpts is a deprecated alias of CheckoutOptions.
|
// Deprecated: CheckoutOpts is a deprecated alias of CheckoutOptions.
|
||||||
type CheckoutOpts = CheckoutOptions
|
type CheckoutOpts = CheckoutOptions
|
||||||
|
|
||||||
|
// credentials.go
|
||||||
|
|
||||||
|
// Deprecated: CredType is a deprecated alias of CredentialType
|
||||||
|
type CredType = CredentialType
|
||||||
|
|
||||||
|
const (
|
||||||
|
CredTypeUserpassPlaintext = CredentialTypeUserpassPlaintext
|
||||||
|
CredTypeSshKey = CredentialTypeSSHKey
|
||||||
|
CredTypeSshCustom = CredentialTypeSSHCustom
|
||||||
|
CredTypeDefault = CredentialTypeDefault
|
||||||
|
)
|
||||||
|
|
||||||
|
// Deprecated: Cred is a deprecated alias of Credential
|
||||||
|
type Cred = Credential
|
||||||
|
|
||||||
|
// Deprecated: NewCredUsername is a deprecated alias of NewCredentialUsername.
|
||||||
|
func NewCredUsername(username string) (*Cred, error) {
|
||||||
|
return NewCredentialUsername(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: NewCredUserpassPlaintext is a deprecated alias of NewCredentialUserpassPlaintext.
|
||||||
|
func NewCredUserpassPlaintext(username string, password string) (*Cred, error) {
|
||||||
|
return NewCredentialUserpassPlaintext(username, password)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: NewCredSshKey is a deprecated alias of NewCredentialSshKey.
|
||||||
|
func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKey(username, publicKeyPath, privateKeyPath, passphrase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: NewCredSshKeyFromMemory is a deprecated alias of NewCredentialSSHKeyFromMemory.
|
||||||
|
func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKeyFromMemory(username, publicKey, privateKey, passphrase)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: NewCredSshKeyFromAgent is a deprecated alias of NewCredentialSSHFromAgent.
|
||||||
|
func NewCredSshKeyFromAgent(username string) (*Cred, error) {
|
||||||
|
return NewCredentialSSHKeyFromAgent(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: NewCredDefault is a deprecated alias fof NewCredentialDefault.
|
||||||
|
func NewCredDefault() (*Cred, error) {
|
||||||
|
return NewCredentialDefault()
|
||||||
|
}
|
||||||
|
|
||||||
// diff.go
|
// diff.go
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -160,6 +205,8 @@ const (
|
||||||
ErrPassthrough = ErrorCodePassthrough
|
ErrPassthrough = ErrorCodePassthrough
|
||||||
// Deprecated: ErrIterOver is a deprecated alias of ErrorCodeIterOver.
|
// Deprecated: ErrIterOver is a deprecated alias of ErrorCodeIterOver.
|
||||||
ErrIterOver = ErrorCodeIterOver
|
ErrIterOver = ErrorCodeIterOver
|
||||||
|
// Deprecated: ErrApplyFail is a deprecated alias of ErrorCodeApplyFail.
|
||||||
|
ErrApplyFail = ErrorCodeApplyFail
|
||||||
)
|
)
|
||||||
|
|
||||||
// index.go
|
// index.go
|
||||||
|
@ -183,7 +230,27 @@ 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")
|
||||||
}
|
}
|
||||||
return (C.int)(callback(sub, C.GoString(name)))
|
err := 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
|
||||||
|
@ -192,9 +259,13 @@ func SubmoduleVisitor(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer)
|
||||||
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)
|
||||||
|
|
||||||
if callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback); ok {
|
callback, ok := pointerHandles.Get(ptr).(TreeWalkCallback)
|
||||||
return C.int(callback(root, newTreeEntry(entry)))
|
if !ok {
|
||||||
} 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func DefaultDescribeOptions() (DescribeOptions, error) {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
opts := C.git_describe_options{}
|
opts := C.git_describe_options{}
|
||||||
ecode := C.git_describe_init_options(&opts, C.GIT_DESCRIBE_OPTIONS_VERSION)
|
ecode := C.git_describe_options_init(&opts, C.GIT_DESCRIBE_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return DescribeOptions{}, MakeGitError(ecode)
|
return DescribeOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func DefaultDescribeFormatOptions() (DescribeFormatOptions, error) {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
opts := C.git_describe_format_options{}
|
opts := C.git_describe_format_options{}
|
||||||
ecode := C.git_describe_init_format_options(&opts, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)
|
ecode := C.git_describe_format_options_init(&opts, C.GIT_DESCRIBE_FORMAT_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return DescribeFormatOptions{}, MakeGitError(ecode)
|
return DescribeFormatOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func (result *DescribeResult) Format(opts *DescribeFormatOptions) (string, error
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return "", MakeGitError(ecode)
|
return "", MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&resultBuf)
|
defer C.git_buf_dispose(&resultBuf)
|
||||||
|
|
||||||
return C.GoString(resultBuf.ptr), nil
|
return C.GoString(resultBuf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
196
diff.go
196
diff.go
|
@ -3,6 +3,7 @@ package git
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
|
extern void _go_git_populate_apply_callbacks(git_apply_options *options);
|
||||||
extern int _go_git_diff_foreach(git_diff *diff, int eachFile, int eachHunk, int eachLine, void *payload);
|
extern int _go_git_diff_foreach(git_diff *diff, int eachFile, int eachHunk, int eachLine, void *payload);
|
||||||
extern void _go_git_setup_diff_notify_callbacks(git_diff_options* opts);
|
extern void _go_git_setup_diff_notify_callbacks(git_diff_options* opts);
|
||||||
extern int _go_git_diff_blobs(git_blob *old, const char *old_path, git_blob *new, const char *new_path, git_diff_options *opts, int eachFile, int eachHunk, int eachLine, void *payload);
|
extern int _go_git_diff_blobs(git_blob *old, const char *old_path, git_blob *new, const char *new_path, git_diff_options *opts, int eachFile, int eachHunk, int eachLine, void *payload);
|
||||||
|
@ -264,7 +265,7 @@ const (
|
||||||
func (stats *DiffStats) String(format DiffStatsFormat,
|
func (stats *DiffStats) String(format DiffStatsFormat,
|
||||||
width uint) (string, error) {
|
width uint) (string, error) {
|
||||||
buf := C.git_buf{}
|
buf := C.git_buf{}
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -457,7 +458,7 @@ func (diff *Diff) ToBuf(format DiffFormat) ([]byte, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&diffBuf)
|
defer C.git_buf_dispose(&diffBuf)
|
||||||
|
|
||||||
return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil
|
return C.GoBytes(unsafe.Pointer(diffBuf.ptr), C.int(diffBuf.size)), nil
|
||||||
}
|
}
|
||||||
|
@ -522,7 +523,7 @@ func DefaultDiffOptions() (DiffOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_diff_init_options(&opts, C.GIT_DIFF_OPTIONS_VERSION)
|
ecode := C.git_diff_options_init(&opts, C.GIT_DIFF_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return DiffOptions{}, MakeGitError(ecode)
|
return DiffOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -577,7 +578,7 @@ func DefaultDiffFindOptions() (DiffFindOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_diff_find_init_options(&opts, C.GIT_DIFF_FIND_OPTIONS_VERSION)
|
ecode := C.git_diff_find_options_init(&opts, C.GIT_DIFF_FIND_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return DiffFindOptions{}, MakeGitError(ecode)
|
return DiffFindOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -643,7 +644,7 @@ func diffNotifyCallback(_diff_so_far unsafe.Pointer, delta_to_add *C.git_diff_de
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateDiffOptions(copts *C.git_diff_options, opts *DiffOptions, repo *Repository, errorTarget *error) *C.git_diff_options {
|
func populateDiffOptions(copts *C.git_diff_options, opts *DiffOptions, repo *Repository, errorTarget *error) *C.git_diff_options {
|
||||||
C.git_diff_init_options(copts, C.GIT_DIFF_OPTIONS_VERSION)
|
C.git_diff_options_init(copts, C.GIT_DIFF_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -887,6 +888,191 @@ func DiffBlobs(oldBlob *Blob, oldAsPath string, newBlob *Blob, newAsPath string,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyHunkCallback is a callback that will be made per delta (file) when applying a patch.
|
||||||
|
type ApplyHunkCallback func(*DiffHunk) (apply bool, err error)
|
||||||
|
|
||||||
|
// ApplyDeltaCallback is a callback that will be made per hunk when applying a patch.
|
||||||
|
type ApplyDeltaCallback func(*DiffDelta) (apply bool, err error)
|
||||||
|
|
||||||
|
// ApplyOptions has 2 callbacks that are called for hunks or deltas
|
||||||
|
// If these functions return an error, abort the apply process immediately.
|
||||||
|
// If the first return value is true, the delta/hunk will be applied. If it is false, the delta/hunk will not be applied. In either case, the rest of the apply process will continue.
|
||||||
|
type ApplyOptions struct {
|
||||||
|
ApplyHunkCallback ApplyHunkCallback
|
||||||
|
ApplyDeltaCallback ApplyDeltaCallback
|
||||||
|
Flags uint
|
||||||
|
}
|
||||||
|
|
||||||
|
type applyCallbackData struct {
|
||||||
|
options *ApplyOptions
|
||||||
|
errorTarget *error
|
||||||
|
}
|
||||||
|
|
||||||
|
//export hunkApplyCallback
|
||||||
|
func hunkApplyCallback(_hunk *C.git_diff_hunk, _payload unsafe.Pointer) C.int {
|
||||||
|
data, ok := pointerHandles.Get(_payload).(*applyCallbackData)
|
||||||
|
if !ok {
|
||||||
|
panic("invalid apply options payload")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.options.ApplyHunkCallback == nil {
|
||||||
|
return C.int(ErrorCodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
hunk := diffHunkFromC(_hunk)
|
||||||
|
|
||||||
|
apply, err := data.options.ApplyHunkCallback(&hunk)
|
||||||
|
if err != nil {
|
||||||
|
*data.errorTarget = err
|
||||||
|
return C.int(ErrorCodeUser)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !apply {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return C.int(ErrorCodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
//export deltaApplyCallback
|
||||||
|
func deltaApplyCallback(_delta *C.git_diff_delta, _payload unsafe.Pointer) C.int {
|
||||||
|
data, ok := pointerHandles.Get(_payload).(*applyCallbackData)
|
||||||
|
if !ok {
|
||||||
|
panic("invalid apply options payload")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.options.ApplyDeltaCallback == nil {
|
||||||
|
return C.int(ErrorCodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
delta := diffDeltaFromC(_delta)
|
||||||
|
|
||||||
|
apply, err := data.options.ApplyDeltaCallback(&delta)
|
||||||
|
if err != nil {
|
||||||
|
*data.errorTarget = err
|
||||||
|
return C.int(ErrorCodeUser)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !apply {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return C.int(ErrorCodeOK)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DefaultApplyOptions returns default options for applying diffs or patches.
|
||||||
|
func DefaultApplyOptions() (*ApplyOptions, error) {
|
||||||
|
opts := C.git_apply_options{}
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ecode := C.git_apply_options_init(&opts, C.GIT_APPLY_OPTIONS_VERSION)
|
||||||
|
if int(ecode) != 0 {
|
||||||
|
return nil, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return applyOptionsFromC(&opts), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateApplyOptions(copts *C.git_apply_options, opts *ApplyOptions, errorTarget *error) *C.git_apply_options {
|
||||||
|
C.git_apply_options_init(copts, C.GIT_APPLY_OPTIONS_VERSION)
|
||||||
|
if opts == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
copts.flags = C.uint(opts.Flags)
|
||||||
|
|
||||||
|
if opts.ApplyDeltaCallback != nil || opts.ApplyHunkCallback != nil {
|
||||||
|
data := &applyCallbackData{
|
||||||
|
options: opts,
|
||||||
|
errorTarget: errorTarget,
|
||||||
|
}
|
||||||
|
C._go_git_populate_apply_callbacks(copts)
|
||||||
|
copts.payload = pointerHandles.Track(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return copts
|
||||||
|
}
|
||||||
|
|
||||||
|
func freeApplyOptions(copts *C.git_apply_options) {
|
||||||
|
if copts == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if copts.payload != nil {
|
||||||
|
pointerHandles.Untrack(copts.payload)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyOptionsFromC(copts *C.git_apply_options) *ApplyOptions {
|
||||||
|
return &ApplyOptions{
|
||||||
|
Flags: uint(copts.flags),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyLocation represents the possible application locations for applying
|
||||||
|
// diffs.
|
||||||
|
type ApplyLocation int
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ApplyLocationWorkdir applies the patch to the workdir, leaving the
|
||||||
|
// index untouched. This is the equivalent of `git apply` with no location
|
||||||
|
// argument.
|
||||||
|
ApplyLocationWorkdir ApplyLocation = C.GIT_APPLY_LOCATION_WORKDIR
|
||||||
|
// ApplyLocationIndex applies the patch to the index, leaving the working
|
||||||
|
// directory untouched. This is the equivalent of `git apply --cached`.
|
||||||
|
ApplyLocationIndex ApplyLocation = C.GIT_APPLY_LOCATION_INDEX
|
||||||
|
// ApplyLocationBoth applies the patch to both the working directory and
|
||||||
|
// the index. This is the equivalent of `git apply --index`.
|
||||||
|
ApplyLocationBoth ApplyLocation = C.GIT_APPLY_LOCATION_BOTH
|
||||||
|
)
|
||||||
|
|
||||||
|
// ApplyDiff appllies a Diff to the given repository, making changes directly
|
||||||
|
// in the working directory, the index, or both.
|
||||||
|
func (v *Repository) ApplyDiff(diff *Diff, location ApplyLocation, opts *ApplyOptions) error {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
cOpts := populateApplyOptions(&C.git_apply_options{}, opts, &err)
|
||||||
|
defer freeApplyOptions(cOpts)
|
||||||
|
|
||||||
|
ret := C.git_apply(v.ptr, diff.ptr, C.git_apply_location_t(location), cOpts)
|
||||||
|
runtime.KeepAlive(v)
|
||||||
|
runtime.KeepAlive(diff)
|
||||||
|
runtime.KeepAlive(cOpts)
|
||||||
|
if ret == C.int(ErrorCodeUser) && err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ret < 0 {
|
||||||
|
return MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyToTree applies a Diff to a Tree and returns the resulting image as an Index.
|
||||||
|
func (v *Repository) ApplyToTree(diff *Diff, tree *Tree, opts *ApplyOptions) (*Index, error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
cOpts := populateApplyOptions(&C.git_apply_options{}, opts, &err)
|
||||||
|
defer freeApplyOptions(cOpts)
|
||||||
|
|
||||||
|
var indexPtr *C.git_index
|
||||||
|
ret := C.git_apply_to_tree(&indexPtr, v.ptr, tree.cast_ptr, diff.ptr, cOpts)
|
||||||
|
runtime.KeepAlive(diff)
|
||||||
|
runtime.KeepAlive(tree)
|
||||||
|
runtime.KeepAlive(cOpts)
|
||||||
|
if ret == C.int(ErrorCodeUser) && err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ret < 0 {
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newIndexFromC(indexPtr, v), nil
|
||||||
|
}
|
||||||
|
|
||||||
// DiffFromBuffer reads the contents of a git patch file into a Diff object.
|
// DiffFromBuffer reads the contents of a git patch file into a Diff object.
|
||||||
//
|
//
|
||||||
// The diff object produced is similar to the one that would be produced if you
|
// The diff object produced is similar to the one that would be produced if you
|
||||||
|
|
448
diff_test.go
448
diff_test.go
|
@ -2,6 +2,10 @@ package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -235,3 +239,447 @@ func TestDiffBlobs(t *testing.T) {
|
||||||
t.Fatalf("Bad number of lines iterated")
|
t.Fatalf("Bad number of lines iterated")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestApplyDiffAddfile(t *testing.T) {
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
||||||
|
seedTestRepo(t, repo)
|
||||||
|
|
||||||
|
addFirstFileCommit, addFirstFileTree := addAndGetTree(t, repo, "file1", `hello`)
|
||||||
|
defer addFirstFileCommit.Free()
|
||||||
|
defer addFirstFileTree.Free()
|
||||||
|
addSecondFileCommit, addSecondFileTree := addAndGetTree(t, repo, "file2", `hello2`)
|
||||||
|
defer addSecondFileCommit.Free()
|
||||||
|
defer addSecondFileTree.Free()
|
||||||
|
|
||||||
|
diff, err := repo.DiffTreeToTree(addFirstFileTree, addSecondFileTree, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer diff.Free()
|
||||||
|
|
||||||
|
t.Run("check does not apply to current tree because file exists", func(t *testing.T) {
|
||||||
|
err = repo.ResetToCommit(addSecondFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expecting applying patch to current repo to fail")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("check apply to correct commit", func(t *testing.T) {
|
||||||
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
t.Run("Check that diff only changed one file", func(t *testing.T) {
|
||||||
|
checkSecondFileStaged(t, repo)
|
||||||
|
|
||||||
|
index, err := repo.Index()
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer index.Free()
|
||||||
|
|
||||||
|
newTreeOID, err := index.WriteTreeTo(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
newTree, err := repo.LookupTree(newTreeOID)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer newTree.Free()
|
||||||
|
|
||||||
|
_, err = repo.CreateCommit("HEAD", signature(), signature(), fmt.Sprintf("patch apply"), newTree, addFirstFileCommit)
|
||||||
|
checkFatal(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("test applying patch produced the same diff", func(t *testing.T) {
|
||||||
|
head, err := repo.Head()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
commit, err := repo.LookupCommit(head.Target())
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer commit.Free()
|
||||||
|
|
||||||
|
tree, err := commit.Tree()
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer tree.Free()
|
||||||
|
|
||||||
|
newDiff, err := repo.DiffTreeToTree(addFirstFileTree, tree, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer newDiff.Free()
|
||||||
|
|
||||||
|
raw1b, err := diff.ToBuf(DiffFormatPatch)
|
||||||
|
checkFatal(t, err)
|
||||||
|
raw2b, err := newDiff.ToBuf(DiffFormatPatch)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
raw1 := string(raw1b)
|
||||||
|
raw2 := string(raw2b)
|
||||||
|
|
||||||
|
if raw1 != raw2 {
|
||||||
|
t.Error("diffs should be the same")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("check convert to raw buffer and apply", func(t *testing.T) {
|
||||||
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
raw, err := diff.ToBuf(DiffFormatPatch)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if len(raw) == 0 {
|
||||||
|
t.Error("empty diff created")
|
||||||
|
}
|
||||||
|
|
||||||
|
diff2, err := DiffFromBuffer(raw, repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer diff2.Free()
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff2, ApplyLocationBoth, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("check apply callbacks work", func(t *testing.T) {
|
||||||
|
// reset the state and get new default options for test
|
||||||
|
resetAndGetOpts := func(t *testing.T) *ApplyOptions {
|
||||||
|
err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
opts, err := DefaultApplyOptions()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("Check hunk callback working applies patch", func(t *testing.T) {
|
||||||
|
opts := resetAndGetOpts(t)
|
||||||
|
|
||||||
|
called := false
|
||||||
|
opts.ApplyHunkCallback = func(hunk *DiffHunk) (apply bool, err error) {
|
||||||
|
called = true
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, opts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if called == false {
|
||||||
|
t.Error("apply hunk callback was not called")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSecondFileStaged(t, repo)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Check delta callback working applies patch", func(t *testing.T) {
|
||||||
|
opts := resetAndGetOpts(t)
|
||||||
|
|
||||||
|
called := false
|
||||||
|
opts.ApplyDeltaCallback = func(hunk *DiffDelta) (apply bool, err error) {
|
||||||
|
if hunk.NewFile.Path != "file2" {
|
||||||
|
t.Error("Unexpected delta in diff application")
|
||||||
|
}
|
||||||
|
called = true
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, opts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if called == false {
|
||||||
|
t.Error("apply hunk callback was not called")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkSecondFileStaged(t, repo)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Check delta callback returning false does not apply patch", func(t *testing.T) {
|
||||||
|
opts := resetAndGetOpts(t)
|
||||||
|
|
||||||
|
called := false
|
||||||
|
opts.ApplyDeltaCallback = func(hunk *DiffDelta) (apply bool, err error) {
|
||||||
|
if hunk.NewFile.Path != "file2" {
|
||||||
|
t.Error("Unexpected hunk in diff application")
|
||||||
|
}
|
||||||
|
called = true
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, opts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if called == false {
|
||||||
|
t.Error("apply hunk callback was not called")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNoFilesStaged(t, repo)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Check hunk callback returning causes application to fail", func(t *testing.T) {
|
||||||
|
opts := resetAndGetOpts(t)
|
||||||
|
|
||||||
|
called := false
|
||||||
|
opts.ApplyHunkCallback = func(hunk *DiffHunk) (apply bool, err error) {
|
||||||
|
called = true
|
||||||
|
return false, errors.New("something happened")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, opts)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected an error after trying to apply")
|
||||||
|
}
|
||||||
|
|
||||||
|
if called == false {
|
||||||
|
t.Error("apply hunk callback was not called")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNoFilesStaged(t, repo)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Check delta callback returning causes application to fail", func(t *testing.T) {
|
||||||
|
opts := resetAndGetOpts(t)
|
||||||
|
|
||||||
|
called := false
|
||||||
|
opts.ApplyDeltaCallback = func(hunk *DiffDelta) (apply bool, err error) {
|
||||||
|
if hunk.NewFile.Path != "file2" {
|
||||||
|
t.Error("Unexpected delta in diff application")
|
||||||
|
}
|
||||||
|
called = true
|
||||||
|
return false, errors.New("something happened")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = repo.ApplyDiff(diff, ApplyLocationBoth, opts)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected an error after trying to apply")
|
||||||
|
}
|
||||||
|
|
||||||
|
if called == false {
|
||||||
|
t.Error("apply hunk callback was not called")
|
||||||
|
}
|
||||||
|
|
||||||
|
checkNoFilesStaged(t, repo)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestApplyToTree(t *testing.T) {
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
||||||
|
seedTestRepo(t, repo)
|
||||||
|
|
||||||
|
commitA, treeA := addAndGetTree(t, repo, "file", "a")
|
||||||
|
defer commitA.Free()
|
||||||
|
defer treeA.Free()
|
||||||
|
commitB, treeB := addAndGetTree(t, repo, "file", "b")
|
||||||
|
defer commitB.Free()
|
||||||
|
defer treeB.Free()
|
||||||
|
commitC, treeC := addAndGetTree(t, repo, "file", "c")
|
||||||
|
defer commitC.Free()
|
||||||
|
defer treeC.Free()
|
||||||
|
|
||||||
|
diffAB, err := repo.DiffTreeToTree(treeA, treeB, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
diffAC, err := repo.DiffTreeToTree(treeA, treeC, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
errMessageDropped := errors.New("message dropped")
|
||||||
|
|
||||||
|
for _, tc := range []struct {
|
||||||
|
name string
|
||||||
|
tree *Tree
|
||||||
|
diff *Diff
|
||||||
|
applyHunkCallback ApplyHunkCallback
|
||||||
|
applyDeltaCallback ApplyDeltaCallback
|
||||||
|
err error
|
||||||
|
expectedDiff *Diff
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "applying patch produces the same diff",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
expectedDiff: diffAB,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "applying a conflicting patch errors",
|
||||||
|
tree: treeB,
|
||||||
|
diff: diffAC,
|
||||||
|
err: &GitError{
|
||||||
|
Message: "hunk at line 1 did not apply",
|
||||||
|
Code: ErrorCodeApplyFail,
|
||||||
|
Class: ErrorClassPatch,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "callbacks succeeding apply the diff",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
applyHunkCallback: func(*DiffHunk) (bool, error) { return true, nil },
|
||||||
|
applyDeltaCallback: func(*DiffDelta) (bool, error) { return true, nil },
|
||||||
|
expectedDiff: diffAB,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hunk callback returning false does not apply",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
applyHunkCallback: func(*DiffHunk) (bool, error) { return false, nil },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hunk callback erroring fails the call",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
applyHunkCallback: func(*DiffHunk) (bool, error) { return true, errMessageDropped },
|
||||||
|
err: errMessageDropped,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "delta callback returning false does not apply",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
applyDeltaCallback: func(*DiffDelta) (bool, error) { return false, nil },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "delta callback erroring fails the call",
|
||||||
|
tree: treeA,
|
||||||
|
diff: diffAB,
|
||||||
|
applyDeltaCallback: func(*DiffDelta) (bool, error) { return true, errMessageDropped },
|
||||||
|
err: errMessageDropped,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
opts, err := DefaultApplyOptions()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
opts.ApplyHunkCallback = tc.applyHunkCallback
|
||||||
|
opts.ApplyDeltaCallback = tc.applyDeltaCallback
|
||||||
|
|
||||||
|
index, err := repo.ApplyToTree(tc.diff, tc.tree, opts)
|
||||||
|
if tc.err != nil {
|
||||||
|
if !reflect.DeepEqual(tc.err, err) {
|
||||||
|
t.Fatalf("expected error %q but got %q", tc.err, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
patchedTreeOID, err := index.WriteTreeTo(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
patchedTree, err := repo.LookupTree(patchedTreeOID)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
patchedDiff, err := repo.DiffTreeToTree(tc.tree, patchedTree, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
appliedRaw, err := patchedDiff.ToBuf(DiffFormatPatch)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if tc.expectedDiff == nil {
|
||||||
|
if len(appliedRaw) > 0 {
|
||||||
|
t.Fatalf("expected no diff but got: %s", appliedRaw)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedDiff, err := tc.expectedDiff.ToBuf(DiffFormatPatch)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if string(expectedDiff) != string(appliedRaw) {
|
||||||
|
t.Fatalf("diffs do not match:\nexpected: %s\n\nactual: %s", expectedDiff, appliedRaw)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkSecondFileStaged checks that there is a single file called "file2" uncommitted in the repo
|
||||||
|
func checkSecondFileStaged(t *testing.T, repo *Repository) {
|
||||||
|
opts := StatusOptions{
|
||||||
|
Show: StatusShowIndexAndWorkdir,
|
||||||
|
Flags: StatusOptIncludeUntracked,
|
||||||
|
}
|
||||||
|
|
||||||
|
statuses, err := repo.StatusList(&opts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
count, err := statuses.EntryCount()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if count != 1 {
|
||||||
|
t.Error("diff should affect exactly one file")
|
||||||
|
}
|
||||||
|
if count == 0 {
|
||||||
|
t.Fatal("no statuses, cannot continue test")
|
||||||
|
}
|
||||||
|
|
||||||
|
entry, err := statuses.ByIndex(0)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if entry.Status != StatusIndexNew {
|
||||||
|
t.Error("status should be 'new' as file has been added between commits")
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry.HeadToIndex.NewFile.Path != "file2" {
|
||||||
|
t.Error("new file should be 'file2")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkNoFilesStaged checks that there is a single file called "file2" uncommitted in the repo
|
||||||
|
func checkNoFilesStaged(t *testing.T, repo *Repository) {
|
||||||
|
opts := StatusOptions{
|
||||||
|
Show: StatusShowIndexAndWorkdir,
|
||||||
|
Flags: StatusOptIncludeUntracked,
|
||||||
|
}
|
||||||
|
|
||||||
|
statuses, err := repo.StatusList(&opts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
count, err := statuses.EntryCount()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
if count != 0 {
|
||||||
|
t.Error("files changed unexpectedly")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// addAndGetTree creates a file and commits it, returning the commit and tree
|
||||||
|
func addAndGetTree(t *testing.T, repo *Repository, filename string, content string) (*Commit, *Tree) {
|
||||||
|
headCommit, err := headCommit(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer headCommit.Free()
|
||||||
|
|
||||||
|
p := repo.Path()
|
||||||
|
p = strings.TrimSuffix(p, ".git")
|
||||||
|
p = strings.TrimSuffix(p, ".git/")
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(path.Join(p, filename), []byte((content)), 0777)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
index, err := repo.Index()
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer index.Free()
|
||||||
|
|
||||||
|
err = index.AddByPath(filename)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
newTreeOID, err := index.WriteTreeTo(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
newTree, err := repo.LookupTree(newTreeOID)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer newTree.Free()
|
||||||
|
|
||||||
|
commitId, err := repo.CreateCommit("HEAD", signature(), signature(), fmt.Sprintf("add %s", filename), newTree, headCommit)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
commit, err := repo.LookupCommit(commitId)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
tree, err := commit.Tree()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
return commit, tree
|
||||||
|
}
|
||||||
|
|
|
@ -36,24 +36,26 @@ func _() {
|
||||||
_ = x[ErrorCodeIterOver - -31]
|
_ = x[ErrorCodeIterOver - -31]
|
||||||
_ = x[ErrorCodeRetry - -32]
|
_ = x[ErrorCodeRetry - -32]
|
||||||
_ = x[ErrorCodeMismatch - -33]
|
_ = x[ErrorCodeMismatch - -33]
|
||||||
|
_ = x[ErrorCodeIndexDirty - -34]
|
||||||
|
_ = x[ErrorCodeApplyFail - -35]
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_ErrorCode_name_0 = "MismatchRetryIterOverPassthrough"
|
_ErrorCode_name_0 = "ApplyFailIndexDirtyMismatchRetryIterOverPassthrough"
|
||||||
_ErrorCode_name_1 = "MergeConflictDirectoryUncommittedInvalidEOFPeelAppliedCertificateAuthModifiedLockedConflictInvalidSpecNonFastForwardUnmergedUnbornBranchBareRepoUserBuffsAmbiguousExistsNotFound"
|
_ErrorCode_name_1 = "MergeConflictDirectoryUncommittedInvalidEOFPeelAppliedCertificateAuthModifiedLockedConflictInvalidSpecNonFastForwardUnmergedUnbornBranchBareRepoUserBuffsAmbiguousExistsNotFound"
|
||||||
_ErrorCode_name_2 = "GenericOK"
|
_ErrorCode_name_2 = "GenericOK"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ErrorCode_index_0 = [...]uint8{0, 8, 13, 21, 32}
|
_ErrorCode_index_0 = [...]uint8{0, 9, 19, 27, 32, 40, 51}
|
||||||
_ErrorCode_index_1 = [...]uint8{0, 13, 22, 33, 40, 43, 47, 54, 65, 69, 77, 83, 91, 102, 116, 124, 136, 144, 148, 153, 162, 168, 176}
|
_ErrorCode_index_1 = [...]uint8{0, 13, 22, 33, 40, 43, 47, 54, 65, 69, 77, 83, 91, 102, 116, 124, 136, 144, 148, 153, 162, 168, 176}
|
||||||
_ErrorCode_index_2 = [...]uint8{0, 7, 9}
|
_ErrorCode_index_2 = [...]uint8{0, 7, 9}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i ErrorCode) String() string {
|
func (i ErrorCode) String() string {
|
||||||
switch {
|
switch {
|
||||||
case -33 <= i && i <= -30:
|
case -35 <= i && i <= -30:
|
||||||
i -= -33
|
i -= -35
|
||||||
return _ErrorCode_name_0[_ErrorCode_index_0[i]:_ErrorCode_index_0[i+1]]
|
return _ErrorCode_name_0[_ErrorCode_index_0[i]:_ErrorCode_index_0[i+1]]
|
||||||
case -24 <= i && i <= -3:
|
case -24 <= i && i <= -3:
|
||||||
i -= -24
|
i -= -24
|
||||||
|
|
70
git.go
70
git.go
|
@ -18,35 +18,35 @@ import (
|
||||||
type ErrorClass int
|
type ErrorClass int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ErrorClassNone ErrorClass = C.GITERR_NONE
|
ErrorClassNone ErrorClass = C.GIT_ERROR_NONE
|
||||||
ErrorClassNoMemory ErrorClass = C.GITERR_NOMEMORY
|
ErrorClassNoMemory ErrorClass = C.GIT_ERROR_NOMEMORY
|
||||||
ErrorClassOS ErrorClass = C.GITERR_OS
|
ErrorClassOS ErrorClass = C.GIT_ERROR_OS
|
||||||
ErrorClassInvalid ErrorClass = C.GITERR_INVALID
|
ErrorClassInvalid ErrorClass = C.GIT_ERROR_INVALID
|
||||||
ErrorClassReference ErrorClass = C.GITERR_REFERENCE
|
ErrorClassReference ErrorClass = C.GIT_ERROR_REFERENCE
|
||||||
ErrorClassZlib ErrorClass = C.GITERR_ZLIB
|
ErrorClassZlib ErrorClass = C.GIT_ERROR_ZLIB
|
||||||
ErrorClassRepository ErrorClass = C.GITERR_REPOSITORY
|
ErrorClassRepository ErrorClass = C.GIT_ERROR_REPOSITORY
|
||||||
ErrorClassConfig ErrorClass = C.GITERR_CONFIG
|
ErrorClassConfig ErrorClass = C.GIT_ERROR_CONFIG
|
||||||
ErrorClassRegex ErrorClass = C.GITERR_REGEX
|
ErrorClassRegex ErrorClass = C.GIT_ERROR_REGEX
|
||||||
ErrorClassOdb ErrorClass = C.GITERR_ODB
|
ErrorClassOdb ErrorClass = C.GIT_ERROR_ODB
|
||||||
ErrorClassIndex ErrorClass = C.GITERR_INDEX
|
ErrorClassIndex ErrorClass = C.GIT_ERROR_INDEX
|
||||||
ErrorClassObject ErrorClass = C.GITERR_OBJECT
|
ErrorClassObject ErrorClass = C.GIT_ERROR_OBJECT
|
||||||
ErrorClassNet ErrorClass = C.GITERR_NET
|
ErrorClassNet ErrorClass = C.GIT_ERROR_NET
|
||||||
ErrorClassTag ErrorClass = C.GITERR_TAG
|
ErrorClassTag ErrorClass = C.GIT_ERROR_TAG
|
||||||
ErrorClassTree ErrorClass = C.GITERR_TREE
|
ErrorClassTree ErrorClass = C.GIT_ERROR_TREE
|
||||||
ErrorClassIndexer ErrorClass = C.GITERR_INDEXER
|
ErrorClassIndexer ErrorClass = C.GIT_ERROR_INDEXER
|
||||||
ErrorClassSSL ErrorClass = C.GITERR_SSL
|
ErrorClassSSL ErrorClass = C.GIT_ERROR_SSL
|
||||||
ErrorClassSubmodule ErrorClass = C.GITERR_SUBMODULE
|
ErrorClassSubmodule ErrorClass = C.GIT_ERROR_SUBMODULE
|
||||||
ErrorClassThread ErrorClass = C.GITERR_THREAD
|
ErrorClassThread ErrorClass = C.GIT_ERROR_THREAD
|
||||||
ErrorClassStash ErrorClass = C.GITERR_STASH
|
ErrorClassStash ErrorClass = C.GIT_ERROR_STASH
|
||||||
ErrorClassCheckout ErrorClass = C.GITERR_CHECKOUT
|
ErrorClassCheckout ErrorClass = C.GIT_ERROR_CHECKOUT
|
||||||
ErrorClassFetchHead ErrorClass = C.GITERR_FETCHHEAD
|
ErrorClassFetchHead ErrorClass = C.GIT_ERROR_FETCHHEAD
|
||||||
ErrorClassMerge ErrorClass = C.GITERR_MERGE
|
ErrorClassMerge ErrorClass = C.GIT_ERROR_MERGE
|
||||||
ErrorClassSSH ErrorClass = C.GITERR_SSH
|
ErrorClassSSH ErrorClass = C.GIT_ERROR_SSH
|
||||||
ErrorClassFilter ErrorClass = C.GITERR_FILTER
|
ErrorClassFilter ErrorClass = C.GIT_ERROR_FILTER
|
||||||
ErrorClassRevert ErrorClass = C.GITERR_REVERT
|
ErrorClassRevert ErrorClass = C.GIT_ERROR_REVERT
|
||||||
ErrorClassCallback ErrorClass = C.GITERR_CALLBACK
|
ErrorClassCallback ErrorClass = C.GIT_ERROR_CALLBACK
|
||||||
ErrorClassRebase ErrorClass = C.GITERR_REBASE
|
ErrorClassRebase ErrorClass = C.GIT_ERROR_REBASE
|
||||||
ErrorClassPatch ErrorClass = C.GITERR_PATCH
|
ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static
|
//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static
|
||||||
|
@ -115,6 +115,10 @@ const (
|
||||||
ErrorCodeRetry ErrorCode = C.GIT_RETRY
|
ErrorCodeRetry ErrorCode = C.GIT_RETRY
|
||||||
// ErrorCodeMismatch represents a hashsum mismatch in object.
|
// ErrorCodeMismatch represents a hashsum mismatch in object.
|
||||||
ErrorCodeMismatch ErrorCode = C.GIT_EMISMATCH
|
ErrorCodeMismatch ErrorCode = C.GIT_EMISMATCH
|
||||||
|
// ErrorCodeIndexDirty represents that unsaved changes in the index would be overwritten.
|
||||||
|
ErrorCodeIndexDirty ErrorCode = C.GIT_EINDEXDIRTY
|
||||||
|
// ErrorCodeApplyFail represents that a patch application failed.
|
||||||
|
ErrorCodeApplyFail ErrorCode = C.GIT_EAPPLYFAIL
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -167,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 git2go objects are live before calling this.
|
// references to any libgit2 go 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() {
|
||||||
|
@ -225,7 +229,7 @@ func NewOid(s string) (*Oid, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(slice) != 20 {
|
if len(slice) != 20 {
|
||||||
return nil, &GitError{"Invalid Oid", ErrorClassNone, ErrGeneric}
|
return nil, &GitError{"invalid oid", ErrorClassNone, ErrorCodeGeneric}
|
||||||
}
|
}
|
||||||
|
|
||||||
copy(o[:], slice[:20])
|
copy(o[:], slice[:20])
|
||||||
|
@ -317,7 +321,7 @@ func MakeGitError(c C.int) error {
|
||||||
var errClass ErrorClass
|
var errClass ErrorClass
|
||||||
errorCode := ErrorCode(c)
|
errorCode := ErrorCode(c)
|
||||||
if errorCode != ErrorCodeIterOver {
|
if errorCode != ErrorCodeIterOver {
|
||||||
err := C.giterr_last()
|
err := C.git_error_last()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMessage = C.GoString(err.message)
|
errMessage = C.GoString(err.message)
|
||||||
errClass = ErrorClass(err.klass)
|
errClass = ErrorClass(err.klass)
|
||||||
|
@ -368,7 +372,7 @@ func Discover(start string, across_fs bool, ceiling_dirs []string) (string, erro
|
||||||
defer C.free(unsafe.Pointer(cstart))
|
defer C.free(unsafe.Pointer(cstart))
|
||||||
|
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
9
go.mod
9
go.mod
|
@ -1,9 +0,0 @@
|
||||||
module github.com/libgit2/git2go/v27
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
13
go.sum
13
go.sum
|
@ -1,13 +0,0 @@
|
||||||
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,3 +40,30 @@ 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
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
13
http.go
13
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)
|
||||||
proxyOpts, err := transport.SmartProxyOptions()
|
remoteConnectOpts, err := transport.SmartRemoteConnectOptions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
switch proxyOpts.Type {
|
switch remoteConnectOpts.ProxyOptions.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(proxyOpts.Url)
|
parsedUrl, err := url.Parse(remoteConnectOpts.ProxyOptions.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 (git2go)")
|
req.Header.Set("User-Agent", "git/2.0 (libgit2)")
|
||||||
|
|
||||||
stream := newManagedHttpStream(t, req)
|
stream := newManagedHttpStream(t, req)
|
||||||
if req.Method == "POST" {
|
if req.Method == "POST" {
|
||||||
|
@ -203,7 +203,9 @@ 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
|
||||||
|
@ -216,10 +218,11 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
|
||||||
if resp.StatusCode == http.StatusUnauthorized {
|
if resp.StatusCode == http.StatusUnauthorized {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
cred, err := self.owner.transport.SmartCredentials("", CredTypeUserpassPlaintext)
|
cred, err := self.owner.transport.SmartCredentials("", CredentialTypeUserpassPlaintext)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cred.Free()
|
||||||
|
|
||||||
userName, password, err = cred.GetUserpassPlaintext()
|
userName, password, err = cred.GetUserpassPlaintext()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
11
index.go
11
index.go
|
@ -10,13 +10,12 @@ 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) int
|
type IndexMatchedPathCallback func(string, string) error
|
||||||
type indexMatchedPathCallbackData struct {
|
type indexMatchedPathCallbackData struct {
|
||||||
callback IndexMatchedPathCallback
|
callback IndexMatchedPathCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -220,7 +219,7 @@ func (v *Index) AddFromBuffer(entry *IndexEntry, buffer []byte) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
if err := C.git_index_add_frombuffer(v.ptr, ¢ry, cbuffer, C.size_t(len(buffer))); err < 0 {
|
if err := C.git_index_add_from_buffer(v.ptr, ¢ry, cbuffer, C.size_t(len(buffer))); err < 0 {
|
||||||
return MakeGitError(err)
|
return MakeGitError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,9 +342,9 @@ func indexMatchedPathCallback(cPath, cMatchedPathspec *C.char, payload unsafe.Po
|
||||||
panic("invalid matched path callback")
|
panic("invalid matched path callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callback(C.GoString(cPath), C.GoString(cMatchedPathspec))
|
err := data.callback(C.GoString(cPath), C.GoString(cMatchedPathspec))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
*data.errorTarget = err
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package git
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -59,14 +60,29 @@ func TestIndexWriteTreeTo(t *testing.T) {
|
||||||
repo := createTestRepo(t)
|
repo := createTestRepo(t)
|
||||||
defer cleanupTestRepo(t, repo)
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
||||||
repo2 := createTestRepo(t)
|
idx, err := NewIndex()
|
||||||
defer cleanupTestRepo(t, repo2)
|
checkFatal(t, err)
|
||||||
|
|
||||||
idx, err := repo.Index()
|
odb, err := repo.Odb()
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
err = idx.AddByPath("README")
|
|
||||||
|
content, err := ioutil.ReadFile(path.Join(repo.Workdir(), "README"))
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
treeId, err := idx.WriteTreeTo(repo2)
|
|
||||||
|
id, err := odb.Write(content, ObjectBlob)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
err = idx.Add(&IndexEntry{
|
||||||
|
Mode: FilemodeBlob,
|
||||||
|
Uid: 0,
|
||||||
|
Gid: 0,
|
||||||
|
Size: uint32(len(content)),
|
||||||
|
Id: id,
|
||||||
|
Path: "README",
|
||||||
|
})
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
treeId, err := idx.WriteTreeTo(repo)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
|
|
||||||
if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" {
|
if treeId.String() != "b7119b11e8ef7a1a5a34d3ac87f5b075228ac81e" {
|
||||||
|
@ -207,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) int {
|
err = idx.AddAll([]string{}, IndexAddDefault, func(p, mP string) error {
|
||||||
cbPath = p
|
cbPath = p
|
||||||
return 0
|
return nil
|
||||||
})
|
})
|
||||||
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) ErrorCode {
|
idx, err := NewIndexer(tmpPath, nil, func(stats TransferProgress) error {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return ErrorCodeOK
|
return nil
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer idx.Free()
|
defer idx.Free()
|
||||||
|
|
15
mempack.go
15
mempack.go
|
@ -6,7 +6,7 @@ package git
|
||||||
|
|
||||||
extern int git_mempack_new(git_odb_backend **out);
|
extern int git_mempack_new(git_odb_backend **out);
|
||||||
extern int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend);
|
extern int git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend);
|
||||||
extern void git_mempack_reset(git_odb_backend *backend);
|
extern int git_mempack_reset(git_odb_backend *backend);
|
||||||
extern void _go_git_odb_backend_free(git_odb_backend *backend);
|
extern void _go_git_odb_backend_free(git_odb_backend *backend);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
@ -71,7 +71,7 @@ func (mempack *Mempack) Dump(repository *Repository) ([]byte, error) {
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
return C.GoBytes(unsafe.Pointer(buf.ptr), C.int(buf.size)), nil
|
return C.GoBytes(unsafe.Pointer(buf.ptr), C.int(buf.size)), nil
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,13 @@ func (mempack *Mempack) Dump(repository *Repository) ([]byte, error) {
|
||||||
//
|
//
|
||||||
// This assumes that Mempack.Dump has been called before to store all the
|
// This assumes that Mempack.Dump has been called before to store all the
|
||||||
// queued objects into a single packfile.
|
// queued objects into a single packfile.
|
||||||
func (mempack *Mempack) Reset() {
|
func (mempack *Mempack) Reset() error {
|
||||||
C.git_mempack_reset(mempack.ptr)
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_mempack_reset(mempack.ptr)
|
||||||
|
if ret < 0 {
|
||||||
|
return MakeGitError(ret)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
14
merge.go
14
merge.go
|
@ -138,7 +138,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type MergeOptions struct {
|
type MergeOptions struct {
|
||||||
Version uint
|
|
||||||
TreeFlags MergeTreeFlag
|
TreeFlags MergeTreeFlag
|
||||||
|
|
||||||
RenameThreshold uint
|
RenameThreshold uint
|
||||||
|
@ -151,7 +150,6 @@ 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),
|
||||||
|
@ -166,7 +164,7 @@ func DefaultMergeOptions() (MergeOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_merge_init_options(&opts, C.GIT_MERGE_OPTIONS_VERSION)
|
ecode := C.git_merge_options_init(&opts, C.GIT_MERGE_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return MergeOptions{}, MakeGitError(ecode)
|
return MergeOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -174,11 +172,11 @@ func DefaultMergeOptions() (MergeOptions, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateMergeOptions(copts *C.git_merge_options, opts *MergeOptions) *C.git_merge_options {
|
func populateMergeOptions(copts *C.git_merge_options, opts *MergeOptions) *C.git_merge_options {
|
||||||
C.git_merge_init_options(copts, C.GIT_MERGE_OPTIONS_VERSION)
|
C.git_merge_options_init(copts, C.GIT_MERGE_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.flags = C.git_merge_flag_t(opts.TreeFlags)
|
copts.flags = C.uint32_t(opts.TreeFlags)
|
||||||
copts.rename_threshold = C.uint(opts.RenameThreshold)
|
copts.rename_threshold = C.uint(opts.RenameThreshold)
|
||||||
copts.target_limit = C.uint(opts.TargetLimit)
|
copts.target_limit = C.uint(opts.TargetLimit)
|
||||||
copts.recursion_limit = C.uint(opts.RecursionLimit)
|
copts.recursion_limit = C.uint(opts.RecursionLimit)
|
||||||
|
@ -518,7 +516,7 @@ func mergeFileOptionsFromC(c C.git_merge_file_options) MergeFileOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateMergeFileOptions(copts *C.git_merge_file_options, opts *MergeFileOptions) *C.git_merge_file_options {
|
func populateMergeFileOptions(copts *C.git_merge_file_options, opts *MergeFileOptions) *C.git_merge_file_options {
|
||||||
C.git_merge_file_init_options(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
|
C.git_merge_file_options_init(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -527,7 +525,7 @@ func populateMergeFileOptions(copts *C.git_merge_file_options, opts *MergeFileOp
|
||||||
copts.our_label = C.CString(opts.OurLabel)
|
copts.our_label = C.CString(opts.OurLabel)
|
||||||
copts.their_label = C.CString(opts.TheirLabel)
|
copts.their_label = C.CString(opts.TheirLabel)
|
||||||
copts.favor = C.git_merge_file_favor_t(opts.Favor)
|
copts.favor = C.git_merge_file_favor_t(opts.Favor)
|
||||||
copts.flags = C.git_merge_file_flag_t(opts.Flags)
|
copts.flags = C.uint32_t(opts.Flags)
|
||||||
copts.marker_size = C.ushort(opts.MarkerSize)
|
copts.marker_size = C.ushort(opts.MarkerSize)
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
@ -567,7 +565,7 @@ func MergeFile(ancestor MergeFileInput, ours MergeFileInput, theirs MergeFileInp
|
||||||
var copts *C.git_merge_file_options
|
var copts *C.git_merge_file_options
|
||||||
if options != nil {
|
if options != nil {
|
||||||
copts = &C.git_merge_file_options{}
|
copts = &C.git_merge_file_options{}
|
||||||
ecode := C.git_merge_file_init_options(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
|
ecode := C.git_merge_file_options_init(copts, C.GIT_MERGE_FILE_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return nil, MakeGitError(ecode)
|
return nil, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
|
2
note.go
2
note.go
|
@ -133,7 +133,7 @@ func (c *NoteCollection) DefaultRef() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := C.GoString(buf.ptr)
|
ret := C.GoString(buf.ptr)
|
||||||
C.git_buf_free(&buf)
|
C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
20
object.go
20
object.go
|
@ -13,12 +13,12 @@ import (
|
||||||
type ObjectType int
|
type ObjectType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ObjectAny ObjectType = C.GIT_OBJ_ANY
|
ObjectAny ObjectType = C.GIT_OBJECT_ANY
|
||||||
ObjectBad ObjectType = C.GIT_OBJ_BAD
|
ObjectInvalid ObjectType = C.GIT_OBJECT_INVALID
|
||||||
ObjectCommit ObjectType = C.GIT_OBJ_COMMIT
|
ObjectCommit ObjectType = C.GIT_OBJECT_COMMIT
|
||||||
ObjectTree ObjectType = C.GIT_OBJ_TREE
|
ObjectTree ObjectType = C.GIT_OBJECT_TREE
|
||||||
ObjectBlob ObjectType = C.GIT_OBJ_BLOB
|
ObjectBlob ObjectType = C.GIT_OBJECT_BLOB
|
||||||
ObjectTag ObjectType = C.GIT_OBJ_TAG
|
ObjectTag ObjectType = C.GIT_OBJECT_TAG
|
||||||
)
|
)
|
||||||
|
|
||||||
type Object struct {
|
type Object struct {
|
||||||
|
@ -36,8 +36,8 @@ func (t ObjectType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case ObjectAny:
|
case ObjectAny:
|
||||||
return "Any"
|
return "Any"
|
||||||
case ObjectBad:
|
case ObjectInvalid:
|
||||||
return "Bad"
|
return "Invalid"
|
||||||
case ObjectCommit:
|
case ObjectCommit:
|
||||||
return "Commit"
|
return "Commit"
|
||||||
case ObjectTree:
|
case ObjectTree:
|
||||||
|
@ -68,7 +68,7 @@ func (o *Object) ShortId() (string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return "", MakeGitError(ecode)
|
return "", MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&resultBuf)
|
defer C.git_buf_dispose(&resultBuf)
|
||||||
return C.GoString(resultBuf.ptr), nil
|
return C.GoString(resultBuf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ func (o *Object) Peel(t ObjectType) (*Object, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C.git_object_peel(&cobj, o.ptr, C.git_otype(t))
|
err := C.git_object_peel(&cobj, o.ptr, C.git_object_t(t))
|
||||||
runtime.KeepAlive(o)
|
runtime.KeepAlive(o)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return nil, MakeGitError(err)
|
return nil, MakeGitError(err)
|
||||||
|
|
38
odb.go
38
odb.go
|
@ -118,12 +118,12 @@ func (v *Odb) ReadHeader(oid *Oid) (uint64, ObjectType, error) {
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
var sz C.size_t
|
var sz C.size_t
|
||||||
var cotype C.git_otype
|
var cotype C.git_object_t
|
||||||
|
|
||||||
ret := C.git_odb_read_header(&sz, &cotype, v.ptr, oid.toC())
|
ret := C.git_odb_read_header(&sz, &cotype, v.ptr, oid.toC())
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return 0, C.GIT_OBJ_BAD, MakeGitError(ret)
|
return 0, ObjectInvalid, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint64(sz), ObjectType(cotype), nil
|
return uint64(sz), ObjectType(cotype), nil
|
||||||
|
@ -150,7 +150,7 @@ func (v *Odb) Write(data []byte, otype ObjectType) (oid *Oid, err error) {
|
||||||
size = C.size_t(0)
|
size = C.size_t(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(&data[0]), size, C.git_otype(otype))
|
ret := C.git_odb_write(oid.toC(), v.ptr, unsafe.Pointer(&data[0]), size, C.git_object_t(otype))
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -176,6 +176,32 @@ 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
|
||||||
|
@ -237,7 +263,7 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
|
||||||
size = C.size_t(0)
|
size = C.size_t(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_otype(otype))
|
ret := C.git_odb_hash(oid.toC(), unsafe.Pointer(&data[0]), size, C.git_object_t(otype))
|
||||||
runtime.KeepAlive(data)
|
runtime.KeepAlive(data)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -249,7 +275,7 @@ func (v *Odb) Hash(data []byte, otype ObjectType) (oid *Oid, err error) {
|
||||||
// contents of the object.
|
// contents of the object.
|
||||||
func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
|
func (v *Odb) NewReadStream(id *Oid) (*OdbReadStream, error) {
|
||||||
stream := new(OdbReadStream)
|
stream := new(OdbReadStream)
|
||||||
var ctype C.git_otype
|
var ctype C.git_object_t
|
||||||
var csize C.size_t
|
var csize C.size_t
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
@ -277,7 +303,7 @@ func (v *Odb) NewWriteStream(size int64, otype ObjectType) (*OdbWriteStream, err
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_off_t(size), C.git_otype(otype))
|
ret := C.git_odb_open_wstream(&stream.ptr, v.ptr, C.git_object_size_t(size), C.git_object_t(otype))
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
|
|
@ -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) ErrorCode {
|
writepack, err := odb.NewWritePack(func(stats TransferProgress) error {
|
||||||
finalStats = stats
|
finalStats = stats
|
||||||
return ErrorCodeOK
|
return nil
|
||||||
})
|
})
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer writepack.Free()
|
defer writepack.Free()
|
||||||
|
|
2
patch.go
2
patch.go
|
@ -52,7 +52,7 @@ func (patch *Patch) String() (string, error) {
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return "", MakeGitError(ecode)
|
return "", MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
return C.GoString(buf.ptr), nil
|
return C.GoString(buf.ptr), nil
|
||||||
}
|
}
|
||||||
|
|
153
rebase.go
153
rebase.go
|
@ -2,11 +2,14 @@ package git
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
|
extern void _go_git_populate_rebase_callbacks(git_rebase_options *opts);
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -69,18 +72,140 @@ func newRebaseOperationFromC(c *C.git_rebase_operation) *RebaseOperation {
|
||||||
return operation
|
return operation
|
||||||
}
|
}
|
||||||
|
|
||||||
// RebaseOptions are used to tell the rebase machinery how to operate
|
//export commitCreateCallback
|
||||||
|
func commitCreateCallback(
|
||||||
|
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)
|
||||||
|
if !ok {
|
||||||
|
panic("invalid sign payload")
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.options.CommitCreateCallback == nil && data.options.CommitSigningCallback == nil {
|
||||||
|
return C.int(ErrorCodePassthrough)
|
||||||
|
}
|
||||||
|
|
||||||
|
messageEncoding := MessageEncodingUTF8
|
||||||
|
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
|
||||||
|
if _parent_count > 0 {
|
||||||
|
hdr := reflect.SliceHeader{
|
||||||
|
Data: uintptr(unsafe.Pointer(_parents)),
|
||||||
|
Len: int(_parent_count),
|
||||||
|
Cap: int(_parent_count),
|
||||||
|
}
|
||||||
|
goParents = *(*[]*C.git_commit)(unsafe.Pointer(&hdr))
|
||||||
|
}
|
||||||
|
|
||||||
|
parents := make([]*Commit, int(_parent_count))
|
||||||
|
for i, p := range goParents {
|
||||||
|
parents[i] = &Commit{
|
||||||
|
Object: Object{
|
||||||
|
ptr: (*C.git_object)(p),
|
||||||
|
repo: data.repo,
|
||||||
|
},
|
||||||
|
cast_ptr: p,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if data.options.CommitCreateCallback != nil {
|
||||||
|
oid, err := data.options.CommitCreateCallback(
|
||||||
|
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 data.errorTarget != nil {
|
||||||
|
*data.errorTarget = err
|
||||||
|
}
|
||||||
|
return setCallbackError(errorMessage, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
signature, signatureField, err := data.options.CommitSigningCallback(string(commitContent))
|
||||||
|
if err != nil {
|
||||||
|
if data.errorTarget != nil {
|
||||||
|
*data.errorTarget = 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RebaseOptions are used to tell the rebase machinery how to operate.
|
||||||
type RebaseOptions struct {
|
type RebaseOptions struct {
|
||||||
Version uint
|
|
||||||
Quiet int
|
Quiet int
|
||||||
InMemory int
|
InMemory int
|
||||||
RewriteNotesRef string
|
RewriteNotesRef string
|
||||||
MergeOptions MergeOptions
|
MergeOptions MergeOptions
|
||||||
CheckoutOptions CheckoutOptions
|
CheckoutOptions CheckoutOptions
|
||||||
|
// CommitCreateCallback is an optional callback that allows users to override
|
||||||
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
type rebaseOptionsData struct {
|
type rebaseOptionsData struct {
|
||||||
options *RebaseOptions
|
options *RebaseOptions
|
||||||
|
repo *Repository
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +216,7 @@ func DefaultRebaseOptions() (RebaseOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_rebase_init_options(&opts, C.GIT_REBASE_OPTIONS_VERSION)
|
ecode := C.git_rebase_options_init(&opts, C.GIT_REBASE_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return RebaseOptions{}, MakeGitError(ecode)
|
return RebaseOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +225,6 @@ 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),
|
||||||
|
@ -109,8 +233,8 @@ func rebaseOptionsFromC(opts *C.git_rebase_options) RebaseOptions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, errorTarget *error) *C.git_rebase_options {
|
func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, repo *Repository, errorTarget *error) *C.git_rebase_options {
|
||||||
C.git_rebase_init_options(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
|
||||||
}
|
}
|
||||||
|
@ -121,6 +245,16 @@ func populateRebaseOptions(copts *C.git_rebase_options, opts *RebaseOptions, err
|
||||||
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 {
|
||||||
|
data := &rebaseOptionsData{
|
||||||
|
options: opts,
|
||||||
|
repo: repo,
|
||||||
|
errorTarget: errorTarget,
|
||||||
|
}
|
||||||
|
C._go_git_populate_rebase_callbacks(copts)
|
||||||
|
copts.payload = pointerHandles.Track(data)
|
||||||
|
}
|
||||||
|
|
||||||
return copts
|
return copts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +265,9 @@ func freeRebaseOptions(copts *C.git_rebase_options) {
|
||||||
C.free(unsafe.Pointer(copts.rewrite_notes_ref))
|
C.free(unsafe.Pointer(copts.rewrite_notes_ref))
|
||||||
freeMergeOptions(&copts.merge_options)
|
freeMergeOptions(&copts.merge_options)
|
||||||
freeCheckoutOptions(&copts.checkout_options)
|
freeCheckoutOptions(&copts.checkout_options)
|
||||||
|
if copts.payload != nil {
|
||||||
|
pointerHandles.Untrack(copts.payload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapEmptyStringToNull(ref string) *C.char {
|
func mapEmptyStringToNull(ref string) *C.char {
|
||||||
|
@ -167,7 +304,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, &err)
|
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, r, &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)
|
||||||
|
@ -191,7 +328,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, &err)
|
cOpts := populateRebaseOptions(&C.git_rebase_options{}, opts, r, &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 {
|
||||||
|
|
122
rebase_test.go
122
rebase_test.go
|
@ -1,10 +1,15 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ProtonMail/go-crypto/openpgp"
|
||||||
|
"github.com/ProtonMail/go-crypto/openpgp/packet"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
@ -206,6 +211,123 @@ func TestRebaseNoConflicts(t *testing.T) {
|
||||||
assertStringList(t, expectedHistory, actualHistory)
|
assertStringList(t, expectedHistory, actualHistory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRebaseGpgSigned(t *testing.T) {
|
||||||
|
// TEST DATA
|
||||||
|
|
||||||
|
entity, err := openpgp.NewEntity("Namey mcnameface", "test comment", "test@example.com", nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
rebaseOpts, err := DefaultRebaseOptions()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
signCommitContent := func(commitContent string) (string, string, error) {
|
||||||
|
cipherText := new(bytes.Buffer)
|
||||||
|
err := openpgp.ArmoredDetachSignText(cipherText, entity, strings.NewReader(commitContent), &packet.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return "", "", errors.New("error signing payload")
|
||||||
|
}
|
||||||
|
|
||||||
|
return cipherText.String(), "", nil
|
||||||
|
}
|
||||||
|
rebaseOpts.CommitSigningCallback = signCommitContent
|
||||||
|
|
||||||
|
commitOpts := commitOptions{
|
||||||
|
CommitSigningCallback: signCommitContent,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inputs
|
||||||
|
branchName := "emile"
|
||||||
|
masterCommit := "something"
|
||||||
|
emileCommits := []string{
|
||||||
|
"fou",
|
||||||
|
"barre",
|
||||||
|
"ouich",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outputs
|
||||||
|
expectedHistory := []string{
|
||||||
|
"Test rebase, Baby! " + emileCommits[2],
|
||||||
|
"Test rebase, Baby! " + emileCommits[1],
|
||||||
|
"Test rebase, Baby! " + emileCommits[0],
|
||||||
|
"Test rebase, Baby! " + masterCommit,
|
||||||
|
"This is a commit\n",
|
||||||
|
}
|
||||||
|
|
||||||
|
// TEST
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer cleanupTestRepo(t, repo)
|
||||||
|
seedTestRepoOpt(t, repo, commitOpts)
|
||||||
|
|
||||||
|
// Try to open existing rebase
|
||||||
|
_, err = repo.OpenRebase(nil)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Did not expect to find a rebase in progress")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup a repo with 2 branches and a different tree
|
||||||
|
err = setupRepoForRebase(repo, masterCommit, branchName, commitOpts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
// Create several commits in emile
|
||||||
|
for _, commit := range emileCommits {
|
||||||
|
_, err = commitSomething(repo, commit, commit, commitOpts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rebase onto master
|
||||||
|
rebase, err := performRebaseOnto(repo, "master", &rebaseOpts)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer rebase.Free()
|
||||||
|
|
||||||
|
// Finish the rebase properly
|
||||||
|
err = rebase.Finish()
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
// Check history is in correct order
|
||||||
|
actualHistory, err := commitMsgsList(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
assertStringList(t, expectedHistory, actualHistory)
|
||||||
|
|
||||||
|
checkAllCommitsSigned(t, entity, repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkAllCommitsSigned(t *testing.T, entity *openpgp.Entity, repo *Repository) {
|
||||||
|
head, err := headCommit(repo)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer head.Free()
|
||||||
|
|
||||||
|
parent := head
|
||||||
|
|
||||||
|
err = checkCommitSigned(t, entity, parent)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
for parent.ParentCount() != 0 {
|
||||||
|
parent = parent.Parent(0)
|
||||||
|
defer parent.Free()
|
||||||
|
|
||||||
|
err = checkCommitSigned(t, entity, parent)
|
||||||
|
checkFatal(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkCommitSigned(t *testing.T, entity *openpgp.Entity, commit *Commit) error {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
signature, signedData, err := commit.ExtractSignature()
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("No signature on commit\n%s", commit.ContentToSign())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature), nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, commitOpts commitOptions) error {
|
func setupRepoForRebase(repo *Repository, masterCommit, branchName string, commitOpts commitOptions) error {
|
||||||
// Create a new branch from master
|
// Create a new branch from master
|
||||||
|
|
24
reference.go
24
reference.go
|
@ -286,7 +286,7 @@ func (v *Reference) Peel(t ObjectType) (*Object, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C.git_reference_peel(&cobj, v.ptr, C.git_otype(t))
|
err := C.git_reference_peel(&cobj, v.ptr, C.git_object_t(t))
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return nil, MakeGitError(err)
|
return nil, MakeGitError(err)
|
||||||
|
@ -476,7 +476,7 @@ func (v *ReferenceIterator) Free() {
|
||||||
C.git_reference_iterator_free(v.ptr)
|
C.git_reference_iterator_free(v.ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReferenceIsValidName returns whether the reference name is well-formed.
|
// ReferenceNameIsValid 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,11 +486,19 @@ 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 ReferenceIsValidName(name string) bool {
|
func ReferenceNameIsValid(name string) (bool, error) {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
return C.git_reference_is_valid_name(cname) == 1
|
runtime.LockOSThread()
|
||||||
|
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 (
|
||||||
|
@ -501,10 +509,10 @@ const (
|
||||||
type ReferenceFormat uint
|
type ReferenceFormat uint
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReferenceFormatNormal ReferenceFormat = C.GIT_REF_FORMAT_NORMAL
|
ReferenceFormatNormal ReferenceFormat = C.GIT_REFERENCE_FORMAT_NORMAL
|
||||||
ReferenceFormatAllowOnelevel ReferenceFormat = C.GIT_REF_FORMAT_ALLOW_ONELEVEL
|
ReferenceFormatAllowOnelevel ReferenceFormat = C.GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL
|
||||||
ReferenceFormatRefspecPattern ReferenceFormat = C.GIT_REF_FORMAT_REFSPEC_PATTERN
|
ReferenceFormatRefspecPattern ReferenceFormat = C.GIT_REFERENCE_FORMAT_REFSPEC_PATTERN
|
||||||
ReferenceFormatRefspecShorthand ReferenceFormat = C.GIT_REF_FORMAT_REFSPEC_SHORTHAND
|
ReferenceFormatRefspecShorthand ReferenceFormat = C.GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReferenceNormalizeName normalizes the reference name and checks validity.
|
// ReferenceNormalizeName normalizes the reference name and checks validity.
|
||||||
|
|
|
@ -214,12 +214,16 @@ func TestIsNote(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReferenceIsValidName(t *testing.T) {
|
func TestReferenceNameIsValid(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
if !ReferenceIsValidName("HEAD") {
|
valid, err := ReferenceNameIsValid("HEAD")
|
||||||
|
checkFatal(t, err)
|
||||||
|
if !valid {
|
||||||
t.Errorf("HEAD should be a valid reference name")
|
t.Errorf("HEAD should be a valid reference name")
|
||||||
}
|
}
|
||||||
if ReferenceIsValidName("HEAD1") {
|
valid, err = ReferenceNameIsValid("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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,149 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <git2.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Refspec struct {
|
||||||
|
doNotCompare
|
||||||
|
ptr *C.git_refspec
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseRefspec parses a given refspec string
|
||||||
|
func ParseRefspec(input string, isFetch bool) (*Refspec, error) {
|
||||||
|
var ptr *C.git_refspec
|
||||||
|
|
||||||
|
cinput := C.CString(input)
|
||||||
|
defer C.free(unsafe.Pointer(cinput))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_refspec_parse(&ptr, cinput, cbool(isFetch))
|
||||||
|
if ret < 0 {
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
spec := &Refspec{ptr: ptr}
|
||||||
|
runtime.SetFinalizer(spec, (*Refspec).Free)
|
||||||
|
return spec, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free releases a refspec object which has been created by ParseRefspec
|
||||||
|
func (s *Refspec) Free() {
|
||||||
|
runtime.SetFinalizer(s, nil)
|
||||||
|
C.git_refspec_free(s.ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Direction returns the refspec's direction
|
||||||
|
func (s *Refspec) Direction() ConnectDirection {
|
||||||
|
direction := C.git_refspec_direction(s.ptr)
|
||||||
|
return ConnectDirection(direction)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Src returns the refspec's source specifier
|
||||||
|
func (s *Refspec) Src() string {
|
||||||
|
var ret string
|
||||||
|
cstr := C.git_refspec_src(s.ptr)
|
||||||
|
|
||||||
|
if cstr != nil {
|
||||||
|
ret = C.GoString(cstr)
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.KeepAlive(s)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dst returns the refspec's destination specifier
|
||||||
|
func (s *Refspec) Dst() string {
|
||||||
|
var ret string
|
||||||
|
cstr := C.git_refspec_dst(s.ptr)
|
||||||
|
|
||||||
|
if cstr != nil {
|
||||||
|
ret = C.GoString(cstr)
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.KeepAlive(s)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force returns the refspec's force-update setting
|
||||||
|
func (s *Refspec) Force() bool {
|
||||||
|
force := C.git_refspec_force(s.ptr)
|
||||||
|
return force != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the refspec's string representation
|
||||||
|
func (s *Refspec) String() string {
|
||||||
|
var ret string
|
||||||
|
cstr := C.git_refspec_string(s.ptr)
|
||||||
|
|
||||||
|
if cstr != nil {
|
||||||
|
ret = C.GoString(cstr)
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.KeepAlive(s)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
// SrcMatches checks if a refspec's source descriptor matches a reference
|
||||||
|
func (s *Refspec) SrcMatches(refname string) bool {
|
||||||
|
cname := C.CString(refname)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
matches := C.git_refspec_src_matches(s.ptr, cname)
|
||||||
|
return matches != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// SrcMatches checks if a refspec's destination descriptor matches a reference
|
||||||
|
func (s *Refspec) DstMatches(refname string) bool {
|
||||||
|
cname := C.CString(refname)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
matches := C.git_refspec_dst_matches(s.ptr, cname)
|
||||||
|
return matches != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transform a reference to its target following the refspec's rules
|
||||||
|
func (s *Refspec) Transform(refname string) (string, error) {
|
||||||
|
buf := C.git_buf{}
|
||||||
|
|
||||||
|
cname := C.CString(refname)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_refspec_transform(&buf, s.ptr, cname)
|
||||||
|
if ret < 0 {
|
||||||
|
return "", MakeGitError(ret)
|
||||||
|
}
|
||||||
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
|
return C.GoString(buf.ptr), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rtransform converts a target reference to its source reference following the
|
||||||
|
// refspec's rules
|
||||||
|
func (s *Refspec) Rtransform(refname string) (string, error) {
|
||||||
|
buf := C.git_buf{}
|
||||||
|
|
||||||
|
cname := C.CString(refname)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_refspec_rtransform(&buf, s.ptr, cname)
|
||||||
|
if ret < 0 {
|
||||||
|
return "", MakeGitError(ret)
|
||||||
|
}
|
||||||
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
|
return C.GoString(buf.ptr), nil
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRefspec(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const (
|
||||||
|
input = "+refs/heads/*:refs/remotes/origin/*"
|
||||||
|
mainLocal = "refs/heads/main"
|
||||||
|
mainRemote = "refs/remotes/origin/main"
|
||||||
|
)
|
||||||
|
|
||||||
|
refspec, err := ParseRefspec(input, true)
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
|
||||||
|
s := refspec.String()
|
||||||
|
if s != input {
|
||||||
|
t.Errorf("expected string %q, got %q", input, s)
|
||||||
|
}
|
||||||
|
|
||||||
|
if d := refspec.Direction(); d != ConnectDirectionFetch {
|
||||||
|
t.Errorf("expected fetch refspec, got direction %v", d)
|
||||||
|
}
|
||||||
|
|
||||||
|
if pat, expected := refspec.Src(), "refs/heads/*"; pat != expected {
|
||||||
|
t.Errorf("expected refspec src %q, got %q", expected, pat)
|
||||||
|
}
|
||||||
|
|
||||||
|
if pat, expected := refspec.Dst(), "refs/remotes/origin/*"; pat != expected {
|
||||||
|
t.Errorf("expected refspec dst %q, got %q", expected, pat)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !refspec.Force() {
|
||||||
|
t.Error("expected refspec force flag")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SrcMatches
|
||||||
|
|
||||||
|
if !refspec.SrcMatches(mainLocal) {
|
||||||
|
t.Errorf("refspec source did not match %q", mainLocal)
|
||||||
|
}
|
||||||
|
|
||||||
|
if refspec.SrcMatches("refs/tags/v1.0") {
|
||||||
|
t.Error("refspec source matched under refs/tags")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DstMatches
|
||||||
|
|
||||||
|
if !refspec.DstMatches(mainRemote) {
|
||||||
|
t.Errorf("refspec destination did not match %q", mainRemote)
|
||||||
|
}
|
||||||
|
|
||||||
|
if refspec.DstMatches("refs/tags/v1.0") {
|
||||||
|
t.Error("refspec destination matched under refs/tags")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transforms
|
||||||
|
|
||||||
|
fromLocal, err := refspec.Transform(mainLocal)
|
||||||
|
checkFatal(t, err)
|
||||||
|
if fromLocal != mainRemote {
|
||||||
|
t.Errorf("transform by refspec returned %s; expected %s", fromLocal, mainRemote)
|
||||||
|
}
|
||||||
|
|
||||||
|
fromRemote, err := refspec.Rtransform(mainRemote)
|
||||||
|
checkFatal(t, err)
|
||||||
|
if fromRemote != mainLocal {
|
||||||
|
t.Errorf("rtransform by refspec returned %s; expected %s", fromRemote, mainLocal)
|
||||||
|
}
|
||||||
|
}
|
229
remote.go
229
remote.go
|
@ -4,6 +4,7 @@ package git
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
#include <git2/sys/cred.h>
|
||||||
|
|
||||||
extern void _go_git_populate_remote_callbacks(git_remote_callbacks *callbacks);
|
extern void _go_git_populate_remote_callbacks(git_remote_callbacks *callbacks);
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +12,7 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -20,6 +22,23 @@ import (
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RemoteCreateOptionsFlag is Remote creation options flags
|
||||||
|
type RemoteCreateOptionsFlag uint
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Ignore the repository apply.insteadOf configuration
|
||||||
|
RemoteCreateSkipInsteadof RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_INSTEADOF
|
||||||
|
// Don't build a fetchspec from the name if none is set
|
||||||
|
RemoteCreateSkipDefaultFetchspec RemoteCreateOptionsFlag = C.GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC
|
||||||
|
)
|
||||||
|
|
||||||
|
// RemoteCreateOptions contains options for creating a remote
|
||||||
|
type RemoteCreateOptions struct {
|
||||||
|
Name string
|
||||||
|
FetchSpec string
|
||||||
|
Flags RemoteCreateOptionsFlag
|
||||||
|
}
|
||||||
|
|
||||||
type TransferProgress struct {
|
type TransferProgress struct {
|
||||||
TotalObjects uint
|
TotalObjects uint
|
||||||
IndexedObjects uint
|
IndexedObjects uint
|
||||||
|
@ -51,15 +70,15 @@ const (
|
||||||
ConnectDirectionPush ConnectDirection = C.GIT_DIRECTION_PUSH
|
ConnectDirectionPush ConnectDirection = C.GIT_DIRECTION_PUSH
|
||||||
)
|
)
|
||||||
|
|
||||||
type TransportMessageCallback func(str string) ErrorCode
|
type TransportMessageCallback func(str string) error
|
||||||
type CompletionCallback func(RemoteCompletion) ErrorCode
|
type CompletionCallback func(RemoteCompletion) error
|
||||||
type CredentialsCallback func(url string, username_from_url string, allowed_types CredType) (ErrorCode, *Cred)
|
type CredentialsCallback func(url string, username_from_url string, allowed_types CredentialType) (*Credential, error)
|
||||||
type TransferProgressCallback func(stats TransferProgress) ErrorCode
|
type TransferProgressCallback func(stats TransferProgress) error
|
||||||
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) ErrorCode
|
type UpdateTipsCallback func(refname string, a *Oid, b *Oid) error
|
||||||
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) ErrorCode
|
type CertificateCheckCallback func(cert *Certificate, valid bool, hostname string) error
|
||||||
type PackbuilderProgressCallback func(stage int32, current, total uint32) ErrorCode
|
type PackbuilderProgressCallback func(stage int32, current, total uint32) error
|
||||||
type PushTransferProgressCallback func(current, total uint32, bytes uint) ErrorCode
|
type PushTransferProgressCallback func(current, total uint32, bytes uint) error
|
||||||
type PushUpdateReferenceCallback func(refname, status string) ErrorCode
|
type PushUpdateReferenceCallback func(refname, status string) error
|
||||||
|
|
||||||
type RemoteCallbacks struct {
|
type RemoteCallbacks struct {
|
||||||
SidebandProgressCallback TransportMessageCallback
|
SidebandProgressCallback TransportMessageCallback
|
||||||
|
@ -128,6 +147,17 @@ 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 (
|
||||||
|
@ -152,8 +182,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),
|
||||||
}
|
}
|
||||||
|
@ -164,6 +194,9 @@ type Remote struct {
|
||||||
ptr *C.git_remote
|
ptr *C.git_remote
|
||||||
callbacks RemoteCallbacks
|
callbacks RemoteCallbacks
|
||||||
repo *Repository
|
repo *Repository
|
||||||
|
// weak indicates that a remote is a weak pointer and should not be
|
||||||
|
// freed.
|
||||||
|
weak bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type remotePointerList struct {
|
type remotePointerList struct {
|
||||||
|
@ -234,7 +267,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 fille.d
|
// field will be filled.
|
||||||
type Certificate struct {
|
type Certificate struct {
|
||||||
Kind CertificateKind
|
Kind CertificateKind
|
||||||
X509 *x509.Certificate
|
X509 *x509.Certificate
|
||||||
|
@ -247,8 +280,8 @@ type HostkeyKind uint
|
||||||
const (
|
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 = 1 << 2
|
HostkeySHA256 HostkeyKind = C.GIT_CERT_SSH_SHA256
|
||||||
HostkeyRaw HostkeyKind = 1 << 3
|
HostkeyRaw HostkeyKind = C.GIT_CERT_SSH_RAW
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server host key information. A bitmask containing the available fields.
|
// Server host key information. A bitmask containing the available fields.
|
||||||
|
@ -314,10 +347,8 @@ 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)
|
||||||
}
|
}
|
||||||
str := C.GoStringN(_str, _len)
|
err := data.callbacks.SidebandProgressCallback(C.GoStringN(_str, _len))
|
||||||
ret := data.callbacks.SidebandProgressCallback(str)
|
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
|
||||||
}
|
}
|
||||||
|
@ -327,14 +358,13 @@ func sidebandProgressCallback(errorMessage **C.char, _str *C.char, _len C.int, h
|
||||||
}
|
}
|
||||||
|
|
||||||
//export completionCallback
|
//export completionCallback
|
||||||
func completionCallback(errorMessage **C.char, completion_type C.git_remote_completion_type, handle unsafe.Pointer) C.int {
|
func completionCallback(errorMessage **C.char, completionType 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)
|
||||||
}
|
}
|
||||||
ret := data.callbacks.CompletionCallback(RemoteCompletion(completion_type))
|
err := data.callbacks.CompletionCallback(RemoteCompletion(completionType))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -346,7 +376,7 @@ func completionCallback(errorMessage **C.char, completion_type C.git_remote_comp
|
||||||
//export credentialsCallback
|
//export credentialsCallback
|
||||||
func credentialsCallback(
|
func credentialsCallback(
|
||||||
errorMessage **C.char,
|
errorMessage **C.char,
|
||||||
_cred **C.git_cred,
|
_cred **C.git_credential,
|
||||||
_url *C.char,
|
_url *C.char,
|
||||||
_username_from_url *C.char,
|
_username_from_url *C.char,
|
||||||
allowed_types uint,
|
allowed_types uint,
|
||||||
|
@ -358,9 +388,8 @@ func credentialsCallback(
|
||||||
}
|
}
|
||||||
url := C.GoString(_url)
|
url := C.GoString(_url)
|
||||||
username_from_url := C.GoString(_username_from_url)
|
username_from_url := C.GoString(_username_from_url)
|
||||||
ret, cred := data.callbacks.CredentialsCallback(url, username_from_url, (CredType)(allowed_types))
|
cred, err := data.callbacks.CredentialsCallback(url, username_from_url, (CredentialType)(allowed_types))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -382,9 +411,8 @@ 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)
|
||||||
}
|
}
|
||||||
ret := data.callbacks.TransferProgressCallback(newTransferProgressFromC(stats))
|
err := data.callbacks.TransferProgressCallback(newTransferProgressFromC(stats))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -408,9 +436,8 @@ func updateTipsCallback(
|
||||||
refname := C.GoString(_refname)
|
refname := C.GoString(_refname)
|
||||||
a := newOidFromC(_a)
|
a := newOidFromC(_a)
|
||||||
b := newOidFromC(_b)
|
b := newOidFromC(_b)
|
||||||
ret := data.callbacks.UpdateTipsCallback(refname, a, b)
|
err := data.callbacks.UpdateTipsCallback(refname, a, b)
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -466,6 +493,18 @@ func certificateCheckCallback(
|
||||||
cert.Hostkey.Kind = HostkeyKind(ccert._type)
|
cert.Hostkey.Kind = HostkeyKind(ccert._type)
|
||||||
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)))
|
||||||
|
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 {
|
||||||
|
@ -474,9 +513,8 @@ func certificateCheckCallback(
|
||||||
return setCallbackError(errorMessage, err)
|
return setCallbackError(errorMessage, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callbacks.CertificateCheckCallback(&cert, valid, host)
|
err := data.callbacks.CertificateCheckCallback(&cert, valid, host)
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -492,9 +530,8 @@ func packProgressCallback(errorMessage **C.char, stage C.int, current, total C.u
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callbacks.PackProgressCallback(int32(stage), uint32(current), uint32(total))
|
err := data.callbacks.PackProgressCallback(int32(stage), uint32(current), uint32(total))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -510,9 +547,8 @@ func pushTransferProgressCallback(errorMessage **C.char, current, total C.uint,
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callbacks.PushTransferProgressCallback(uint32(current), uint32(total), uint(bytes))
|
err := data.callbacks.PushTransferProgressCallback(uint32(current), uint32(total), uint(bytes))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -528,9 +564,8 @@ func pushUpdateReferenceCallback(errorMessage **C.char, refname, status *C.char,
|
||||||
return C.int(ErrorCodeOK)
|
return C.int(ErrorCodeOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callbacks.PushUpdateReferenceCallback(C.GoString(refname), C.GoString(status))
|
err := data.callbacks.PushUpdateReferenceCallback(C.GoString(refname), C.GoString(status))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
err := errors.New(ErrorCode(ret).String())
|
|
||||||
if data.errorTarget != nil {
|
if data.errorTarget != nil {
|
||||||
*data.errorTarget = err
|
*data.errorTarget = err
|
||||||
}
|
}
|
||||||
|
@ -540,7 +575,7 @@ func pushUpdateReferenceCallback(errorMessage **C.char, refname, status *C.char,
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateProxyOptions(copts *C.git_proxy_options, opts *ProxyOptions) *C.git_proxy_options {
|
func populateProxyOptions(copts *C.git_proxy_options, opts *ProxyOptions) *C.git_proxy_options {
|
||||||
C.git_proxy_init_options(copts, C.GIT_PROXY_OPTIONS_VERSION)
|
C.git_proxy_options_init(copts, C.GIT_PROXY_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -558,12 +593,20 @@ func freeProxyOptions(copts *C.git_proxy_options) {
|
||||||
C.free(unsafe.Pointer(copts.url))
|
C.free(unsafe.Pointer(copts.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteIsValidName returns whether the remote name is well-formed.
|
// RemoteNameIsValid returns whether the remote name is well-formed.
|
||||||
func RemoteIsValidName(name string) bool {
|
func RemoteNameIsValid(name string) (bool, error) {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|
||||||
return C.git_remote_is_valid_name(cname) == 1
|
runtime.LockOSThread()
|
||||||
|
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.
|
||||||
|
@ -577,6 +620,9 @@ func (r *Remote) free() {
|
||||||
// Free releases the resources of the Remote.
|
// Free releases the resources of the Remote.
|
||||||
func (r *Remote) Free() {
|
func (r *Remote) Free() {
|
||||||
r.repo.Remotes.untrackRemote(r)
|
r.repo.Remotes.untrackRemote(r)
|
||||||
|
if r.weak {
|
||||||
|
return
|
||||||
|
}
|
||||||
r.free()
|
r.free()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,7 +661,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_free(&r)
|
defer C.git_strarray_dispose(&r)
|
||||||
|
|
||||||
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
remotes := makeStringsFromCStrings(r.strings, int(r.count))
|
||||||
return remotes, nil
|
return remotes, nil
|
||||||
|
@ -640,6 +686,28 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
|
||||||
return remote, nil
|
return remote, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateWithOptions Creates a repository object with extended options.
|
||||||
|
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
|
||||||
|
remote := &Remote{repo: c.repo}
|
||||||
|
|
||||||
|
curl := C.CString(url)
|
||||||
|
defer C.free(unsafe.Pointer(curl))
|
||||||
|
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
copts := populateRemoteCreateOptions(&C.git_remote_create_options{}, option, c.repo)
|
||||||
|
defer freeRemoteCreateOptions(copts)
|
||||||
|
|
||||||
|
ret := C.git_remote_create_with_opts(&remote.ptr, curl, copts)
|
||||||
|
runtime.KeepAlive(c.repo)
|
||||||
|
if ret < 0 {
|
||||||
|
return nil, MakeGitError(ret)
|
||||||
|
}
|
||||||
|
c.trackRemote(remote)
|
||||||
|
return remote, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *RemoteCollection) Delete(name string) error {
|
func (c *RemoteCollection) Delete(name string) error {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
@ -863,7 +931,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_free(&crefspecs)
|
defer C.git_strarray_dispose(&crefspecs)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
return refspecs, nil
|
return refspecs, nil
|
||||||
|
@ -896,7 +964,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_free(&crefspecs)
|
defer C.git_strarray_dispose(&crefspecs)
|
||||||
runtime.KeepAlive(o)
|
runtime.KeepAlive(o)
|
||||||
|
|
||||||
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
refspecs := makeStringsFromCStrings(crefspecs.strings, int(crefspecs.count))
|
||||||
|
@ -910,13 +978,15 @@ func (o *Remote) RefspecCount() uint {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorTarget *error) *C.git_fetch_options {
|
func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorTarget *error) *C.git_fetch_options {
|
||||||
C.git_fetch_init_options(copts, C.GIT_FETCH_OPTIONS_VERSION)
|
C.git_fetch_options_init(copts, C.GIT_FETCH_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
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)
|
||||||
copts.update_fetchhead = cbool(opts.UpdateFetchhead)
|
fmt.Println("populateFetchOptions() is broken. fixme!")
|
||||||
|
// 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{
|
||||||
|
@ -937,7 +1007,7 @@ func freeFetchOptions(copts *C.git_fetch_options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populatePushOptions(copts *C.git_push_options, opts *PushOptions, errorTarget *error) *C.git_push_options {
|
func populatePushOptions(copts *C.git_push_options, opts *PushOptions, errorTarget *error) *C.git_push_options {
|
||||||
C.git_push_init_options(copts, C.GIT_PUSH_OPTIONS_VERSION)
|
C.git_push_options_init(copts, C.GIT_PUSH_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1144,3 +1214,54 @@ func (o *Remote) Prune(callbacks *RemoteCallbacks) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultApplyOptions returns default options for remote create
|
||||||
|
func DefaultRemoteCreateOptions() (*RemoteCreateOptions, error) {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
opts := C.git_remote_create_options{}
|
||||||
|
ecode := C.git_remote_create_options_init(&opts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION)
|
||||||
|
if ecode < 0 {
|
||||||
|
return nil, MakeGitError(ecode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &RemoteCreateOptions{
|
||||||
|
Flags: RemoteCreateOptionsFlag(opts.flags),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func populateRemoteCreateOptions(copts *C.git_remote_create_options, opts *RemoteCreateOptions, repo *Repository) *C.git_remote_create_options {
|
||||||
|
C.git_remote_create_options_init(copts, C.GIT_REMOTE_CREATE_OPTIONS_VERSION)
|
||||||
|
if opts == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var cRepository *C.git_repository
|
||||||
|
if repo != nil {
|
||||||
|
cRepository = repo.ptr
|
||||||
|
}
|
||||||
|
copts.repository = cRepository
|
||||||
|
copts.name = C.CString(opts.Name)
|
||||||
|
copts.fetchspec = C.CString(opts.FetchSpec)
|
||||||
|
copts.flags = C.uint(opts.Flags)
|
||||||
|
|
||||||
|
return copts
|
||||||
|
}
|
||||||
|
|
||||||
|
func freeRemoteCreateOptions(ptr *C.git_remote_create_options) {
|
||||||
|
if ptr == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
C.free(unsafe.Pointer(ptr.name))
|
||||||
|
C.free(unsafe.Pointer(ptr.fetchspec))
|
||||||
|
}
|
||||||
|
|
||||||
|
// createNewEmptyRemote used to get a new empty object of *Remote
|
||||||
|
func createNewEmptyRemote() *Remote {
|
||||||
|
return &Remote{
|
||||||
|
callbacks: RemoteCallbacks{},
|
||||||
|
repo: nil,
|
||||||
|
weak: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
@ -37,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) ErrorCode {
|
func assertHostname(cert *Certificate, valid bool, hostname string, t *testing.T) error {
|
||||||
if hostname != "github.com" {
|
if hostname != "github.com" {
|
||||||
t.Fatal("Hostname does not match")
|
t.Fatal("hostname does not match")
|
||||||
return ErrorCodeUser
|
return errors.New("hostname does not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorCodeOK
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCertificateCheck(t *testing.T) {
|
func TestCertificateCheck(t *testing.T) {
|
||||||
|
@ -57,7 +58,7 @@ func TestCertificateCheck(t *testing.T) {
|
||||||
|
|
||||||
options := FetchOptions{
|
options := FetchOptions{
|
||||||
RemoteCallbacks: RemoteCallbacks{
|
RemoteCallbacks: RemoteCallbacks{
|
||||||
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) ErrorCode {
|
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
|
||||||
return assertHostname(cert, valid, hostname, t)
|
return assertHostname(cert, valid, hostname, t)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -80,6 +81,29 @@ func TestRemoteConnect(t *testing.T) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRemoteConnectOption(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
repo := createTestRepo(t)
|
||||||
|
defer cleanupTestRepo(t, repo)
|
||||||
|
|
||||||
|
config, err := repo.Config()
|
||||||
|
checkFatal(t, err)
|
||||||
|
err = config.SetString("url.git@github.com:.insteadof", "https://github.com/")
|
||||||
|
checkFatal(t, err)
|
||||||
|
|
||||||
|
option, err := DefaultRemoteCreateOptions()
|
||||||
|
checkFatal(t, err)
|
||||||
|
option.Name = "origin"
|
||||||
|
option.Flags = RemoteCreateSkipInsteadof
|
||||||
|
|
||||||
|
remote, err := repo.Remotes.CreateWithOptions("https://github.com/libgit2/TestGitRepository", option)
|
||||||
|
checkFatal(t, err)
|
||||||
|
defer remote.Free()
|
||||||
|
|
||||||
|
err = remote.ConnectFetch(nil, nil, nil)
|
||||||
|
checkFatal(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemoteLs(t *testing.T) {
|
func TestRemoteLs(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
repo := createTestRepo(t)
|
repo := createTestRepo(t)
|
||||||
|
@ -219,17 +243,18 @@ func TestRemoteCredentialsCalled(t *testing.T) {
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer remote.Free()
|
defer remote.Free()
|
||||||
|
|
||||||
|
errNonExistent := errors.New("non-existent repository")
|
||||||
fetchOpts := FetchOptions{
|
fetchOpts := FetchOptions{
|
||||||
RemoteCallbacks: RemoteCallbacks{
|
RemoteCallbacks: RemoteCallbacks{
|
||||||
CredentialsCallback: func(url, username string, allowedTypes CredType) (ErrorCode, *Cred) {
|
CredentialsCallback: func(url, username string, allowedTypes CredentialType) (*Credential, error) {
|
||||||
return ErrorCodeUser, nil
|
return nil, errNonExistent
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err = remote.Fetch(nil, &fetchOpts, "fetch")
|
err = remote.Fetch(nil, &fetchOpts, "fetch")
|
||||||
if IsErrorCode(err, ErrorCodeUser) {
|
if err != errNonExistent {
|
||||||
t.Fatalf("remote.Fetch() = %v, want %v", err, ErrorCodeUser)
|
t.Fatalf("remote.Fetch() = %v, want %v", err, errNonExistent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,33 +479,29 @@ 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) ErrorCode {
|
CertificateCheckCallback: func(cert *Certificate, valid bool, hostname string) error {
|
||||||
hostkeyFingerprint := fmt.Sprintf("%x", cert.Hostkey.HashMD5[:])
|
hostkeyFingerprint := fmt.Sprintf("%x", cert.Hostkey.HashMD5[:])
|
||||||
if hostkeyFingerprint != publicKeyFingerprint {
|
if hostkeyFingerprint != publicKeyFingerprint {
|
||||||
t.Logf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
|
return fmt.Errorf("server hostkey %q, want %q", hostkeyFingerprint, publicKeyFingerprint)
|
||||||
return ErrorCodeAuth
|
|
||||||
}
|
}
|
||||||
certificateCheckCallbackCalled = true
|
certificateCheckCallbackCalled = true
|
||||||
return ErrorCodeOK
|
return nil
|
||||||
},
|
},
|
||||||
CredentialsCallback: func(url, username string, allowedTypes CredType) (ErrorCode, *Cred) {
|
CredentialsCallback: func(url, username string, allowedTypes CredentialType) (*Credential, error) {
|
||||||
if allowedTypes&(CredTypeSshKey|CredTypeSshCustom) != 0 {
|
if allowedTypes&(CredentialTypeSSHKey|CredentialTypeSSHCustom|CredentialTypeSSHMemory) != 0 {
|
||||||
cred, err := NewCredentialSSHKeyFromSigner(pubKeyUsername, signer)
|
return NewCredentialSSHKeyFromSigner(pubKeyUsername, signer)
|
||||||
if err != nil {
|
|
||||||
t.Logf("failed to create credentials: %v", err)
|
|
||||||
return ErrorCodeAuth, nil
|
|
||||||
}
|
}
|
||||||
return ErrorCodeOK, cred
|
if (allowedTypes & CredentialTypeUsername) != 0 {
|
||||||
|
return NewCredentialUsername(pubKeyUsername)
|
||||||
}
|
}
|
||||||
t.Logf("unknown credential type %+v", allowedTypes)
|
return nil, fmt.Errorf("unknown credential type %+v", allowedTypes)
|
||||||
return ErrorCodeAuth, nil
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
remote, err := repo.Remotes.Create(
|
remote, err := repo.Remotes.Create(
|
||||||
"origin",
|
"origin",
|
||||||
fmt.Sprintf("ssh://%s@%s/TestGitRepository", pubKeyUsername, listener.Addr().String()),
|
fmt.Sprintf("ssh://%s/TestGitRepository", listener.Addr().String()),
|
||||||
)
|
)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer remote.Free()
|
defer remote.Free()
|
||||||
|
|
|
@ -173,9 +173,15 @@ func (v *Repository) Config() (*Config, error) {
|
||||||
// This configuration file will be used for all configuration queries involving
|
// This configuration file will be used for all configuration queries involving
|
||||||
// this repository.
|
// this repository.
|
||||||
func (v *Repository) SetConfig(c *Config) error {
|
func (v *Repository) SetConfig(c *Config) error {
|
||||||
C.git_repository_set_config(v.ptr, c.ptr)
|
runtime.LockOSThread()
|
||||||
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
|
ret := C.git_repository_set_config(v.ptr, c.ptr)
|
||||||
runtime.KeepAlive(v)
|
runtime.KeepAlive(v)
|
||||||
runtime.KeepAlive(c)
|
runtime.KeepAlive(c)
|
||||||
|
if ret < 0 {
|
||||||
|
return MakeGitError(ret)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +205,7 @@ func (v *Repository) lookupType(id *Oid, t ObjectType) (*Object, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_otype(t))
|
ret := C.git_object_lookup(&ptr, v.ptr, id.toC(), C.git_object_t(t))
|
||||||
runtime.KeepAlive(id)
|
runtime.KeepAlive(id)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -214,7 +220,7 @@ func (v *Repository) lookupPrefixType(id *Oid, prefix uint, t ObjectType) (*Obje
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ret := C.git_object_lookup_prefix(&ptr, v.ptr, id.toC(), C.size_t(prefix), C.git_otype(t))
|
ret := C.git_object_lookup_prefix(&ptr, v.ptr, id.toC(), C.size_t(prefix), C.git_object_t(t))
|
||||||
runtime.KeepAlive(id)
|
runtime.KeepAlive(id)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
|
@ -562,7 +568,7 @@ func (v *Repository) CreateCommitBuffer(
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
ret := C.git_commit_create_buffer(
|
ret := C.git_commit_create_buffer(
|
||||||
&buf, v.ptr,
|
&buf, v.ptr,
|
||||||
authorSig, committerSig,
|
authorSig, committerSig,
|
||||||
|
@ -809,7 +815,7 @@ func (r *Repository) ClearGitIgnoreRules() error {
|
||||||
// the file after you create the commit.
|
// the file after you create the commit.
|
||||||
func (r *Repository) Message() (string, error) {
|
func (r *Repository) Message() (string, error) {
|
||||||
buf := C.git_buf{}
|
buf := C.git_buf{}
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -856,7 +862,7 @@ const (
|
||||||
|
|
||||||
func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
|
func (r *Repository) ItemPath(item RepositoryItem) (string, error) {
|
||||||
var c_buf C.git_buf
|
var c_buf C.git_buf
|
||||||
defer C.git_buf_free(&c_buf)
|
defer C.git_buf_dispose(&c_buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
16
revert.go
16
revert.go
|
@ -11,26 +11,26 @@ 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
|
||||||
MergeOpts MergeOptions
|
MergeOptions MergeOptions
|
||||||
CheckoutOpts CheckoutOptions
|
CheckoutOptions 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 {
|
||||||
C.git_revert_init_options(copts, C.GIT_REVERT_OPTIONS_VERSION)
|
C.git_revert_options_init(copts, C.GIT_REVERT_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.mainline = C.uint(opts.Mainline)
|
copts.mainline = C.uint(opts.Mainline)
|
||||||
populateMergeOptions(&copts.merge_opts, &opts.MergeOpts)
|
populateMergeOptions(&copts.merge_opts, &opts.MergeOptions)
|
||||||
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOpts, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, 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),
|
||||||
MergeOpts: mergeOptionsFromC(&copts.merge_opts),
|
MergeOptions: mergeOptionsFromC(&copts.merge_opts),
|
||||||
CheckoutOpts: checkoutOptionsFromC(&copts.checkout_opts),
|
CheckoutOptions: checkoutOptionsFromC(&copts.checkout_opts),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func DefaultRevertOptions() (RevertOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_revert_init_options(&copts, C.GIT_REVERT_OPTIONS_VERSION)
|
ecode := C.git_revert_options_init(&copts, C.GIT_REVERT_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return RevertOptions{}, MakeGitError(ecode)
|
return RevertOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,12 +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.MergeOpts)
|
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOptions)
|
||||||
checkFatal(t, err)
|
checkFatal(t, err)
|
||||||
defer index.Free()
|
defer index.Free()
|
||||||
|
|
||||||
revertOptions.CheckoutOpts.Strategy = CheckoutSafe
|
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)
|
||||||
|
|
|
@ -46,24 +46,40 @@ if [ -z "${BUILD_SHARED_LIBS}" ]; then
|
||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${BUILD_LIBGIT_REF}" ]; then
|
||||||
|
git -C "${VENDORED_PATH}" checkout "${BUILD_LIBGIT_REF}"
|
||||||
|
trap "git submodule update --init" EXIT
|
||||||
|
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"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
USE_BUNDLED_ZLIB="ON"
|
||||||
|
if [ "${USE_CHROMIUM_ZLIB}" = "ON" ]; then
|
||||||
|
USE_BUNDLED_ZLIB="Chromium"
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p "${BUILD_PATH}/build" &&
|
mkdir -p "${BUILD_PATH}/build" &&
|
||||||
cd "${BUILD_PATH}/build" &&
|
cd "${BUILD_PATH}/build" &&
|
||||||
cmake -DTHREADSAFE=ON \
|
cmake -DTHREADSAFE=ON \
|
||||||
-DBUILD_CLAR=OFF \
|
-DBUILD_CLAR=OFF \
|
||||||
-DBUILD_SHARED_LIBS"=${BUILD_SHARED_LIBS}" \
|
-DBUILD_SHARED_LIBS"=${BUILD_SHARED_LIBS}" \
|
||||||
|
-DREGEX_BACKEND=builtin \
|
||||||
|
-DUSE_BUNDLED_ZLIB="${USE_BUNDLED_ZLIB}" \
|
||||||
-DUSE_HTTPS=OFF \
|
-DUSE_HTTPS=OFF \
|
||||||
-DUSE_SSH=OFF \
|
-DUSE_SSH=OFF \
|
||||||
-DCMAKE_C_FLAGS=-fPIC \
|
-DCMAKE_C_FLAGS=-fPIC \
|
||||||
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
|
||||||
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
-DCMAKE_INSTALL_PREFIX="${BUILD_INSTALL_PREFIX}" \
|
||||||
-DDEPRECATE_HARD=ON \
|
-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 git2go in dynamic mode on Travis
|
# Install libgit2 to go libgit2 in dynamic mode on Travis
|
||||||
#
|
#
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
|
@ -18,7 +18,7 @@ int _go_git_opts_set_size_t(int opt, size_t val)
|
||||||
return git_libgit2_opts(opt, val);
|
return git_libgit2_opts(opt, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _go_git_opts_set_cache_object_limit(git_otype type, size_t size)
|
int _go_git_opts_set_cache_object_limit(git_object_t type, size_t size)
|
||||||
{
|
{
|
||||||
return git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, type, size);
|
return git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, type, size);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ import (
|
||||||
|
|
||||||
func SearchPath(level ConfigLevel) (string, error) {
|
func SearchPath(level ConfigLevel) (string, error) {
|
||||||
var buf C.git_buf
|
var buf C.git_buf
|
||||||
defer C.git_buf_free(&buf)
|
defer C.git_buf_dispose(&buf)
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
@ -126,7 +126,7 @@ func SetCacheObjectLimit(objectType ObjectType, size int) error {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
err := C._go_git_opts_set_cache_object_limit(C.git_otype(objectType), C.size_t(size))
|
err := C._go_git_opts_set_cache_object_limit(C.git_object_t(objectType), C.size_t(size))
|
||||||
if err < 0 {
|
if err < 0 {
|
||||||
return MakeGitError(err)
|
return MakeGitError(err)
|
||||||
}
|
}
|
||||||
|
|
29
ssh.go
29
ssh.go
|
@ -3,7 +3,7 @@ package git
|
||||||
/*
|
/*
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
|
|
||||||
void _go_git_credential_free(git_cred *cred);
|
#include <git2/sys/credential.h>
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
@ -106,11 +106,11 @@ func (t *sshSmartSubtransport) Action(urlString string, action SmartServiceActio
|
||||||
return nil, fmt.Errorf("unexpected action: %v", action)
|
return nil, fmt.Errorf("unexpected action: %v", action)
|
||||||
}
|
}
|
||||||
|
|
||||||
cred, err := t.transport.SmartCredentials("", CredTypeSshKey)
|
cred, err := t.transport.SmartCredentials("", CredentialTypeSSHKey|CredentialTypeSSHMemory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer C._go_git_credential_free(cred.ptr)
|
defer cred.Free()
|
||||||
|
|
||||||
sshConfig, err := getSSHConfigFromCredential(cred)
|
sshConfig, err := getSSHConfigFromCredential(cred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -201,10 +201,10 @@ func (stream *sshSmartSubtransportStream) Write(buf []byte) (int, error) {
|
||||||
func (stream *sshSmartSubtransportStream) Free() {
|
func (stream *sshSmartSubtransportStream) Free() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSSHConfigFromCredential(cred *Cred) (*ssh.ClientConfig, error) {
|
func getSSHConfigFromCredential(cred *Credential) (*ssh.ClientConfig, error) {
|
||||||
switch cred.Type() {
|
switch cred.Type() {
|
||||||
case CredTypeSshCustom:
|
case CredentialTypeSSHCustom:
|
||||||
credSSHCustom := (*C.git_cred_ssh_custom)(unsafe.Pointer(cred.ptr))
|
credSSHCustom := (*C.git_credential_ssh_custom)(unsafe.Pointer(cred.ptr))
|
||||||
data, ok := pointerHandles.Get(credSSHCustom.payload).(*credentialSSHCustomData)
|
data, ok := pointerHandles.Get(credSSHCustom.payload).(*credentialSSHCustomData)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.New("unsupported custom SSH credentials")
|
return nil, errors.New("unsupported custom SSH credentials")
|
||||||
|
@ -215,16 +215,21 @@ func getSSHConfigFromCredential(cred *Cred) (*ssh.ClientConfig, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
username, _, privatekey, passphrase, ret := cred.GetSSHKey()
|
username, _, privatekey, passphrase, err := cred.GetSSHKey()
|
||||||
if ret != nil {
|
|
||||||
return nil, ret
|
|
||||||
}
|
|
||||||
|
|
||||||
pemBytes, err := ioutil.ReadFile(privatekey)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pemBytes []byte
|
||||||
|
if cred.Type() == CredentialTypeSSHMemory {
|
||||||
|
pemBytes = []byte(privatekey)
|
||||||
|
} else {
|
||||||
|
pemBytes, err = ioutil.ReadFile(privatekey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var key ssh.Signer
|
var key ssh.Signer
|
||||||
if passphrase != "" {
|
if passphrase != "" {
|
||||||
key, err = ssh.ParsePrivateKeyWithPassphrase(pemBytes, []byte(passphrase))
|
key, err = ssh.ParsePrivateKeyWithPassphrase(pemBytes, []byte(passphrase))
|
||||||
|
|
6
stash.go
6
stash.go
|
@ -152,7 +152,7 @@ func DefaultStashApplyOptions() (StashApplyOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
ecode := C.git_stash_apply_init_options(&optsC, C.GIT_STASH_APPLY_OPTIONS_VERSION)
|
ecode := C.git_stash_apply_options_init(&optsC, C.GIT_STASH_APPLY_OPTIONS_VERSION)
|
||||||
if ecode < 0 {
|
if ecode < 0 {
|
||||||
return StashApplyOptions{}, MakeGitError(ecode)
|
return StashApplyOptions{}, MakeGitError(ecode)
|
||||||
}
|
}
|
||||||
|
@ -163,11 +163,11 @@ func DefaultStashApplyOptions() (StashApplyOptions, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateStashApplyOptions(copts *C.git_stash_apply_options, opts *StashApplyOptions, errorTarget *error) *C.git_stash_apply_options {
|
func populateStashApplyOptions(copts *C.git_stash_apply_options, opts *StashApplyOptions, errorTarget *error) *C.git_stash_apply_options {
|
||||||
C.git_stash_apply_init_options(copts, C.GIT_STASH_APPLY_OPTIONS_VERSION)
|
C.git_stash_apply_options_init(copts, C.GIT_STASH_APPLY_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
copts.flags = C.git_stash_apply_flags(opts.Flags)
|
copts.flags = C.uint32_t(opts.Flags)
|
||||||
populateCheckoutOptions(&copts.checkout_options, &opts.CheckoutOptions, errorTarget)
|
populateCheckoutOptions(&copts.checkout_options, &opts.CheckoutOptions, errorTarget)
|
||||||
if opts.ProgressCallback != nil {
|
if opts.ProgressCallback != nil {
|
||||||
progressData := &stashApplyProgressCallbackData{
|
progressData := &stashApplyProgressCallbackData{
|
||||||
|
|
|
@ -160,7 +160,7 @@ func (v *Repository) StatusList(opts *StatusOptions) (*StatusList, error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
copts = &C.git_status_options{}
|
copts = &C.git_status_options{}
|
||||||
ret := C.git_status_init_options(copts, C.GIT_STATUS_OPTIONS_VERSION)
|
ret := C.git_status_options_init(copts, C.GIT_STATUS_OPTIONS_VERSION)
|
||||||
if ret < 0 {
|
if ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
19
submodule.go
19
submodule.go
|
@ -8,15 +8,14 @@ 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 {
|
||||||
*CheckoutOpts
|
CheckoutOptions CheckoutOptions
|
||||||
*FetchOptions
|
FetchOptions FetchOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submodule
|
// Submodule
|
||||||
|
@ -111,7 +110,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) int
|
type SubmoduleCallback func(sub *Submodule, name string) error
|
||||||
type submoduleCallbackData struct {
|
type submoduleCallbackData struct {
|
||||||
callback SubmoduleCallback
|
callback SubmoduleCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -126,9 +125,9 @@ func submoduleCallback(csub unsafe.Pointer, name *C.char, handle unsafe.Pointer)
|
||||||
panic("invalid submodule visitor callback")
|
panic("invalid submodule visitor callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callback(sub, C.GoString(name))
|
err := data.callback(sub, C.GoString(name))
|
||||||
if ret < 0 {
|
if err != nil {
|
||||||
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
*data.errorTarget = err
|
||||||
return C.int(ErrorCodeUser)
|
return C.int(ErrorCodeUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,13 +385,13 @@ func (sub *Submodule) Update(init bool, opts *SubmoduleUpdateOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func populateSubmoduleUpdateOptions(copts *C.git_submodule_update_options, opts *SubmoduleUpdateOptions, errorTarget *error) *C.git_submodule_update_options {
|
func populateSubmoduleUpdateOptions(copts *C.git_submodule_update_options, opts *SubmoduleUpdateOptions, errorTarget *error) *C.git_submodule_update_options {
|
||||||
C.git_submodule_update_init_options(copts, C.GIT_SUBMODULE_UPDATE_OPTIONS_VERSION)
|
C.git_submodule_update_options_init(copts, C.GIT_SUBMODULE_UPDATE_OPTIONS_VERSION)
|
||||||
if opts == nil {
|
if opts == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
populateCheckoutOptions(&copts.checkout_opts, opts.CheckoutOpts, errorTarget)
|
populateCheckoutOptions(&copts.checkout_opts, &opts.CheckoutOptions, 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) int {
|
err = repo.Submodules.Foreach(func(sub *Submodule, name string) error {
|
||||||
i++
|
i++
|
||||||
return 0
|
return nil
|
||||||
})
|
})
|
||||||
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_free(&strC)
|
defer C.git_strarray_dispose(&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_free(&strC)
|
defer C.git_strarray_dispose(&strC)
|
||||||
|
|
||||||
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
tags := makeStringsFromCStrings(strC.strings, int(strC.count))
|
||||||
return tags, nil
|
return tags, nil
|
||||||
|
|
37
transport.go
37
transport.go
|
@ -22,7 +22,6 @@ void _go_git_setup_smart_subtransport_stream(_go_managed_smart_subtransport_stre
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
@ -32,7 +31,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// globalRegisteredSmartTransports is a mapping of global, git2go-managed
|
// globalRegisteredSmartTransports is a mapping of global, libgit2 go-managed
|
||||||
// transports.
|
// transports.
|
||||||
globalRegisteredSmartTransports = struct {
|
globalRegisteredSmartTransports = struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
@ -42,7 +41,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// unregisterManagedTransports unregisters all git2go-managed transports.
|
// unregisterManagedTransports unregisters all libgit2 go-managed transports.
|
||||||
func unregisterManagedTransports() error {
|
func unregisterManagedTransports() error {
|
||||||
globalRegisteredSmartTransports.Lock()
|
globalRegisteredSmartTransports.Lock()
|
||||||
originalTransports := globalRegisteredSmartTransports.transports
|
originalTransports := globalRegisteredSmartTransports.transports
|
||||||
|
@ -85,22 +84,22 @@ type Transport struct {
|
||||||
ptr *C.git_transport
|
ptr *C.git_transport
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmartProxyOptions gets a copy of the proxy options for this transport.
|
// SmartRemoteConnectOptions gets a copy of the proxy options for this transport.
|
||||||
func (t *Transport) SmartProxyOptions() (*ProxyOptions, error) {
|
func (t *Transport) SmartRemoteConnectOptions() (*RemoteConnectOptions, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
var cpopts C.git_proxy_options
|
var copts C.git_remote_connect_options
|
||||||
if ret := C.git_transport_smart_proxy_options(&cpopts, t.ptr); ret < 0 {
|
if ret := C.git_transport_remote_connect_options(&copts, t.ptr); ret < 0 {
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
return proxyOptionsFromC(&cpopts), nil
|
return remoteConnectOptionsFromC(&copts), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmartCredentials calls the credentials callback for this transport.
|
// SmartCredentials calls the credentials callback for this transport.
|
||||||
func (t *Transport) SmartCredentials(user string, methods CredType) (*Cred, error) {
|
func (t *Transport) SmartCredentials(user string, methods CredentialType) (*Credential, error) {
|
||||||
cred := &Cred{}
|
cred := newCredential()
|
||||||
var cstr *C.char
|
var cstr *C.char
|
||||||
|
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
|
@ -112,6 +111,7 @@ func (t *Transport) SmartCredentials(user string, methods CredType) (*Cred, erro
|
||||||
}
|
}
|
||||||
ret := C.git_transport_smart_credentials(&cred.ptr, t.ptr, cstr, C.int(methods))
|
ret := C.git_transport_smart_credentials(&cred.ptr, t.ptr, cstr, C.int(methods))
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
|
cred.Free()
|
||||||
return nil, MakeGitError(ret)
|
return nil, MakeGitError(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +128,20 @@ func (t *Transport) SmartCertificateCheck(cert *Certificate, valid bool, hostnam
|
||||||
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)))
|
||||||
|
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:
|
||||||
|
@ -294,8 +305,10 @@ func smartTransportCallback(
|
||||||
registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport)
|
registeredSmartTransport := pointerHandles.Get(handle).(*RegisteredSmartTransport)
|
||||||
remote, ok := remotePointers.get(owner)
|
remote, ok := remotePointers.get(owner)
|
||||||
if !ok {
|
if !ok {
|
||||||
err := errors.New("remote pointer not found")
|
// create a new empty remote and set it
|
||||||
return setCallbackError(errorMessage, err)
|
// as a weak pointer, so that control stays in golang
|
||||||
|
remote = createNewEmptyRemote()
|
||||||
|
remote.weak = true
|
||||||
}
|
}
|
||||||
|
|
||||||
managed := &managedSmartSubtransport{
|
managed := &managedSmartSubtransport{
|
||||||
|
|
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) int
|
type TreeWalkCallback func(string, *TreeEntry) error
|
||||||
type treeWalkCallbackData struct {
|
type treeWalkCallbackData struct {
|
||||||
callback TreeWalkCallback
|
callback TreeWalkCallback
|
||||||
errorTarget *error
|
errorTarget *error
|
||||||
|
@ -134,15 +134,30 @@ func treeWalkCallback(_root *C.char, entry *C.git_tree_entry, ptr unsafe.Pointer
|
||||||
panic("invalid treewalk callback")
|
panic("invalid treewalk callback")
|
||||||
}
|
}
|
||||||
|
|
||||||
ret := data.callback(C.GoString(_root), newTreeEntry(entry))
|
err := data.callback(C.GoString(_root), newTreeEntry(entry))
|
||||||
if ret < 0 {
|
if err == TreeWalkSkip {
|
||||||
*data.errorTarget = errors.New(ErrorCode(ret).String())
|
return C.int(1)
|
||||||
|
} 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,6 +1,9 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestTreeEntryById(t *testing.T) {
|
func TestTreeEntryById(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -63,3 +66,72 @@ 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Subproject commit 45c6187cbfdcfee2bcf59a1ed3a853065142f203
|
|
62
wrapper.c
62
wrapper.c
|
@ -3,6 +3,7 @@
|
||||||
#include <git2.h>
|
#include <git2.h>
|
||||||
#include <git2/sys/odb_backend.h>
|
#include <git2/sys/odb_backend.h>
|
||||||
#include <git2/sys/refdb_backend.h>
|
#include <git2/sys/refdb_backend.h>
|
||||||
|
#include <git2/sys/cred.h>
|
||||||
|
|
||||||
// There are two ways in which to declare a callback:
|
// There are two ways in which to declare a callback:
|
||||||
//
|
//
|
||||||
|
@ -103,12 +104,50 @@ 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(GITERR_CALLBACK, error_message);
|
giterr_set_str(GIT_ERROR_CALLBACK, error_message);
|
||||||
free(error_message);
|
free(error_message);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _go_git_populate_apply_callbacks(git_apply_options *options)
|
||||||
|
{
|
||||||
|
options->delta_cb = (git_apply_delta_cb)&deltaApplyCallback;
|
||||||
|
options->hunk_cb = (git_apply_hunk_cb)&hunkApplyCallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int commit_create_callback(
|
||||||
|
git_oid *out,
|
||||||
|
const git_signature *author,
|
||||||
|
const git_signature *committer,
|
||||||
|
const char *message_encoding,
|
||||||
|
const char *message,
|
||||||
|
const git_tree *tree,
|
||||||
|
size_t parent_count,
|
||||||
|
const git_commit *parents[],
|
||||||
|
void *payload)
|
||||||
|
{
|
||||||
|
char *error_message = NULL;
|
||||||
|
const int ret = commitCreateCallback(
|
||||||
|
&error_message,
|
||||||
|
out,
|
||||||
|
(git_signature *)author,
|
||||||
|
(git_signature *)committer,
|
||||||
|
(char *)message_encoding,
|
||||||
|
(char *)message,
|
||||||
|
(git_tree *)tree,
|
||||||
|
parent_count,
|
||||||
|
(git_commit **)parents,
|
||||||
|
payload
|
||||||
|
);
|
||||||
|
return set_callback_error(error_message, ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _go_git_populate_rebase_callbacks(git_rebase_options *opts)
|
||||||
|
{
|
||||||
|
opts->commit_create_cb = commit_create_callback;
|
||||||
|
}
|
||||||
|
|
||||||
void _go_git_populate_clone_callbacks(git_clone_options *opts)
|
void _go_git_populate_clone_callbacks(git_clone_options *opts)
|
||||||
{
|
{
|
||||||
opts->remote_cb = (git_remote_create_cb)&remoteCreateCallback;
|
opts->remote_cb = (git_remote_create_cb)&remoteCreateCallback;
|
||||||
|
@ -215,7 +254,7 @@ static int completion_callback(git_remote_completion_type completion_type, void
|
||||||
}
|
}
|
||||||
|
|
||||||
static int credentials_callback(
|
static int credentials_callback(
|
||||||
git_cred **cred,
|
git_credential **cred,
|
||||||
const char *url,
|
const char *url,
|
||||||
const char *username_from_url,
|
const char *username_from_url,
|
||||||
unsigned int allowed_types,
|
unsigned int allowed_types,
|
||||||
|
@ -411,6 +450,11 @@ void _go_git_writestream_free(git_writestream *stream)
|
||||||
stream->free(stream);
|
stream->free(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
git_credential_t _go_git_credential_credtype(git_credential *cred)
|
||||||
|
{
|
||||||
|
return cred->credtype;
|
||||||
|
}
|
||||||
|
|
||||||
static int credential_ssh_sign_callback(
|
static int credential_ssh_sign_callback(
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
unsigned char **sig, size_t *sig_len,
|
unsigned char **sig, size_t *sig_len,
|
||||||
|
@ -428,17 +472,12 @@ static int credential_ssh_sign_callback(
|
||||||
return set_callback_error(error_message, ret);
|
return set_callback_error(error_message, ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _go_git_populate_credential_ssh_custom(git_cred_ssh_custom *cred)
|
void _go_git_populate_credential_ssh_custom(git_credential_ssh_custom *cred)
|
||||||
{
|
{
|
||||||
cred->parent.free = (void (*)(git_cred *))credentialSSHCustomFree;
|
cred->parent.free = (void (*)(git_credential *))credentialSSHCustomFree;
|
||||||
cred->sign_callback = credential_ssh_sign_callback;
|
cred->sign_callback = credential_ssh_sign_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _go_git_credential_free(git_cred *cred)
|
|
||||||
{
|
|
||||||
cred->free(cred);
|
|
||||||
}
|
|
||||||
|
|
||||||
int _go_git_odb_write_pack(git_odb_writepack **out, git_odb *db, void *progress_payload)
|
int _go_git_odb_write_pack(git_odb_writepack **out, git_odb *db, void *progress_payload)
|
||||||
{
|
{
|
||||||
return git_odb_write_pack(out, db, transfer_progress_callback, progress_payload);
|
return git_odb_write_pack(out, db, transfer_progress_callback, progress_payload);
|
||||||
|
@ -470,7 +509,10 @@ int _go_git_indexer_new(
|
||||||
git_odb *odb,
|
git_odb *odb,
|
||||||
void *progress_cb_payload)
|
void *progress_cb_payload)
|
||||||
{
|
{
|
||||||
return git_indexer_new(out, path, mode, odb, transfer_progress_callback, progress_cb_payload);
|
git_indexer_options indexer_options = GIT_INDEXER_OPTIONS_INIT;
|
||||||
|
indexer_options.progress_cb = transfer_progress_callback;
|
||||||
|
indexer_options.progress_cb_payload = progress_cb_payload;
|
||||||
|
return git_indexer_new(out, path, mode, odb, &indexer_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int smart_transport_callback(
|
static int smart_transport_callback(
|
||||||
|
|
Loading…
Reference in New Issue