Commit Graph

118 Commits

Author SHA1 Message Date
Edward Thomson
338ceb93b6 Improve documentation 2024-11-26 21:44:09 +00:00
Edward Thomson
cb4b61770f Merge branch 'main' into ethomson/worktree-config 2024-03-11 22:41:25 +00:00
Edward Thomson
b454eba9a7 errors: introduce GIT_ENOTSUPPORTED
libgit2 lacks many of the things that git supports. Give a reasonable
error code for these cases.
2024-03-11 21:07:21 +00:00
Edward Thomson
fb187bd003 config: return GIT_EREADONLY on read-only configs
Introduce `GIT_EREADONLY` and return it when a read-only configuration
is attempted to be mutated. This is preferred over the prior
`GIT_ENOTFOUND` which is not accurate.
2024-03-10 21:35:24 +00:00
Edward Thomson
67a4d04b59 commit: introduce git_commit_create_from_stage
Provide a simple helper method that allows users to create a commit from
the current index with minimal information.
2024-01-15 15:53:19 +00:00
Edward Thomson
f78ae89bf1 errors: move systems things into the sys includes
Most callers only need to _get_ error messages. Only callers implemented
more complicated functions (like a custom ODB for example) need to set
them.

(Callback users should likely ferry their own error information in their
callback payload.)
2023-09-03 14:00:35 +01:00
Edward Thomson
3618a2aa45 errors: never return a NULL error
Callers want to be able to simply call `git_error_last()->message`,
not have to worry about whether `git_error_last()` returns NULL or not.
2023-09-03 14:00:35 +01:00
Edward Thomson
fad9042897 streams: sockets are non-blocking and can timeout
Make socket I/O non-blocking and add optional timeouts.

Users may now set `GIT_OPT_SET_SERVER_CONNECT_TIMEOUT` to set a shorter
connection timeout. (The connect timeout cannot be longer than the
operating system default.) Users may also now configure the socket read
and write timeouts with `GIT_OPT_SET_SERVER_TIMEOUT`.

By default, connects still timeout based on the operating system
defaults (typically 75 seconds) and socket read and writes block.

Add a test against our custom testing git server that ensures that we
can timeout reads against a slow server.
2023-05-13 16:42:04 +01:00
yuangli
52ba17f3d6 Merge branch 'pr/pks-t/5254' into shallow-clone-local 2022-07-26 16:26:32 +01:00
Yuang Li
e07aa9c3c4 Merge branch 'main' into pr/pks-t/5254 2022-06-24 13:21:48 +01:00
Edward Thomson
c0dfd1ad97 repo: ensure that repo dir is owned by current user
Ensure that the repository directory is owned by the current user; this
prevents us from opening configuration files that may have been created
by an attacker.
2022-04-11 22:15:45 -04:00
Edward Thomson
36df49c26d sha: GIT_ERROR_SHA1 is deprecated in favor of GIT_ERROR_SHA
The more generic GIT_ERROR_SHA allows for SHA256 errors as well as SHA1.
2022-03-23 08:39:19 -04:00
Edward Thomson
49e180c862 errors: expose git_error_set
The `git_error_set` function is useful for callers who implement
backends and advanced callbacks.  Expose it.
2022-02-22 22:07:44 -05:00
Peter Pettersson
38c3449822 Make enum in includes C90 compliant by removing trailing comma. 2021-11-15 16:45:40 +01:00
Edward Thomson
9937967efd Merge branch 'main' into http-use-eauth 2021-08-29 21:29:14 -04:00
Patrick Steinhardt
05e286fba3 grafts: move parsing into grafts module
Parsing of grafts files is currently contained in the repository code.
To make grafts-related logic more self-contained, move it into
"grafts.c" instead.
2020-06-27 14:33:58 +02:00
Edward Thomson
abe2efe1ff Introduce GIT_ASSERT macros
Provide macros to replace usages of `assert`.  A true `assert` is
punishing as a library.  Instead we should do our best to not crash.

GIT_ASSERT_ARG(x) will now assert that the given argument complies to
some format and sets an error message and returns `-1` if it does not.

