Compare commits

..

2 Commits

Author SHA1 Message Date
Sunny 5bd7c33e5d Update SmartServiceActionReceivepack request path
Similar to SmartServiceActionUploadpack, SmartServiceActionReceivepack
is not an info endpoint. Fix the path for git-receive-pack.
2021-11-29 01:49:12 +05:30
Sunny 3d4b9b97d1
Add option to configure http/s managed transport
This change introduces NewRegisterSmartTransportWithOptions() to help
configure the smart transport with SmartSubtransportOptions. If the
default smart subtransport client needs to be configured, a newly
configured smart transport can be registered and used.
The SmartSubtransportOptions includes CABundle only for now.

This enables creating and using new transport with secrets that can be
deleted and not shared with subsequent operations.

The http client from httpSmartSubtransport is now shared with the
underlying httpSmartSubtransportStream, reusing the client and its
configurations.

It also fixes the error during cloning:
```
unable to clone: Post "http://test-user:***@127.0.0.1:40463/bar/test-reponame/git-upload-pack": io: read/write on closed pipe
```
by using credentials if available and avoiding failure due to
unauthorized request.

A user of the smart transport who needs to add a CA bundle in the
http client can do the following to setup the smart transport before
cloning:

```
stOpts := &git2go.SmartSubtransportOptions{CABundle: opts.CAFile}
rst, err := git2go.NewRegisterSmartTransportWithOptions("https", stOpts)
if err != nil {
	return err
}
if rst != nil {
	defer rst.Free()
}
```
2021-11-22 19:56:43 +05:30
26 changed files with 415 additions and 464 deletions

54
.github/workflows/backport.yml vendored Normal file
View File

@ -0,0 +1,54 @@
name: Backport to older releases
on:
push:
branches:
- main
jobs:
backport:
name: Backport change to branch ${{ matrix.branch }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
branch: [ 'release-1.2', 'release-1.1', 'release-1.0', '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)"

130
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,130 @@
name: git2go CI
on:
pull_request:
push:
branches:
- main
- release-*
- v*
jobs:
build-static:
strategy:
fail-fast: false
matrix:
go: [ '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17' ]
name: Go ${{ matrix.go }}
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Build
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
make build-libgit2-static
- name: Test
run: make TEST_ARGS=-test.v test-static
build-dynamic:
strategy:
fail-fast: false
name: Go (dynamic)
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Build
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
make build-libgit2-dynamic
- name: Test
run: make TEST_ARGS=-test.v test-dynamic
build-system-dynamic:
strategy:
fail-fast: false
matrix:
libgit2:
- 'v1.3.0'
name: Go (system-wide, dynamic)
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Build libgit2 ${{ matrix.libgit2 }}
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
sudo env BUILD_LIBGIT_REF=${{ matrix.libgit2 }} ./script/build-libgit2.sh --dynamic --system
- name: Test
run: make TEST_ARGS=-test.v test
build-system-static:
strategy:
fail-fast: false
name: Go (system-wide, static)
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Build libgit2
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
sudo ./script/build-libgit2.sh --static --system
- name: Test
run: go test --count=1 --tags "static,system_libgit2" ./...
check-generate:
name: Check generated files were not modified
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Install libgit2 build dependencies
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
go install golang.org/x/tools/cmd/stringer@latest
- name: Generate files
run: |
export PATH=$(go env GOPATH)/bin:$PATH
make generate
- name: Check nothing changed
run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1)

28
.github/workflows/tag.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: Tag new releases
on:
push:
branches:
- main
- release-*
jobs:
tag-release:
name: Bump tag in ${{ github.ref }}
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v1
with:
fetch-depth: 0
- name: Bump version and push tag
id: bump-version
uses: anothrNick/github-tag-action@9aaabdb5e989894e95288328d8b17a6347217ae3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
TAG_CONTEXT: branch
RELEASE_BRANCHES: .*

2
.gitignore vendored
View File

@ -1,4 +1,2 @@
/static-build/ /static-build/
/dynamic-build/ /dynamic-build/
go.*

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "vendor/libgit2"]
path = vendor/libgit2
url = https://github.com/libgit2/libgit2

View File

@ -10,8 +10,8 @@ package git
#cgo CFLAGS: -DLIBGIT2_STATIC #cgo CFLAGS: -DLIBGIT2_STATIC
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5 #if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.0" # error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0"
#endif #endif
*/ */
import "C" import "C"

