Commit Graph

3820 Commits

Author SHA1 Message Date
Edward Thomson
096cc6f76d commit: introduce a signing callback
Callers can now introduce a commit signing callback instead of needing
to call a specialized commit buffer creation function.
2026-06-01 21:23:59 +01:00
Edward Thomson
a7786fcd7e commit: support custom user-specified headers
Some clients (eg GitButler) are storing additional information in custom
user-specified commit headers. We should make this a first-class
concept.
2026-06-01 21:23:59 +01:00
Edward Thomson
a7e1eb2638 Merge pull request #7245 from mrdimidium/main 2026-05-30 18:56:01 +01:00
Edward Thomson
43bbc31735 Merge branch 'pr/7170' 2026-05-25 21:50:30 +01:00
Edward Thomson
9710edbd8b regex: apple's regcomp got weird with locales 2026-05-22 17:19:45 +01:00
Yelninei
84806965a0 tests: Remove GITTEST_FLAKY_STAT environment variable.
This was caused by the tests being compiled with -D_FILE_OFFSET_BITS=64
which causes incompatibilities if libgit2 itself is not.

As this has been resolved the environment variable is no longer
necessary and can be removed.
2026-05-16 12:34:36 +00:00
Yelninei
4ae8367b4e tests: Fix stat tests on 32bit systems.
On 32bit systems the git_fs_path_lstat from libgit2 by default uses 32bit stat
structs while the tests are being compiled with struct stat64 via
_FILE_OFFSET_BITS=64.

This discrepancy causes the "flaky" stat failures in tests.

The solution is to use the same _FILE_OFFSET_BITS as the library by
setting _FILE_OFFSET_BITS globally

Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-05-16 12:34:03 +00:00
Cameron Will
3d1e45895e fix: Recognize relative worktrees extension
Git supports relative worktrees since Git v2.48 - cf6f63ea6b/Documentation/RelNotes/2.48.0.adoc (L57)

This was already handled programatically in libgit2, but was
not recognized as an extension, meaning downstream consumers
like Nix had issues with relative worktree-enabled repos.

Fixes #7210
2026-05-08 15:14:16 -04:00
Edward Thomson
160bb3d942 Merge pull request #7220 from libgit2/ethomson/faster_sha256_oids
oid: sha1s must now be zero-padded
2026-05-06 23:35:04 +01:00
Edward Thomson
3a244c6875 Merge pull request #7052 from QiuYitai/main
Fix the null reference vulnerability.
2026-05-06 23:05:55 +01:00
Edward Thomson
e279d645f1 oid: sha1s must now be zero-padded
Now that we have two types of object IDs, with different sizes, we
expect shorter object ID types (in other words, SHA1 object ids) to be
zero-padded at their suffix. This allows us to use faster comparison and
copy routines over the entirety of the structure, instead of trying to
examine the type and then do a comparison of the appropriately sized
structure.

For pure manipulation of object IDs, this produces parity with the
SHA1-only object ID code.

SHA1:
oid::cmp_sha1:  8.065 ms ± 703.9 μs / range: 7.875 ms … 14.88 ms  (201 runs)
oid::cmp_sha256:  skipped
oid::cpy_sha1:  5.340 ms ± 47.26 μs / range: 5.272 ms … 5.617 ms  (548 runs)
oid::cpy_sha256:  skipped
oid::zero_sha1:  5.327 ms ± 49.27 μs / range: 5.271 ms … 5.612 ms  (553 runs)
oid::zero_sha256:  skipped

SHA256 (before this change; testing the `type`):
oid::cmp_sha1:  10.82 ms ± 1.029 ms / range: 10.57 ms … 20.63 ms  (145 runs)
oid::cmp_sha256:  10.63 ms ± 103.9 μs / range: 10.50 ms … 11.48 ms  (279 runs)
oid::cpy_sha1:  26.13 ms ± 63.91 μs / range: 26.07 ms … 26.45 ms  (113 runs)
oid::cpy_sha256:  20.92 ms ± 58.32 μs / range: 20.86 ms … 21.25 ms  (141 runs)
oid::zero_sha1:  13.19 ms ± 129.1 μs / range: 13.11 ms … 13.72 ms  (224 runs)
oid::zero_sha256:  13.12 ms ± 30.06 μs / range: 13.10 ms … 13.30 ms  (225 runs)

