Commit Graph

3794 Commits

Author SHA1 Message Date
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
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
Edward Thomson
219730325e clar: update to latest 2026-01-10 20:17:08 +00:00
Edward Thomson
a09440a4f5 index: support USE_NSEC=OFF
Ideally, nobody should be building without nanosecond precision. But
support them if they do.
2026-01-08 22:39:56 +00:00
Edward Thomson
c5105a07dd Merge pull request #7172 from Oblivionsage/main
delta: fix undefined behavior in hdr_sz varint parsing
2026-01-08 21:25:44 +00:00
Edward Thomson
6a41fb7870 tests: update to latest clar 2026-01-08 01:03:42 +00:00
Oblivionsage
4e6b493787 delta: fix undefined behavior in hdr_sz varint parsing
The expression (c & 0x7f) << shift in hdr_sz() causes undefined
behavior when shift >= 32, because (c & 0x7f) is an unsigned int
(32-bit type). A malicious delta with a long varint can trigger this.

Fix by:
1. Casting to size_t before shifting to support 64-bit shifts
2. Adding a shift limit check to reject overlong varints
2025-12-24 16:46:30 +01:00
Łukasz Langa
0abde52675 fix: prevent SSH timeout infinite loop and enable TCP keepalive
This patch makes two improvements:
1. In case of LIBSSH2_ERROR_TIMEOUT, don't loop forever
2. Enable TCP keepalive on all sockets to detect dead connections

The added test demonstrates the hang without the patch.
2025-12-23 16:44:23 +01:00
Edward Thomson
3ac4c0adb1 Merge pull request #7148 from roberth/refs-shorthand-multi-segment
refs: honor REFSPEC_SHORTHAND for multi-segment refs
2025-12-20 13:08:02 +00:00
Patrick Steinhardt
4686f10ecb refs: introduce GIT_HEAD_REF define
Introduce the GIT_HEAD_REF define so that we can clearly indicate that
we're talking about the "HEAD" reference and not necessarily a file.
Note that there still are a couple of places where GIT_HEAD_FILE is
being used:

  - `git_repository_create_head()`: This function is used to create HEAD
    when initializing a new repository. This should get fixed eventually
    so that we create HEAD via the refdb, but this is a more involved
    refactoring that will be handled in a separate patch series.

  - `repo_init_head()`: Likewise.

  - `conditional_match_onbranch()`: This function is used to decide
    whether or not an `includeIf.onbranch` condition matches. This will
    be fixed in subsequent commits.

Other than that there shouldn't be any more references to GIT_HEAD_FILE.
2025-12-08 07:27:24 +01:00
Patrick Steinhardt
cd45e55246 refs: rename GIT_STASH_FILE to indicate this is a ref
The GIT_STASH_FILE define contains the path to the stash reference.
While we know that this used to be a file with the "files" backend, it's
not a standalone file with the "reftable" backend anymore.

Rename the macro to GIT_STASH_REF to indicate that this is a proper ref.
2025-12-08 07:27:24 +01:00
Patrick Steinhardt
88229c53be refs: handle CHERRY_PICK_HEAD via the refdb
Fix handling of "CHERRY_PICK_HEAD" by exclusively reading and writing it
via the reference database.
2025-12-08 07:27:24 +01:00
Patrick Steinhardt
71bddb1744 refs: handle REVERT_HEAD via the refdb
Fix handling of "REVERT_HEAD" by exclusively reading and writing it via
the reference database.
2025-12-08 07:27:24 +01:00
Patrick Steinhardt
9554d2e3d3 refs: handle ORIG_HEAD via the refdb
We have a bunch of references that we treat like pseudo-refs. Those
references are (sometimes) read and written by going to the filesystem
directly, at other times they are read and written via the refdb. This
works alright with the "files" ref storage format given that any root
reference never gets packed into the "packed-refs" file, and thus they
would always be accessible a loose ref if present.

The behaviour is wrong though when considering alternate backends like
the "reftable" backend. All references except for pseudo-refs must be
read via the backend, and that includes root refs.

Historically this part of Git has been ill-defined, and it wasn't quite
clear which refs are considered pseudo-refs in the first place. This was
clarified in 6fd80375640 (Documentation/glossary: redefine pseudorefs as
special refs, 2024-05-15): there only are two pseudorefs, "FETCH_HEAD"
and "MERGE_HEAD". The reason why those two references are considered
special is that they may contain additional data that doesn't fit into
the normal reference format.

In any case, our current handling of a couple of root references is
broken in this new world.

Fix this for "ORIG_HEAD" by exclusively going through the refdb to read
and write that reference. Rename the define accordingly to clarify that
it is a reference and not a file.
2025-12-08 07:27:24 +01:00
Łukasz Langa
fadbef196e ci: Fix cases of -Werror=discarded-qualifiers raised by gcc 15.2 2025-12-06 23:02:39 +01:00
Edward Thomson
610dcaac06 Merge pull request #7153 from ambv/fix-iterator-index-case-folding-test-docker 2025-12-06 21:54:41 +00:00
Edward Thomson
ce0524670c Merge pull request #7120 from xokdvium/refspec-del
refspec: Detect DEL character in is_valid_name
2025-12-06 17:54:52 +00:00
Edward Thomson
cfed471032 Merge pull request #7102 from pks-gitlab/pks-refformat-extension
Introduction of the "refFormat" extension
2025-12-06 16:58:16 +00:00
Edward Thomson
7ed8f12087 ssh_exec: use GIT_SSH_COMMAND in tests
We specify additional arguments to the ssh executable; as a result, we
specify arguments with `GIT_SSH_COMMAND`.
2025-12-01 21:44:36 +00:00
Edward Thomson
4c9134e501 str: allow escaping with prefix and suffix
Allow `git_str_puts_escaped` to take an escaping prefix and an escaping
suffix; this allows for more options, including the ability to better
support escaping executed paths.
2025-12-01 21:44:36 +00:00
Edward Thomson
2ad709e77c process: resolve paths for win32
When using `git_process_new` on win32, resolve the path to the
application in the same way that we do on POSIX.

Search `PATH` for command to execute (unless the given executable is
fully qualified). In addition, better match Windows executable lookup
behavior itself (allowing the command to be `foo`, and looking for a
matching `foo.exe` or `foo.cmd`.)
2025-12-01 21:44:36 +00:00
Edward Thomson
ed39bcee40 fs: improved executable-in-path location tests
Ensure that our `find_executable` behaves as expected:

* When the executable contains a fully- or partially-qualified filename
  component (eg, `foo/bar`) that `PATH` is not searched; these paths are
  relative to the current working directory.
* An empty segment in `PATH` (on POSIX systems) is treated as the
  current directory; this is for compatibility with Bourne shells.
* When a file exists in `PATH`, it is actually executable (on POSIX)
2025-11-29 12:50:44 +00:00
Łukasz Langa
269427b2bb test: check the correct filesystem for case-sensitivity
It's certainly possible for the root filesystem to be case-sensitive
while /tmp is not, or vice versa. One example where this might happen
is when running Docker containers (like ci/docker/fedora) on macOS with
the repository checkout on AppleFS (not case sensitive) while the
container's /tmp is case sensitive.

This fix allows the test to pass under those circumstances as well.
2025-10-23 14:05:31 +02:00