View File

@ -5,10 +5,11 @@ package git
/* /*
#cgo pkg-config: libgit2 #cgo pkg-config: libgit2
#cgo CFLAGS: -DLIBGIT2_DYNAMIC -I/opt/libgit2/include #cgo CFLAGS: -DLIBGIT2_DYNAMIC
#cgo LDFLAGS: -L/opt/libgit2 -lgit2
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3
# error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0"
#endif
*/ */
import "C" import "C"

View File

@ -8,8 +8,8 @@ package git
#cgo CFLAGS: -DLIBGIT2_STATIC #cgo CFLAGS: -DLIBGIT2_STATIC
#include <git2.h> #include <git2.h>
#if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 5 || LIBGIT2_VER_MINOR > 5 #if LIBGIT2_VER_MAJOR != 1 || LIBGIT2_VER_MINOR < 3 || LIBGIT2_VER_MINOR > 3
# error "Invalid libgit2 version; this libgit2 supports libgit2 between v1.5.0 and v1.5.0" # error "Invalid libgit2 version; this git2go supports libgit2 between v1.3.0 and v1.3.0"
#endif #endif
*/ */
import "C" import "C"

View File

@ -1,6 +1,6 @@
The MIT License The MIT License
Copyright (c) 2013 The libgit2 contributors Copyright (c) 2013 The git2go contributors
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -1,11 +1,7 @@
TEST_ARGS ?= --count=1 TEST_ARGS ?= --count=1
PKG_CONFIG_PATH=/opt/libgit2/ default: test
default: goimports test
goimports:
goimports -w *.go
generate: static-build/install/lib/libgit2.a generate: static-build/install/lib/libgit2.a
go generate --tags "static" ./... go generate --tags "static" ./...
@ -14,19 +10,12 @@ generate: static-build/install/lib/libgit2.a
# ============== # ==============
# This uses whatever version of libgit2 can be found in the system. # This uses whatever version of libgit2 can be found in the system.
test: test:
-go-mod-clean # go install go.wit.com/apps/go-mod-clean@latest
go run script/check-MakeGitError-thread-lock.go go run script/check-MakeGitError-thread-lock.go
LD_LIBRARY_PATH=/opt/libgit2 PKG_CONFIG_PATH=/opt/libgit2/ go test -v -x $(TEST_ARGS) ./... go test $(TEST_ARGS) ./...
add-remote:
git remote add git2go https://github.com/libgit2/git2go.git
install: install:
go install ./... go install ./...
clean:
rm go.*
# Bundled dynamic library # Bundled dynamic library
# ======================= # =======================
# In order to avoid having to manipulate `git_dynamic.go`, which would prevent # In order to avoid having to manipulate `git_dynamic.go`, which would prevent

View File