SHA256 (with this change):
oid::cmp_sha1:  7.985 ms ± 562.3 μs / range: 7.874 ms … 14.32 ms  (209 runs)
oid::cmp_sha256:  6.609 ms ± 30.77 μs / range: 6.584 ms … 6.870 ms  (443 runs)
oid::cpy_sha1:  5.282 ms ± 21.90 μs / range: 5.266 ms … 5.524 ms  (543 runs)
oid::cpy_sha256:  5.279 ms ± 17.57 μs / range: 5.263 ms … 5.415 ms  (554 runs)
oid::zero_sha1:  5.288 ms ± 22.92 μs / range: 5.268 ms … 5.508 ms  (544 runs)
oid::zero_sha256:  5.286 ms ± 21.29 μs / range: 5.271 ms … 5.527 ms  (542 runs)
2026-05-06 23:03:46 +01:00
Edward Thomson
af1e2fa3d0 Merge pull request #7117 from pks-gitlab/pks/reftables-support
Reftables support
2026-05-06 22:02:32 +01:00
Edward Thomson
b6a9e9a994 Merge pull request #7051 from timonvo/diff-from-buffer-binary-roundtrip
diff: make `git_diff_from_buffer` diffs show binary data when printed.
2026-05-06 21:48:25 +01:00
Edward Thomson
07c737f235 Merge pull request #7249 from kcsaul/fix/missing-library-error
cmake: fix linker error when using ninja build generator
2026-05-04 21:29:15 +01:00
Kevin Saul
50fa757381 cmake: fix linker error when using ninja build generator 2026-05-05 07:40:20 +12:00
Edward Thomson
4cc873458e Merge pull request #7003 from mathworks/lrm29/issue6963
submodule: git_index_add_bypath does not move conflict entries to REU…
2026-05-03 12:48:11 +01:00
Nikolay Govorov
dac34eeecd Add build flag for disable http transport 2026-05-03 12:41:49 +01:00
Edward Thomson
38a5767ec5 Merge pull request #7001 from libgit2/ethomson/object_id
Introduce `git_object_id_from...` APIs
2026-05-02 17:36:17 +01:00
Edward Thomson
af304578e1 Merge pull request #7049 from mathworks/git_indexer_stats_init
indexer: Initialise all members of git_indexer_progress
2026-05-02 17:34:44 +01:00
Edward Thomson
8bb32e5780 object: move internal use to git_object_id_from...
Using the `git_object_id_from` is an overall code simplification; switch
to it.
2026-05-02 14:17:21 +01:00
Edward Thomson
200aace53d Merge pull request #7165 from ambv/tcp-keepalive
fix: prevent SSH timeout infinite loop and enable TCP keepalive
2026-05-02 14:12:25 +01:00
Edward Thomson
643b7e1038 merge_files: some simplification 2026-05-02 08:24:18 +01:00
Edward Thomson
8d4d980b10 merge_files: test with zero-byte file
Test handing a zero byte but extant file to merge_files.
2026-05-02 08:24:18 +01:00
Edward Thomson
cefc409a97 Merge pull request #7092 from eantoranz/git_merge_file_from_index-null_child
git_merge_file_from_index: handle cases when a child (ours or theirs) is null
2026-04-30 23:39:06 +01:00
Edward Thomson
70ff46d7fe Merge pull request #7236 from libgit2/ethomson/lengths
Check object lengths against headers in `read_loose`
2026-04-30 23:19:07 +01:00
Edward Thomson
a1c807c79e object: test looking up truncated objects
Add a test that looks up an invalid, truncated object, that is shorter
than the advertised length.
2026-04-30 22:59:20 +01:00
Kevin Saul
3b5ecb0d42 config: update memory backend test to reproduce crash 2026-04-29 22:11:28 +12:00
Edward Thomson
1e7d7c07d0 Merge pull request #7195 from weihanglo/insteadof
fix: apply insteadOf from global config for detached remotes
2026-04-24 11:19:47 +01:00
Weihang Lo
e047e80074 fix(transport): get oid_type on local transport
Cache `oid_type` in `transport_local` struct during `connect()`
so `git_remote_oid_type()` keeps working after disconnect.

