Commit Graph

992 Commits

Author SHA1 Message Date
lhchavez 10c67474a8
More callback refactoring (#713)
This change:

* Gets rid of the `.toC()` functions for Options objects, since they
  were redundant with the `populateXxxOptions()`.
* Adds support for `errorTarget` to the `RemoteOptions`, since they are
  used in the same stack for some functions (like `Fetch()`). Now for
  those cases, the error returned by the callback will be preserved
  as-is.
2020-12-10 07:19:41 -08:00
lhchavez e28cce87c7
Ensure that no pointer handles leak during the test (#712)
This change makes sure that pointer handles are correctly cleaned up
during tests.
2020-12-10 05:35:40 -08:00
lhchavez abf02bc7d7
Add `NewCredentialSSHKeyFromSigner` (#706)
This change adds `NewCredentialSSHKeyFromSigner`, which allows idiomatic
use of SSH keys from Go. This also lets us spin off an SSH server in the
tests.
2020-12-06 11:55:04 -08:00
lhchavez 54afccfa0f
Build improvements (#707)
This change makes the test be verbose and use parallelization if
possible (when using gmake to build).
2020-12-06 06:13:38 -08:00
lhchavez 5d8eaf7e65
Refactor all callbacks (#700)
This change is a preparation for another change that makes all callback
types return a Go error instead of an error code / an integer. That is
going to make make things a lot more idiomatic.

The reason this change is split is threefold:

a) This change is mostly mechanical and should contain no semantic
   changes.
b) This change is backwards-compatible (in the Go API compatibility
   sense of the word), and thus can be backported to all other releases.
c) It makes the other change a bit smaller and more focused on just one
   thing.

Concretely, this change makes all callbacks populate a Go error when
they fail. If the callback is invoked from the same stack as the
function to which it was passed (e.g. for `Tree.Walk`), it will preserve
the error object directly into a struct that also holds the callback
function. Otherwise if the callback is pased to one func and will be
invoked when run from another one (e.g. for `Repository.InitRebase`),
the error string is saved into the libgit2 thread-local storage and then
re-created as a `GitError`.
2020-12-05 13:13:59 -08:00
lhchavez 137c05e802
Mark some symbols to be deprecated #minor (#698)
This change introduces the file deprecated.go, which contains any
constants, functions, and types that are slated to be deprecated in the
next major release.

These symbols are deprecated because they refer to old spellings in
pre-1.0 libgit2. This also makes the build be done with the
`-DDEPRECATE_HARD` flag to avoid regressions.

This, together with
[gorelease](https://godoc.org/golang.org/x/exp/cmd/gorelease)[1] should
make releases safer going forward.

1: More information about how that works at
   https://go.googlesource.com/exp/+/refs/heads/master/apidiff/README.md
2020-12-05 07:23:44 -08:00
nmeum 1fabe95fb7
Relax libgit2 minor version check (#696)
The major version must still be an exact match since libgit2 uses
semantic versioning and changes to the major number indicate backwards
incompatible changes to the API.

Fixes: #695
2020-11-28 11:10:34 -08:00
Hans Duedal 7497529f70
Expose GIT_CERT_SSH_SHA256 (#690)
Newer versions of libssh2 use SHA256 fingerprints
2020-11-26 17:32:24 -08:00
Segev Finer 2bd574b6bd
Add ReferenceNormalizeName (#681) 2020-11-13 16:50:59 -08:00
Devendra 2d639d8e49
Travis-ci: added support for ppc64le (#682)
Added power support for the travis.yml file with ppc64le. This is part of the Ubuntu distribution for ppc64le. This helps us simplify testing later when distributions are re-building and re-releasing.
2020-11-13 05:32:44 -08:00
Suhaib Mujahid ccbe4719bd
Add GIT_BLAME_IGNORE_WHITESPACE flag (#677)
The `GIT_BLAME_IGNORE_WHITESPACE` blame option flag was introduced in libgit2 v1.1.0

Change type: #minor
2020-11-07 15:02:03 -08:00
Suhaib Mujahid b46ebfab8c
Add GIT_BLAME_USE_MAILMAP flag (#676)
The `GIT_BLAME_USE_MAILMAP` blame option flag was introduced in libgit2 v0.28

Change type: #minor
2020-11-07 14:54:23 -08:00
lhchavez 77460dd7f0
Use the correct branch name for backporting into v1.0 (#674)
This change uses the correct branch name (`release-1.0`) to backport
changes into the v1.0 branch.
2020-11-02 19:15:32 -08:00
Suhaib Mujahid c3664193f3
feat: Implement an option to control hash verification (#671)
Add a binding to enable/disable hash verification using the `GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION` option.

Change type: #minor
2020-11-02 18:36:20 -08:00
Suhaib Mujahid ad3ec3664d
Create v31 to support libgit2 v1.1.x (#668)
The libgit2 `v1.1.0` is released two weeks ago. This PR allows `git2go` to link against the new version.
2020-10-26 18:09:26 -07:00
lhchavez f83530b18d
CI refresh (#666)
This change:

* Makes the Travis tests only run tip, since the rest of the Go versions are better served by GitHub Actions.
* Use Go 1.15 in the CI. This has been released for a while.
2020-10-23 05:47:14 -07:00
Sami Hiltunen 10d5ebf231
apply: Add bindings for git_apply_to_tree (#657)
Adds bindings to the git_apply_to_tree function that allows applying
a diff directly to a tree.
2020-10-23 05:17:38 -07:00
lhchavez 3a4204bd93
Make `TestApplyDiffAddFile()` explicitly `.Free()` stuff (#661)
This change adds explicit `.Free()` calls in `TestApplyDiffAddFile()`.
It was discovered in #657 that some objects were not explicitly being
freed, so this fixes that!
2020-10-22 06:30:31 -07:00
Suhaib Mujahid 5b6ce70b89
refactor: Use undeprecated options init (#656)
This PR move form linking against the deprecated `init_options` functions to the renamed `options_init` functions.

For more context see libgit2/libgit2@0b5ba0d744 and libgit2/libgit2@c6184f0c4b.
2020-10-22 06:18:11 -07:00
Patrick Steinhardt 37b81b61f1
repository: Implement wrappers for `git_object_lookup_prefix` (#658)
While we already have wrappers for `git_object_lookup`, there are none
yet for the prefixed variant where only the first n bytes of the OID are
used for the lookup. This commit adds them.
2020-10-22 05:21:25 -07:00
Suhaib Mujahid 111185838c
feat: Enable change the system install path (#653)
#### Problem:
The current `CMAKE_INSTALL_PREFIX` value for the `system` build mode is `/usr`. However, in`macOS` as an example, you cannot write to `/usr` without `sudo` permission.

#### Proposed solution:
Enable changing the value to `/usr/local` (or any other path). This change makes the script use the value of the environment variable `SYSTEM_INSTALL_PREFIX` to select the installation path.  If the variable is not set, it fallback to the path `/usr`.
2020-09-30 17:27:48 -07:00
Suhaib Mujahid f3a746d7b6
Enable set the VENDORED_PATH for libgit2 (#650)
### What this change is doing?
This change aims to enable us to set the `VENDORED_PATH` as an environment variable and failback to the default value if the environment variable is not set. Thus, this change should not break current behavior.

### Why we need this?
This will enable using the script to build libgit2 form source code downloaded manually.

Example:
```sh
LIBGIT2_VER="1.0.1"
DOWNLOAD_URL="https://codeload.github.com/libgit2/libgit2/tar.gz/v${LIBGIT2_VER}""
LIBGIT2_PATH="${HOME}/libgit2-${LIBGIT2_VER}"
wget -O "${LIBGIT2_PATH}.tar.gz" "$DOWNLOAD_URL"
tar -xzvf "${LIBGIT2_PATH}.tar.gz"


VENDORED_PATH=$LIBGIT2_PATH sh ./script/build-libgit2.sh --static
```
2020-09-30 16:57:50 -07:00
Jesse Hathaway 3c5c580d78
Add a ReInit function (#647)
libgit2 stores the lookup paths for gitconfig files in its global state.
This means that after a program changes its effective uid libgit2 will
still look for gitconfig files in the home directory of the original
uid. Expose a way to call C.git_libgit2_init so a user can reinitialize
the libgit2 global state.
2020-09-29 15:42:20 -07:00
Patrick Steinhardt 7e726fda6e
merge: Expose recursion limit merge option (#642)
The `recursion_limit` merge option provided by libgit2 is currently not
exposed and thus inaccessible to Git2Go users. Let's expose it to let
users control creation of recursive merge bases.
2020-09-18 05:43:56 -07:00
michael boulton 7d4453198b
Add support for creating signed commits and signing commits during a rebase (#626) 2020-08-18 09:25:31 -07:00
michael boulton 7883ec85de
More diff functionality (#629)
This PR adds

- The ability to apply a Diff object to the repo
- Support for git_apply_hunk_cb and git_apply_delta_cb callbacks in options for applying the diffs
- The ability to import a diff from a raw buffer (for example, one exported by ToBuf) into a Diff object associated with the repo
- Tests for the above
2020-08-18 06:14:02 -07:00
lhchavez 2ac9f4e69b
Add two more GitHub Actions workflows (#633)
This change adds:

* `tag.yml`: Creates a new tag every time the master or a release branch
  is pushed.
* `backport.yml`: Creates a cherry-pick in older release branches to
  keep them up to date with little cost.
2020-08-16 07:27:17 -07:00
lhchavez 5314951759
Refresh the GitHub Actions CI (#632)
This change:

* Builds the library with Go 1.14, too.
* Builds the non-legacy tests with Ubuntu Focal (20.04).
* Adds testing for system-wide libraries, both static and dynamic
  versions.
* Fixes a typo in the README.
2020-08-15 17:19:53 -07:00
michael boulton fc6eaf3638
Fix null pointer dereference in status.ByIndex (#628)
`git_status_byindex` can return a null pointer if there is no statuses.
2020-08-14 11:19:21 -07:00
Yuichi Watanabe 462ebd83e0
Add support for git_blob_is_binary (#625)
This adds IsBinary() func to Blob struct, which simply returns the result of git_blob_is_binary function.
Refs: https://libgit2.org/libgit2/#HEAD/group/blob/git_blob_is_binary
Issue: Add support for git_blob_is_binary #426

Fixes: #426
2020-07-30 05:07:05 -07:00
Patrick Steinhardt d8f9990d4d
Fix installation of libgit2 into wrong libdir (#624)
Upstream libgit2 has migrated to use the GNUInstallDirs module to decide
where things will be installed to by default. While it improves
consistency with the host system, we're not really after that when
building the vendored libgit2 library, and in fact libgit2.{a,pc} may
now be installed into a different directory than before as it started to
depend on the host platform.

Fix this by explicitly specifying that we want the library and pkgconfig
file to be installed into a plain "lib/" directory.
2020-07-25 13:08:04 -07:00
Jesse Hathaway b1cad11555
FetchOptions: add ability to specify ProxyOptions (#623)
Prior to this change you could not specifiy proxy options on the
FetchOptions struct, which made it impossible to specify a proxy for an
initial clone. This change adds the ProxyOptions to the FetchOptions
struct so you can go through a proxy when cloning.
2020-07-10 13:00:52 -07:00
lhchavez 20a55cdf92
Revamp the ways in which the library can be built (#621)
This change allows to link the system version of libgit2 statically.
Since `-tags static` is already used for the bundled version of the
library and to avoid breaking old workflows, `-tags
static,system_libgit2` is now used to select that.

This means that the valid combinations are:

| Flag                          | Effect                                        |
|-------------------------------|-----------------------------------------------|
| _No flags_                    | Dynamically-linked against the system libgit2 |
| `-tags static,system_libgit2` | Statically-linked against the system libgit2  |
| `-tags static`                | Statically-linked against the bundled libgit2 |

Note that there is no way to express dynamically linking against the
bundled libgit2 because that makes very little sense, since the binaries
wouldn't be able to be distributed. If that's still desired, the
`PKG_CONFIG_PATH` environment variable can set before building the code.
[`Makefile`](https://github.com/libgit2/git2go/blob/master/Makefile) has
an example of how it is used in the CI.
2020-06-21 15:40:52 -07:00
lhchavez c78ae57de6
Fix a potential use-after-free in DiffNotifyCallback (#579)
This change makes the DiffNotifyCallback always use an "unowned"
*git.Diff that does _not_ run the finalizer. Since the underlying
git_diff object is still owned by libgit2, we shouldn't be calling
Diff.Free() on it, even by accident, since that would cause a whole lot
of undefined behavior.

Now instead of storing a reference to a *git.Diff in the intermediate
state while the diff operation is being done, create a brand new
*git.Diff for every callback invocation, and only create a fully-owned
*git.Diff when the diff operation is done and the ownership is
transfered to Go.
2020-06-21 06:45:39 -07:00
lhchavez 619a9c236b
Add a way to cleanly shut down the library (#578)
This change adds the Shutdown() method, so that the library can be
cleanly shut down. This helps significanly reduce the amount of noise in
the leak detector.
2020-06-21 06:44:06 -07:00
lhchavez 9eaf4fed5f
Update the `README.md` to clarify some aspects of static libgit2 (#620)
This change improves the documentation surrounding libgit2 static builds
and modules.

Fixes: #618
2020-06-20 16:24:46 -07:00
lhchavez 1c9bef0f9f
Remove a couple of now-unnecessary CMake defines (#619)
This change removes the `LIB_INSTALL_DIR` and `INCLUDE_INSTALL_DIR` from
the `script/build-libgit2.sh` script, since they are now unneeded and
just print a warning if they are used.
2020-06-20 12:39:03 -07:00
Takuji Shimokawa 33dac3d460
Provide missing merge flags (#615)
This change adds two missing merge flags MergeTreeSkipREUC and MergeTreeNoRecursive.
2020-06-04 20:34:37 -07:00
Jesse Hathaway 5241c72e6e
Add support for parsing git trailers (#614)
Adds a wrapper for git_message_trailers which returns a slice of trailer
structs.
2020-06-02 10:30:42 -07:00
lhchavez 31f877e249
Merge pull request #582 from suhaibmujahid/method-rename
It is not Go idiomatic to put Get into the getter's name
2020-05-09 20:39:51 -07:00
Suhaib Mujahid cf6522c7fe refactor: Rename methods with Get prefix
It is not Go idiomatic to put Get into the getter's name.

https: //golang.org/doc/effective_go.html#Getters
Co-Authored-By: lhchavez <lhchavez@users.noreply.github.com>
2020-05-09 23:32:17 -04:00
lhchavez 8b51d0db8e
expose options related to caching 2020-05-04 17:44:13 -07:00
Vladimir Buzuev 862cde393c cache_opts: address PR comments 2020-05-04 11:01:38 -07:00
Suhaib Mujahid 91d08450b6 Check nil signature 2020-04-23 16:26:35 -07:00
Vladimir Buzuev 512f37b369 expose options related to caching 2020-04-03 11:51:20 -07:00
lhchavez 13ca96065e Uprev vendor/libgit2 to v1.0
This uprevs libgit2 to the latest and greatest.
2020-04-02 07:53:59 -07:00
lhchavez 0843b826d2
Fix SIGSEGV on double free for Cred object
This change removes the Go finalizer when passing ownership to libgit2.

Fixes: #553
2020-03-26 17:50:12 -07:00
Vladimir Buzuev 89dc80bbea clear native cred pointer after transfer ownership to libgit 2020-03-26 17:30:05 -07:00
Vladimir Buzuev 033ad6e5ef fix SIGSERV on double free for Cred object 2020-03-26 14:43:43 -07:00
Suhaib Mujahid 3a2102638d Update README.md 2020-03-23 18:22:12 -07:00