@ -1,34 +1,47 @@
GO libgit2 git2go
====== ======
[![GoDoc](https://godoc.org/go.wit.com/lib/libgit2?status.svg)](http://godoc.org/go.wit.com/lib/libgit2) [![Build Status](https://travis-ci.org/libgit2/libgit2.svg?branch=main)](https://travis-ci.org/libgit2/libgit2) [![GoDoc](https://godoc.org/github.com/libgit2/git2go?status.svg)](http://godoc.org/github.com/libgit2/git2go) [![Build Status](https://travis-ci.org/libgit2/git2go.svg?branch=main)](https://travis-ci.org/libgit2/git2go)
Go bindings for [libgit2](http://libgit2.github.com/). Go bindings for [libgit2](http://libgit2.github.com/).
### Updated 2024/12/16
### Which Go version to use ### Which Go version to use
* This package is updated to work against libgit2 version 1.8 on Debian sid Due to the fact that Go 1.11 module versions have semantic meaning and don't necessarily align with libgit2's release schedule, please consult the following table for a mapping between libgit2 and git2go module versions:
* There is one line commented out which needs to be fixed in remote.go
* some of the tests seem to run | libgit2 | git2go |
|---------|---------------|
| main | (will be v34) |
| 1.3 | v33 |
| 1.2 | v32 |
| 1.1 | v31 |
| 1.0 | v30 |
| 0.99 | v29 |
| 0.28 | v28 |
| 0.27 | v27 |
You can import them in your project with the version's major number as a suffix. For example, if you have libgit2 v1.2 installed, you'd import git2go v33 with:
```sh ```sh
go install go.wit.com/apps/go-clone@latest go get github.com/libgit2/git2go/v33
go install go.wit.com/apps/go-mod-clean@latest ```
go-clone --recusive go.wit.com/lib/libgit2 ```go
import "github.com/libgit2/git2go/v33"
``` ```
which will ensure there are no sudden changes to the API.
The `main` branch follows the tip of libgit2 itself (with some lag) and as such has no guarantees on the stability of libgit2's API. Thus this only supports statically linking against libgit2.
### Which branch to send Pull requests to ### Which branch to send Pull requests to
TODO: not sure yet If there's something version-specific that you'd want to contribute to, you can send them to the `release-${MAJOR}.${MINOR}` branches, which follow libgit2's releases.
Installing Installing
---------- ----------
This project wraps the functionality provided by libgit2. It thus needs it in order to perform the work. This project wraps the functionality provided by libgit2. It thus needs it in order to perform the work.
This project wraps the functionality provided by libgit2. If you're using a versioned branch, install it to your system via your system's package manager and then install libgit2. This project wraps the functionality provided by libgit2. If you're using a versioned branch, install it to your system via your system's package manager and then install git2go.
### Versioned branch, dynamic linking ### Versioned branch, dynamic linking
@ -36,13 +49,42 @@ This project wraps the functionality provided by libgit2. If you're using a vers
When linking dynamically against a released version of libgit2, install it via your system's package manager. CGo will take care of finding its pkg-config file and set up the linking. Import via Go modules, e.g. to work against libgit2 v1.2 When linking dynamically against a released version of libgit2, install it via your system's package manager. CGo will take care of finding its pkg-config file and set up the linking. Import via Go modules, e.g. to work against libgit2 v1.2
```go ```go
goimports -w *.go import "github.com/libgit2/git2go/v33"
``` ```
### 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/v33 => ../../libgit2/git2go
Parallelism and network operations Parallelism and network operations
---------------------------------- ----------------------------------
libgit2 may use OpenSSL and LibSSH2 for performing encrypted network connections. For now, libgit2 asks libgit2 to set locking for OpenSSL. This makes HTTPS connections thread-safe, but it is fragile and will likely stop doing it soon. This may also make SSH connections thread-safe if your copy of libssh2 is linked against OpenSSL. Check libgit2's `THREADSAFE.md` for more information. libgit2 may use OpenSSL and LibSSH2 for performing encrypted network connections. For now, git2go asks libgit2 to set locking for OpenSSL. This makes HTTPS connections thread-safe, but it is fragile and will likely stop doing it soon. This may also make SSH connections thread-safe if your copy of libssh2 is linked against OpenSSL. Check libgit2's `THREADSAFE.md` for more information.
Running the tests Running the tests
----------------- -----------------
@ -64,6 +106,6 @@ M to the I to the T. See the LICENSE file if you've never seen an MIT license be
Authors Authors
------- -------
- Carlos Martín (github@carlosmn) - Carlos Martín (@carlosmn)
- Vicent Martí (github@vmg) - Vicent Martí (@vmg)

2
git.go
View File

@ -171,7 +171,7 @@ func initLibGit2() {
} }
// Shutdown frees all the resources acquired by libgit2. Make sure no // Shutdown frees all the resources acquired by libgit2. Make sure no
// references to any libgit2 go objects are live before calling this. // references to any git2go objects are live before calling this.
// After this is called, invoking any function from this library will result in // After this is called, invoking any function from this library will result in
// undefined behavior, so make sure this is called carefully. // undefined behavior, so make sure this is called carefully.
func Shutdown() { func Shutdown() {

9
go.mod Normal file
View File

@ -0,0 +1,9 @@
module github.com/libgit2/git2go/v33
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 Normal file
View File

@ -0,0 +1,13 @@
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k=
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88 h1:KmZPnMocC93w341XZp26yTJg8Za7lhb2KhkYmixoeso=
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

95
http.go
View File

@ -1,6 +1,8 @@
package git package git
import ( import (
"crypto/tls"
"crypto/x509"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -16,7 +18,7 @@ import (
// If Shutdown or ReInit are called, make sure that the smart transports are // If Shutdown or ReInit are called, make sure that the smart transports are
// freed before it. // freed before it.
func RegisterManagedHTTPTransport(protocol string) (*RegisteredSmartTransport, error) { func RegisterManagedHTTPTransport(protocol string) (*RegisteredSmartTransport, error) {
return NewRegisteredSmartTransport(protocol, true, httpSmartSubtransportFactory) return NewRegisteredSmartTransport(protocol, true, httpSmartSubtransportFactory(nil))
} }
func registerManagedHTTP() error { func registerManagedHTTP() error {
@ -27,7 +29,7 @@ func registerManagedHTTP() error {
if _, ok := globalRegisteredSmartTransports.transports[protocol]; ok { if _, ok := globalRegisteredSmartTransports.transports[protocol]; ok {
continue continue
} }
managed, err := newRegisteredSmartTransport(protocol, true, httpSmartSubtransportFactory, true) managed, err := newRegisteredSmartTransport(protocol, true, httpSmartSubtransportFactory(nil), true)
if err != nil { if err != nil {
return fmt.Errorf("failed to register transport for %q: %v", protocol, err) return fmt.Errorf("failed to register transport for %q: %v", protocol, err)
} }
@ -36,19 +38,26 @@ func registerManagedHTTP() error {
return nil return nil
} }
func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSubtransport, error) { // httpSmartSubtransportFactory implements SmartSubtransportCallback which
// returns a SmartSubtransport for a remote and transport.
func httpSmartSubtransportFactory(opts *SmartSubtransportOptions) SmartSubtransportCallback {
return func(remote *Remote, transport *Transport) (SmartSubtransport, error) {
sst := &httpSmartSubtransport{
transport: transport,
}
var proxyFn func(*http.Request) (*url.URL, error) var proxyFn func(*http.Request) (*url.URL, error)
remoteConnectOpts, err := transport.SmartRemoteConnectOptions() proxyOpts, err := transport.SmartProxyOptions()
if err != nil { if err != nil {
return nil, err return nil, err
} }
switch remoteConnectOpts.ProxyOptions.Type { switch proxyOpts.Type {
case ProxyTypeNone: case ProxyTypeNone:
proxyFn = nil proxyFn = nil
case ProxyTypeAuto: case ProxyTypeAuto:
proxyFn = http.ProxyFromEnvironment proxyFn = http.ProxyFromEnvironment
case ProxyTypeSpecified: case ProxyTypeSpecified:
parsedUrl, err := url.Parse(remoteConnectOpts.ProxyOptions.Url) parsedUrl, err := url.Parse(proxyOpts.Url)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -56,14 +65,26 @@ func httpSmartSubtransportFactory(remote *Remote, transport *Transport) (SmartSu
proxyFn = http.ProxyURL(parsedUrl) proxyFn = http.ProxyURL(parsedUrl)
} }
return &httpSmartSubtransport{ // Add the proxy to the http transport.
transport: transport, httpTransport := &http.Transport{
client: &http.Client{
Transport: &http.Transport{
Proxy: proxyFn, Proxy: proxyFn,
}, }
},
}, nil // Add any provided certificate to the http transport.
if opts != nil && len(opts.CABundle) > 0 {
cap := x509.NewCertPool()
if ok := cap.AppendCertsFromPEM(opts.CABundle); !ok {
return nil, fmt.Errorf("failed to use certificate from PEM")
}
httpTransport.TLSClientConfig = &tls.Config{
RootCAs: cap,
}
}
sst.client = &http.Client{Transport: httpTransport}
return sst, nil
}
} }
type httpSmartSubtransport struct { type httpSmartSubtransport struct {
@ -89,7 +110,7 @@ func (t *httpSmartSubtransport) Action(url string, action SmartServiceAction) (S
req, err = http.NewRequest("GET", url+"/info/refs?service=git-receive-pack", nil) req, err = http.NewRequest("GET", url+"/info/refs?service=git-receive-pack", nil)
case SmartServiceActionReceivepack: case SmartServiceActionReceivepack:
req, err = http.NewRequest("POST", url+"/info/refs?service=git-upload-pack", nil) req, err = http.NewRequest("POST", url+"/git-receive-pack", nil)
if err != nil { if err != nil {
break break
} }
@ -103,9 +124,9 @@ func (t *httpSmartSubtransport) Action(url string, action SmartServiceAction) (S
return nil, err return nil, err
} }
req.Header.Set("User-Agent", "git/2.0 (libgit2)") req.Header.Set("User-Agent", "git/2.0 (git2go)")
stream := newManagedHttpStream(t, req) stream := newManagedHttpStream(t, req, t.client)
if req.Method == "POST" { if req.Method == "POST" {
stream.recvReply.Add(1) stream.recvReply.Add(1)
stream.sendRequestBackground() stream.sendRequestBackground()
@ -124,6 +145,7 @@ func (t *httpSmartSubtransport) Free() {
type httpSmartSubtransportStream struct { type httpSmartSubtransportStream struct {
owner *httpSmartSubtransport owner *httpSmartSubtransport
client *http.Client
req *http.Request req *http.Request
resp *http.Response resp *http.Response
reader *io.PipeReader reader *io.PipeReader
@ -133,10 +155,11 @@ type httpSmartSubtransportStream struct {
httpError error httpError error
} }
func newManagedHttpStream(owner *httpSmartSubtransport, req *http.Request) *httpSmartSubtransportStream { func newManagedHttpStream(owner *httpSmartSubtransport, req *http.Request, client *http.Client) *httpSmartSubtransportStream {
r, w := io.Pipe() r, w := io.Pipe()
return &httpSmartSubtransportStream{ return &httpSmartSubtransportStream{
owner: owner, owner: owner,
client: client,
req: req, req: req,
reader: r, reader: r,
writer: w, writer: w,
@ -192,6 +215,23 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
var err error var err error
var userName string var userName string
var password string var password string
// Obtain the credentials and use them if available.
cred, err := self.owner.transport.SmartCredentials("", CredentialTypeUserpassPlaintext)
if err != nil {
// Passthrough error indicates that no credentials were provided.
// Continue without credentials.
if err.Error() != ErrorCodePassthrough.String() {
return err
}
} else {
userName, password, err = cred.GetUserpassPlaintext()
if err != nil {
return err
}
defer cred.Free()
}
for { for {
req := &http.Request{ req := &http.Request{
Method: self.req.Method, Method: self.req.Method,
@ -203,10 +243,8 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
req.ContentLength = -1 req.ContentLength = -1
} }
if userName != "" && password != "" {
req.SetBasicAuth(userName, password) req.SetBasicAuth(userName, password)
} resp, err = self.client.Do(req)
resp, err = http.DefaultClient.Do(req)
if err != nil { if err != nil {
return err return err
} }
@ -215,23 +253,6 @@ func (self *httpSmartSubtransportStream) sendRequest() error {
break break
} }
if resp.StatusCode == http.StatusUnauthorized {
resp.Body.Close()
cred, err := self.owner.transport.SmartCredentials("", CredentialTypeUserpassPlaintext)
if err != nil {
return err
}
defer cred.Free()
userName, password, err = cred.GetUserpassPlaintext()
if err != nil {
return err
}
continue
}
// Any other error we treat as a hard error and punt back to the caller // Any other error we treat as a hard error and punt back to the caller
resp.Body.Close() resp.Body.Close()
return fmt.Errorf("Unhandled HTTP error %s", resp.Status) return fmt.Errorf("Unhandled HTTP error %s", resp.Status)

View File

@ -318,7 +318,7 @@ func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedComm
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
return newRebaseFromC(ptr, r, cOpts), nil return newRebaseFromC(ptr, cOpts), nil
} }
// OpenRebase opens an existing rebase that was previously started by either an invocation of InitRebase or by another client. // OpenRebase opens an existing rebase that was previously started by either an invocation of InitRebase or by another client.
@ -340,7 +340,7 @@ func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
return newRebaseFromC(ptr, r, cOpts), nil return newRebaseFromC(ptr, cOpts), nil
} }
// OperationAt gets the rebase operation specified by the given index. // OperationAt gets the rebase operation specified by the given index.
@ -392,27 +392,6 @@ func (rebase *Rebase) Next() (*RebaseOperation, error) {
return newRebaseOperationFromC(ptr), nil return newRebaseOperationFromC(ptr), nil
} }
// InmemoryIndex gets the index produced by the last operation, which is the
// result of `Next()` and which will be committed by the next invocation of
// `Commit()`. This is useful for resolving conflicts in an in-memory rebase
// before committing them.
//
// This is only applicable for in-memory rebases; for rebases within a working
// directory, the changes were applied to the repository's index.
func (rebase *Rebase) InmemoryIndex() (*Index, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
var ptr *C.git_index
err := C.git_rebase_inmemory_index(&ptr, rebase.ptr)
runtime.KeepAlive(rebase)
if err < 0 {
return nil, MakeGitError(err)
}
return newIndexFromC(ptr, rebase.r), nil
}
// Commit commits the current patch. // Commit commits the current patch.
// You must have resolved any conflicts that were introduced during the patch application from the Next() invocation. // You must have resolved any conflicts that were introduced during the patch application from the Next() invocation.
func (rebase *Rebase) Commit(ID *Oid, author, committer *Signature, message string) error { func (rebase *Rebase) Commit(ID *Oid, author, committer *Signature, message string) error {
@ -478,8 +457,8 @@ func (r *Rebase) Free() {
freeRebaseOptions(r.options) freeRebaseOptions(r.options)
} }
func newRebaseFromC(ptr *C.git_rebase, repo *Repository, opts *C.git_rebase_options) *Rebase { func newRebaseFromC(ptr *C.git_rebase, opts *C.git_rebase_options) *Rebase {
rebase := &Rebase{ptr: ptr, r: repo, options: opts} rebase := &Rebase{ptr: ptr, options: opts}
runtime.SetFinalizer(rebase, (*Rebase).Free) runtime.SetFinalizer(rebase, (*Rebase).Free)
return rebase return rebase
} }

View File

@ -8,86 +8,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/ProtonMail/go-crypto/openpgp" "golang.org/x/crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/packet" "golang.org/x/crypto/openpgp/packet"
) )
// Tests // Tests
func TestRebaseInMemoryWithConflict(t *testing.T) {
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
// Create two branches with common history, where both modify "common-file"
// in a conflicting way.
_, err := commitSomething(repo, "common-file", "a\nb\nc\n", commitOptions{})
checkFatal(t, err)
checkFatal(t, createBranch(repo, "branch-a"))
checkFatal(t, createBranch(repo, "branch-b"))
checkFatal(t, repo.SetHead("refs/heads/branch-a"))
_, err = commitSomething(repo, "common-file", "1\nb\nc\n", commitOptions{})
checkFatal(t, err)
checkFatal(t, repo.SetHead("refs/heads/branch-b"))
_, err = commitSomething(repo, "common-file", "x\nb\nc\n", commitOptions{})
checkFatal(t, err)
branchA, err := repo.LookupBranch("branch-a", BranchLocal)
checkFatal(t, err)
onto, err := repo.AnnotatedCommitFromRef(branchA.Reference)
checkFatal(t, err)
// We then rebase "branch-b" onto "branch-a" in-memory, which should result
// in a conflict.
rebase, err := repo.InitRebase(nil, nil, onto, &RebaseOptions{InMemory: 1})
checkFatal(t, err)
_, err = rebase.Next()
checkFatal(t, err)
index, err := rebase.InmemoryIndex()
checkFatal(t, err)
// We simply resolve the conflict and commit the rebase.
if !index.HasConflicts() {
t.Fatal("expected index to have conflicts")
}
conflict, err := index.Conflict("common-file")
checkFatal(t, err)
resolvedBlobID, err := repo.CreateBlobFromBuffer([]byte("resolved contents"))
checkFatal(t, err)
resolvedEntry := *conflict.Our
resolvedEntry.Id = resolvedBlobID
checkFatal(t, index.Add(&resolvedEntry))
checkFatal(t, index.RemoveConflict("common-file"))
var commitID Oid
checkFatal(t, rebase.Commit(&commitID, signature(), signature(), "rebased message"))
checkFatal(t, rebase.Finish())
// And then assert that we can look up the new merge commit, and that the
// "common-file" has the expected contents.
commit, err := repo.LookupCommit(&commitID)
checkFatal(t, err)
if commit.Message() != "rebased message" {
t.Fatalf("unexpected commit message %q", commit.Message())
}
tree, err := commit.Tree()
checkFatal(t, err)
blob, err := repo.LookupBlob(tree.EntryByName("common-file").Id)
checkFatal(t, err)
if string(blob.Contents()) != "resolved contents" {
t.Fatalf("unexpected resolved blob contents %q", string(blob.Contents()))
}
}
func TestRebaseAbort(t *testing.T) { func TestRebaseAbort(t *testing.T) {
// TEST DATA // TEST DATA
@ -319,7 +245,7 @@ func checkCommitSigned(t *testing.T, entity *openpgp.Entity, commit *Commit) err
return err return err
} }
_, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature), nil) _, err = openpgp.CheckArmoredDetachedSignature(openpgp.EntityList{entity}, strings.NewReader(signedData), bytes.NewBufferString(signature))
if err != nil { if err != nil {
t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign()) t.Logf("Commit is not signed correctly\n%s", commit.ContentToSign())
return err return err

View File

@ -1,149 +0,0 @@
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
}

View File

@ -1,75 +0,0 @@
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)
}
}

View File

@ -12,7 +12,6 @@ import "C"
import ( import (
"crypto/x509" "crypto/x509"
"errors" "errors"
"fmt"
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
@ -147,17 +146,6 @@ type FetchOptions struct {
ProxyOptions ProxyOptions ProxyOptions ProxyOptions
} }
type RemoteConnectOptions struct {
// Proxy options to use for this fetch operation
ProxyOptions ProxyOptions
}
func remoteConnectOptionsFromC(copts *C.git_remote_connect_options) *RemoteConnectOptions {
return &RemoteConnectOptions{
ProxyOptions: proxyOptionsFromC(&copts.proxy_opts),
}
}
type ProxyType uint type ProxyType uint
const ( const (
@ -182,8 +170,8 @@ type ProxyOptions struct {
Url string Url string
} }
func proxyOptionsFromC(copts *C.git_proxy_options) ProxyOptions { func proxyOptionsFromC(copts *C.git_proxy_options) *ProxyOptions {
return ProxyOptions{ return &ProxyOptions{
Type: ProxyType(copts._type), Type: ProxyType(copts._type),
Url: C.GoString(copts.url), Url: C.GoString(copts.url),
} }
@ -303,9 +291,6 @@ type PushOptions struct {
// Headers are extra headers for the push operation. // Headers are extra headers for the push operation.
Headers []string Headers []string
// Proxy options to use for this push operation
ProxyOptions ProxyOptions
} }
type RemoteHead struct { type RemoteHead struct {
@ -686,7 +671,7 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
return remote, nil return remote, nil
} }
// CreateWithOptions Creates a repository object with extended options. //CreateWithOptions Creates a repository object with extended options.
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) { func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
remote := &Remote{repo: c.repo} remote := &Remote{repo: c.repo}
@ -984,9 +969,7 @@ func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorT
} }
populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget) populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget)
copts.prune = C.git_fetch_prune_t(opts.Prune) copts.prune = C.git_fetch_prune_t(opts.Prune)
fmt.Println("populateFetchOptions() is broken. fixme!") copts.update_fetchhead = cbool(opts.UpdateFetchhead)
// fix this line: ./remote.go:988:27: cannot use cbool(opts.UpdateFetchhead) (value of type _Ctype_int) as _Ctype_uint value in assignment
// copts.update_fetchhead = cbool(opts.UpdateFetchhead)
copts.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags) copts.download_tags = C.git_remote_autotag_option_t(opts.DownloadTags)
copts.custom_headers = C.git_strarray{ copts.custom_headers = C.git_strarray{
@ -1018,7 +1001,6 @@ func populatePushOptions(copts *C.git_push_options, opts *PushOptions, errorTarg
strings: makeCStringsFromStrings(opts.Headers), strings: makeCStringsFromStrings(opts.Headers),
} }
populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget) populateRemoteCallbacks(&copts.callbacks, &opts.RemoteCallbacks, errorTarget)
populateProxyOptions(&copts.proxy_opts, &opts.ProxyOptions)
return copts return copts
} }
@ -1028,7 +1010,6 @@ func freePushOptions(copts *C.git_push_options) {
} }
untrackCallbacksPayload(&copts.callbacks) untrackCallbacksPayload(&copts.callbacks)
freeStrarray(&copts.custom_headers) freeStrarray(&copts.custom_headers)
freeProxyOptions(&copts.proxy_opts)
} }
// Fetch performs a fetch operation. refspecs specifies which refspecs // Fetch performs a fetch operation. refspecs specifies which refspecs

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Install libgit2 to go libgit2 in dynamic mode on Travis # Install libgit2 to git2go in dynamic mode on Travis
# #
set -ex set -ex

View File

@ -101,14 +101,6 @@ func EnableStrictHashVerification(enabled bool) error {
} }
} }
func EnableFsyncGitDir(enabled bool) error {
if enabled {
return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 1)
} else {
return setSizet(C.GIT_OPT_ENABLE_FSYNC_GITDIR, 0)
}
}
func CachedMemory() (current int, allowed int, err error) { func CachedMemory() (current int, allowed int, err error) {
return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY) return getSizetSizet(C.GIT_OPT_GET_CACHED_MEMORY)
} }