GIT_ASSERT(x) is for internal usage, and available as an internal
consistency check.  It will set an error message and return `-1` in the
event of failure.
2020-05-11 20:13:54 +01:00
Josh Bleecher Snyder
b8aedc84ca use consistent whitespace before comments 2020-02-07 09:44:21 -08:00
Edward Thomson
f78f6bd597 error functions: return an int
Stop returning a void for functions, future-proofing them to allow them
to fail.
2020-01-24 15:12:56 -06:00
Edward Thomson
e9cef7c4b1 http: introduce GIT_ERROR_HTTP
Disambiguate between general network problems and HTTP problems in error
codes.
2020-01-24 10:39:56 -06:00
Edward Thomson
a7d0d14fb0 deprecation: move deprecated bits to deprecated.h 2019-01-25 09:06:50 +00:00
Edward Thomson
647dfdb42d git_error: deprecate error values
Replace the `GITERR` values with a `const int` to deprecate error
values.
2019-01-22 22:26:51 +00:00
Edward Thomson
20961b9871 git_error: use full class name in public error API
Move to the `git_error` name in error-related functions, deprecating the
`giterr` functions.  This means, for example, that `giterr_last` is now
`git_error_last`.  The old names are retained for compatibility.

This only updates the public API; internal API and function usage
remains unchanged.
2019-01-22 22:26:51 +00:00
Edward Thomson
a2e6e0ea0e transport: allow cred/cert callbacks to return GIT_PASSTHROUGH
Allow credential and certificate checking callbacks to return
GIT_PASSTHROUGH, indicating that they do not want to act.
Introduce this to support in both the http and ssh callbacks.
Additionally, enable the same mechanism for certificate validation.

This is most useful to disambiguate any meaning in the publicly exposed
credential and certificate functions (`git_transport_smart_credentials`
and `git_transport_smart_certificate_check`) but it may be more
generally useful for callers to be able to defer back to libgit2.
2018-11-21 23:06:12 +00:00
Edward Thomson
c3077ea0fa apply: return a specific exit code on failure
Return `GIT_EAPPLYFAIL` on patch application failure so that users can
determine that patch application failed due to a malformed/conflicting
patch by looking at the error code.
2018-11-04 09:21:48 +00:00
Patrick Steinhardt
7edc1c870e Merge pull request #4788 from tiennou/doc-fixes
Documentation fixes
2018-08-30 12:51:05 +02:00
Etienne Samson
7765c0a9ff doc: fix comment on GIT_EUSER 2018-08-29 21:56:26 +02:00
Johan Abildskov
c0b2e5256c Add two words to clarify 2018-08-27 09:23:02 +02:00
Johan Abildskov
4bd2a508fb Update giterr_last API documentation to reflect real behaviour 2018-08-20 13:51:28 +02:00
Edward Thomson
787768c2d7 index: return a unique error code on dirty index
When the index is dirty, return GIT_EINDEXDIRTY so that consumers can
identify the exact problem programatically.
2018-06-29 14:54:28 +01:00
Patrick Steinhardt
28a0741f1a odb: verify object hashes
The upstream git.git project verifies objects when looking them up from
disk. This avoids scenarios where objects have somehow become corrupt on
disk, e.g. due to hardware failures or bit flips. While our mantra is
usually to follow upstream behavior, we do not do so in this case, as we
never check hashes of objects we have just read from disk.

To fix this, we create a new error class `GIT_EMISMATCH` which denotes
that we have looked up an object with a hashsum mismatch. `odb_read_1`
will then, after having read the object from its backend, hash the
object and compare the resulting hash to the expected hash. If hashes do
not match, it will return an error.

This obviously introduces another computation of checksums and could
potentially impact performance. Note though that we usually perform I/O
operations directly before doing this computation, and as such the
actual overhead should be drowned out by I/O. Running our test suite
seems to confirm this guess. On a Linux system with best-of-five
timings, we had 21.592s with the check enabled and 21.590s with the
ckeck disabled. Note though that our test suite mostly contains very
small blobs only. It is expected that repositories with bigger blobs may
notice an increased hit by this check.