This matches the smart transport behavior.
2026-04-23 23:17:57 -04:00
Weihang Lo
6753d535c8 test(transport): get oid_type on local transport
Exercise git_remote_oid_type on a SHA256 local transport.

The after-disconnect assertion is commented out because
local_oid_type dereferences `t->repo`, which local_close
has already freed (SIGSEGV).

I ran these commands to test btw:

```
cmake .. -DGIT_EXPERIMENTAL_SHA256=ON -DBUILD_TESTS=ON
cmake --build .
./libgit2_tests -snetwork::remote::local::sha256_oid_type
```
2026-04-23 23:14:01 -04:00
Weihang Lo
d375ab70c1 fix(remote): apply insteadOf from global config for detached remotes
Detached remotes already read global/system config for http proxy
settings, but did not apply url.*.insteadOf or url.*.pushInsteadOf
rules. This inconsistency meant that `git_remote_create_detached`
behaved differently from git's `ls-remote`, which was the primary
use case for detached remotes.

This fixes it by loading the default config when no repository is
provided and apply insteadOf rules consistently.

While this is a behavior change, it still respects
`GIT_REMOTE_CREATE_SKIP_INSTEADOF`, meaning that user can restore
the previous behavior with minimal effort

Fixes https://github.com/libgit2/libgit2/issues/5469
2026-04-23 18:32:11 -04:00
Weihang Lo
aa5d9886d1 test(remote): show buggy detached remote insteadOf behavior
`git_remote_create_detached` does not apply
`url.*.insteadOf` or url.*.pushInsteadOf from global config.

These tests currently pass, asserting the buggy behavior
and serving as a minimal reproduction.

The assertions will be updated when the fix is applied.

See <https://github.com/libgit2/libgit2/issues/5469>
2026-04-23 18:32:11 -04:00
Edward Thomson
d35f378794 Merge pull request #7226 from weihanglo/local-object-format
fix(clone): propagate object format in local clone
2026-04-23 22:11:06 +01:00
Edward Thomson
87c03c1aaa Apply suggestions from code review
Co-authored-by: Edward Thomson <ethomson@edwardthomson.com>
2026-04-23 21:30:21 +01:00
Weihang Lo
735bb2e2f5 fix(refs): attach refdb owner to loose pseudorefs
Pseudoref lookup now reads `FETCH_HEAD` directly as a loose ref,
but callers still expect looked-up references to know their owning
repository.

Attach the repo's refdb after the loose pseudoref is read so
owner-dependent ops such as peeling can safely resolve objects.
2026-04-22 17:50:23 -04:00
Weihang Lo
c0a5341635 test(refs): cover pseudoref owner regression from b17ecb23e
b17ecb23e changed pseudoref lookup to read loose refs directly,
bypassing refdb lookup.

This documents the resulting buggy behavior:
a looked-up `FETCH_HEAD` pseudoref has no owning refdb attached.
2026-04-22 17:50:14 -04:00
Weihang Lo
47fdc9c3f0 fix(clone): propagate object format in local clone
`clone_local_into()` copies objects from the source repository
but does not set the destination's object format.
This cause SHA256 repositories to be unreadable after a local clone
because the destination defaults to SHA1.

The remote clone path already handles this correctly
so local clone path follows suite.

See: <https://github.com/libgit2/libgit2/blob/1f34e2a57/src/libgit2/clone.c#L448-L450>
2026-04-19 11:34:50 -04:00
Weihang Lo
9fa192de95 test(clone): document SHA256 local clone failure
Local clone, both hardlink and copy paths, does not propagate
the source repository's object format to the destination.

A SHA256 repository cloned locally is initialized as SHA1
and caused object lookup failures.

These tests are added as reproducible examples,
and will be fixed in the next commit

* `sha256_via_no_local`
  * `file://` URL + `GIT_CLONE_NO_LOCAL` -> remote code path