View File

@ -65,14 +65,6 @@ func TestEnableStrictHashVerification(t *testing.T) {
checkFatal(t, err) checkFatal(t, err)
} }
func TestEnableFsyncGitDir(t *testing.T) {
err := EnableFsyncGitDir(false)
checkFatal(t, err)
err = EnableFsyncGitDir(true)
checkFatal(t, err)
}
func TestCachedMemory(t *testing.T) { func TestCachedMemory(t *testing.T) {
current, allowed, err := CachedMemory() current, allowed, err := CachedMemory()
checkFatal(t, err) checkFatal(t, err)

View File

@ -31,7 +31,7 @@ import (
) )
var ( var (
// globalRegisteredSmartTransports is a mapping of global, libgit2 go-managed // globalRegisteredSmartTransports is a mapping of global, git2go-managed
// transports. // transports.
globalRegisteredSmartTransports = struct { globalRegisteredSmartTransports = struct {
sync.Mutex sync.Mutex
@ -41,7 +41,7 @@ var (
} }
) )
// unregisterManagedTransports unregisters all libgit2 go-managed transports. // unregisterManagedTransports unregisters all git2go-managed transports.
func unregisterManagedTransports() error { func unregisterManagedTransports() error {
globalRegisteredSmartTransports.Lock() globalRegisteredSmartTransports.Lock()
originalTransports := globalRegisteredSmartTransports.transports originalTransports := globalRegisteredSmartTransports.transports
@ -84,17 +84,17 @@ type Transport struct {
ptr *C.git_transport ptr *C.git_transport
} }
// SmartRemoteConnectOptions gets a copy of the proxy options for this transport. // SmartProxyOptions gets a copy of the proxy options for this transport.
func (t *Transport) SmartRemoteConnectOptions() (*RemoteConnectOptions, error) { func (t *Transport) SmartProxyOptions() (*ProxyOptions, error) {
runtime.LockOSThread() runtime.LockOSThread()
defer runtime.UnlockOSThread() defer runtime.UnlockOSThread()
var copts C.git_remote_connect_options var cpopts C.git_proxy_options
if ret := C.git_transport_remote_connect_options(&copts, t.ptr); ret < 0 { if ret := C.git_transport_smart_proxy_options(&cpopts, t.ptr); ret < 0 {
return nil, MakeGitError(ret) return nil, MakeGitError(ret)
} }
return remoteConnectOptionsFromC(&copts), nil return proxyOptionsFromC(&cpopts), nil
} }
// SmartCredentials calls the credentials callback for this transport. // SmartCredentials calls the credentials callback for this transport.
@ -219,6 +219,22 @@ type RegisteredSmartTransport struct {
handle unsafe.Pointer handle unsafe.Pointer
} }
// SmartSubtransportOptions is an option for configuring the smart subtransport.
type SmartSubtransportOptions struct {
CABundle []byte
}
// NewRegisterSmartTransportWithOptions registers Go-native transport configured
// with options.
func NewRegisterSmartTransportWithOptions(protocol string, opts *SmartSubtransportOptions) (*RegisteredSmartTransport, error) {
switch protocol {
case "http", "https":
return NewRegisteredSmartTransport(protocol, true, httpSmartSubtransportFactory(opts))
default:
return nil, nil
}
}
// NewRegisteredSmartTransport adds a custom transport definition, to be used // NewRegisteredSmartTransport adds a custom transport definition, to be used
// in addition to the built-in set of transports that come with libgit2. // in addition to the built-in set of transports that come with libgit2.
func NewRegisteredSmartTransport( func NewRegisteredSmartTransport(

1
vendor/libgit2 vendored Submodule

@ -0,0 +1 @@
Subproject commit b7bad55e4bb0a285b073ba5e02b01d3f522fc95d

View File

@ -104,7 +104,7 @@ static int set_callback_error(char *error_message, int ret)
{ {
if (error_message != NULL) { if (error_message != NULL) {
if (ret < 0) if (ret < 0)
giterr_set_str(GIT_ERROR_CALLBACK, error_message); git_error_set_str(GIT_ERROR_CALLBACK, error_message);
free(error_message); free(error_message);
} }
return ret; return ret;