In addition to a new test, we also had to change the
odb::backend::nonrefreshing test suite, which now triggers a hashsum
mismatch when looking up the commit "deadbeef...". This is expected, as
the fake backend allocated inside of the test will return an empty
object for the OID "deadbeef...", which will obviously not hash back to
"deadbeef..." again. We can simply adjust the hash to equal the hash of
the empty object here to fix this test.
2017-04-28 14:05:45 +02:00
Edward Thomson
cc8d9a29e7 win32: introduce do_with_retries macro
Provide a macro that will allow us to run a function with posix-like
return values multiple times in a retry loop, with an optional cleanup
function called between invocations.
2017-04-01 10:47:30 +01:00
Edward Thomson
2dfd1294f7 hash: include sha1collisiondetection
Include the SHA1 collision attack detection library from
https://github.com/cr-marcstevens/sha1collisiondetection
2017-03-03 10:50:27 +00:00
Patrick Steinhardt
372dc9ff6a worktree: implement git_worktree_validate
Add a new function that checks wether a given `struct
git_worktree` is valid. The validation includes checking if the
gitdir, parent directory and common directory are present.
2017-02-13 10:59:16 +01:00
Edward Thomson
7cb904ba44 Introduce git_apply_patch
The beginnings of patch application from an existing (diff-created)
git_patch object: applies the hunks of a git_patch to a buffer.
2016-05-26 11:36:11 -05:00
Edward Thomson
cd59e0c0c7 giterr_set_str: remove GITERR_OS documentation
The `giterr_set_str` does not actually honor `GITERR_OS`.  Remove
the documentation that claims that we do.
2016-02-23 13:08:58 -05:00
Edward Thomson
8683d31f08 merge: add GIT_MERGE_TREE_FAIL_ON_CONFLICT
Provide a new merge option, GIT_MERGE_TREE_FAIL_ON_CONFLICT, which
will stop on the first conflict and fail the merge operation with
GIT_EMERGECONFLICT.
2015-10-22 14:55:17 -04:00
Michael Procter
25dbcf3499 Make giterr_detach no longer public 2015-08-03 15:23:17 +01:00
Carlos Martín Nieto
8a52ed7a48 errors: add EDIRECTORY
This is to be returned when the operation which the user asked for is
not possible to do on a directory.
2015-07-12 12:11:22 +02:00
Edward Thomson
82b1c93d08 stash: don't allow apply with staged changes 2015-06-25 18:34:36 -04:00
Carlos Martín Nieto
189aad45af errors: introduce EINVALID
We've been using EINVALIDSPEC for a while to mean this, but that name
is too specific. Introduce this to be more explicit.
2015-06-24 23:49:10 +02:00
Edward Thomson
885b94aac0 Rename GIT_EMERGECONFLICT to GIT_ECONFLICT
We do not error on "merge conflicts"; on the contrary, merge conflicts
are a normal part of merging.  We only error on "checkout conflicts",
where a change exists in the index or the working directory that would
otherwise be overwritten by performing the checkout.

This *may* happen during merge (after the production of the new index
that we're going to checkout) but it could happen during any checkout.
2015-05-29 09:55:09 -04:00
Carlos Martín Nieto
1396c38178 errors: add GIT_EEOF to indicate early EOF
This can be used by tools to show mesages about failing to communicate
with the server. The error message in this case will often contain the
server's error message, as far as it managed to send anything.
2015-05-20 15:08:39 +02:00
Edward Thomson
fe598f0903 mkdir: walk up tree to mkdir
Walk up the tree to mkdir, which is less immediately efficient,
but allows us to look at intermediate directories that may need
attention.
2015-01-20 17:12:46 -06:00
Carlos Martín Nieto
753e17b0f5 peel: reject bad queries with EINVALIDSPEC
There are some combination of objects and target types which we know
cannot be fulfilled. Return EINVALIDSPEC for those to signify that there
is a mismatch in the user-provided data and what the object model is
capable of satisfying.

If we start at a tag and in the course of peeling find out that we
cannot reach a particular type, we return EPEEL.
2014-11-22 18:55:22 +01:00
Edward Thomson
93a7004cc2 git_rebase_commit: drop already-picked commits
Already cherry-picked commits should not be re-included.  If all changes
included in a commit exist in the upstream, then we should error with
GIT_EAPPLIED.
2014-10-26 22:59:21 -04:00
Edward Thomson
867a36f3a6 Introduce git_rebase to set up a rebase session
Introduce `git_rebase` to set up a rebase session that can
then be continued.  Immediately, only merge-type rebase is
supported.
2014-10-26 22:59:08 -04:00
Carlos Martín Nieto
af6cc38fc0 Merge remote-tracking branch 'upstream/master' into cmn/describe 2014-09-30 04:38:05 +02:00
Carlos Martín Nieto
9b9405865e Provide a callback for certificate validation
If the certificate validation fails (or always in the case of ssh),
let the user decide whether to allow the connection.

The data structure passed to the user is the native certificate
information from the underlying implementation, namely OpenSSL or
WinHTTP.
2014-09-16 17:01:30 +02:00
Carlos Martín Nieto
8873728f37 Introduce GIT_EAUTH
Introduce this error code to signal an authentication failure.
2014-06-26 22:58:38 +02:00