* `sha256_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL` -> local code path with hardlinks
* `sha256_no_links_object_format_is_propagated`
  * `file://` URL + `GIT_CLONE_LOCAL_NO_LINKS` -> local code path with copy
2026-04-19 11:34:44 -04:00
Patrick Steinhardt
5c6cba5142 tests: wire up reftable tests
Wire up reftable tests so that they can be executed by setting the
`CLAR_REF_FORMAT` environment variable. This only catches tests that use
`cl_git_sandbox_init()`, but that should cover most of our tests. So
this infrastructure isn't perfect, but for now it's good enough. We may
want to iterate on it in the future.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
415f3fbdb0 tests: generate test resources for reftables
Generate test resources for reftables. These resources are basically the
Git repositories we already have, but converted to use the "reftable"
format. For most of the part, this conversion is done by executing `git
refs migrate`.

A couple notes:

  - This require a recent Git upstream version with not-yet-upstreamed
    patches due to a bug in `git refs migrate` with reflogs.

  - The migration command does not yet support repositories with
    worktrees. Those were converted by first removing the worktrees,
    migrating the refs and then recreating them.

  - The HEAD_TRACKER reference in testrepo.git is not recognized as a
    root ref and is thus not automatically migrated.

  - testrepo.git has an empty reflog for refs/heads/with-empty-log that
    does not get migrated.
2026-04-16 14:56:46 +02:00
Patrick Steinhardt
1888a166e4 tests/libgit2: conditional checks for the "files"-backend
We have a bunch of checks for properties of the "files" reference
backend:

  - Whether a specific reference has been packed or whether it still
    exists as a loose reference.

  - Whether empty ref directories get pruned.

  - Whether we properly fsync data to disk.

These checks continue to be sensible for that backend, but for any other
backend they plain don't work. Adapt the tests so that we only run them
in case the repository uses the "files" backend.
2026-03-30 07:54:12 +02:00
Patrick Steinhardt
1030b68f3d tests/libgit2: don't overwrite config when testing conditionals
When testing conditional includes we overwrite the repository's config
file with the relevant conditions. This causes us to fully overwrite all
repository configuration, including the repository format version and
any extensions. While the test repository used in this test does not
have any extensions, we will add a reftable-enabled repository that does
rely on the "refStorage" extension eventually.

Fix this by only modifying the relevant config keys.
2026-03-30 07:54:12 +02:00
Patrick Steinhardt
5c5db73e3e tests/libgit2: don't access refs via filesystem
There are a bunch of tests where we read or write references via the
filesystem directly. This only works with the "files" backend, but
naturally breaks if we supported any other reference format.

Refactor these tests to instead use the refdb to access those.
2026-03-30 07:54:09 +02:00
Edward Thomson
079379ee96 Merge pull request #7111 from pks-gitlab/pks-refdb-pseudorefs
Fix handling of pseudorefs with different refdb backends
2026-03-29 14:00:44 +01:00
Kovacsics Robert
828f60337c revparse: Allow HEAD abbreviation @
The `@` alone (without predeeding refname in `<refname>@`) is an
alias for HEAD, and can then be used with other modifiers for example
`HEAD^{/...}`
2026-03-01 21:03:26 +00:00
Edward Thomson
928a81e872 microbenchmarks: benchmark the oid code
At present, the library's oid manipulation functions are slower when
built in SHA256 mode than when not. Add some microbenchmarks around the
oid compare and copy functions to understand this better.
2026-01-26 21:43:06 +00:00
Edward Thomson
8fda867e46 benchmarks: move them to their own folder
Benchmarks aren't really tests, don't keep them in the `tests` folder.
2026-01-26 21:43:06 +00:00
Edward Thomson
1424585fb6 tests: move clar to deps
Clean up the `tests` folder to only contain _actual tests_. Since clar
is now a reasonably external project, move it to `deps`.
2026-01-26 21:43:06 +00:00
Edward Thomson
6720d66b2f hashmap: tests initialize to NULL to avoid warnings 2026-01-25 16:53:58 +00:00
Edward Thomson
ea87da84a8 config: tests set entry to NULL to avoid warnings 2026-01-25 16:53:58 +00:00