3618 Commits

Author SHA1 Message Date
Edward Thomson
abedcfe71c tests: reset the allocator to the default
Instead of setting the allocator to stdalloc, just pass `NULL`, in case
we're running with the debug allocator.
2024-05-13 11:30:25 +01:00
Edward Thomson
cfd6e0148b tests: use git__ allocator functions consistently 2024-05-13 11:30:25 +01:00
Sven Strickroth
60f219e80b Revparse: Correctly accept ref with '@' at the end
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2024-05-08 17:36:18 +02:00
Edward Thomson
4839f4fbfc http: allow users more control over user-agent
Users can now override the "product" portion of the user-agent (via
GIT_OPT_SET_USER_AGENT_PRODUCT). This continues to default to "git/2.0",
but users may define their own string, or may opt out of sending a
user-agent entirely (by passing an empty string). Similarly, users may
now also opt-out of sending any additional "comment" information by
setting the GIT_OPT_SET_USER_AGENT value to an empty string.
2024-03-28 10:10:50 +00:00
Edward Thomson
4d19e8c9c5 settings: pull settings out into its own file 2024-03-28 10:10:46 +00:00
Edward Thomson
0f12a011ab Merge pull request #6770 from libgit2/ethomson/ctype
cast characters to unsigned when classifying characters
2024-03-18 11:31:39 +00:00
Edward Thomson
8e6beb3d16 ctype: switch to git__ ctype functions
Use the `git__` ctype functions (`git__isdigit` and friends) instead of
explicitly casting.
2024-03-18 11:07:47 +00:00
Edward Thomson
cc7764f6a6 config: correct fetching the HIGHEST_LEVEL config
Also, add a test for fetching the `GIT_CONFIG_HIGHEST_LEVEL`.
2024-03-17 14:11:40 +00:00
Edward Thomson
c2ed49c78e Merge pull request #6756 from libgit2/ethomson/worktree-config
Separate config reader and writer backend priorities (for worktree configs)
2024-03-16 16:36:22 +00:00
Edward Thomson
b70dd12706 packbuilder: adjust nondeterministic tests
The packbuilder tests should be deterministic. This comment suggests
that they are:

```
/*
 * By default, packfiles are created with only one thread.
 * Therefore we can predict the object ordering and make sure
 * we create exactly the same pack as git.git does when *not*
 * reusing existing deltas (as libgit2).
 *
 * $ cd tests/resources/testrepo.git
 * $ git rev-list --objects HEAD | \
 *  git pack-objects -q --no-reuse-delta --threads=1 pack
 * $ sha1sum pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack
 * 5d410bdf97cf896f9007681b92868471d636954b
 *
 */
```

but it is disappointingly incorrect. As is evidenced by the fact that --
at least on _my_ machine -- that command does not actually produce that
output any longer.

Variations in things like the which compression library is actually
used, and its defaults, mean that we cannot accurately predict or
enforce the bytes in the packfile from one system to another.

Adjust the tests so that they do not believe that they should enforce
the bytes in the packfile. This allows broader compatibility with
zlib-compatible compression libraries, or other compression levels.
2024-03-16 12:19:16 +00:00
Edward Thomson
e3d11454fe Merge pull request #6761 from libgit2/ethomson/message_trailer
Fix message trailer parsing
2024-03-16 11:23:33 +00:00
Edward Thomson
4c9353227b tests: don't free an unininitialized repo 2024-03-14 19:20:18 +00:00
Edward Thomson
d488817076 trailer: ensure we identify patch lines like git
Git looks explicitly for `---` followed by whitespace (`isspace()`) to
determine when a patch line begins in a commit message. Match that
behavior. This ensures that we don't treat (say) `----` as a patch line
incorrectly.
2024-03-14 11:28:20 +00:00
Edward Thomson
fdaf373c0e trailer: test actual array equivalence
We never test the lengths of the two arrays, so a short return from
`git_message_trailers` will match erroneously.
2024-03-14 11:27:36 +00:00
Edward Thomson
cb4b61770f Merge branch 'main' into ethomson/worktree-config 2024-03-11 22:41:25 +00:00
Edward Thomson
b8f3dae325 fetch: fail on depth for local transport
We don't support shallow clones for the local transport, currently.
Fail, instead of silently ignoring the depth option.
2024-03-11 21:07:46 +00:00
Edward Thomson
3baa6372fd config: read the individual worktree config
Instead of reading the worktree configuration from the commondir, read
it from the gitdir. This ensures that each worktree gets its own
configuration.
2024-03-11 15:21:12 +00:00
Edward Thomson
e890ca35aa config: only read worktree config if extension is set
Only read the worktree configuration when `extensions.worktreeconfig` is
set to true.
2024-03-11 15:20:02 +00:00
Edward Thomson
5f85714e1f config: don't git_config_free an aborted transaction
When a configuration transaction is freed with `git_transaction_free` -
without first committing it - we should not `git_config_free`. We never
increased the refcount, so we certainly shouldn't decrease it.

Also, add a test around aborting a transaction without committing it.
2024-03-10 21:35:25 +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
9baf618ced Merge remote-tracking branch 'origin/main' into worktree_refs 2024-03-08 22:02:56 +00:00
Edward Thomson
85f5aec13e Merge remote-tracking branch 'origin/main' into worktree 2024-03-05 09:44:16 +00:00
Laurence McGlashan
88b516713d trace: Re-enable tests as tracing is now enabled by default 2024-03-04 10:46:45 +00:00
Edward Thomson
78f145366e config: update tests to use fail_with
`cl_git_fail_with` is preferred over asserting a return value; the
former gives more detailed information about the mismatch.
2024-03-02 09:07:12 +00:00
Sven Strickroth
2f6c4f75e3 Fix broken regexp that matches submodule names containing ".path"
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2024-02-24 15:25:00 +01:00
Edward Thomson
88608a5e9e worktree: update worktree refs test
Ensure that we test for the expected error code (GIT_ENOTFOUND) on not
found refs. In addition, we don't need to handle the error case with an
explicit free; it's okay to leak memory on test failures.
2024-02-22 14:08:00 +00:00
Edward Thomson
8fd4f83e8a Merge pull request #5893 from libgit2/ethomson/diff_fail
Ensure that completely ignored diff is empty
2024-02-22 13:39:19 +00:00
Sean Allred
ea66ab0773 config: skip worktree config in get_backend_for_use
It would seem that `get_backend_for_use` is primarily used when
writing config data -- either to set keys or delete them (based on the
possible values of `backend_use`). When git-config(1) is used for
side-effects, it will modify only the local (repository-level)
configuration unless explicitly overridden.

From git-config(1):

    --local
        For writing options: write to the repository .git/config file.
	This is the default behavior.

`get_backend_for_use` does not have the ability to specify a config
level and typically is expected (it seems) to 'do the right thing'.
Taking its cue from git-config(1), don't update worktree-specific
config unless it's the only option.

If that functionality is needed by consumers, I assume they would find
the appropriate backend with `git_config_open_level` and feed that
`git_config` object through to the `git_config_set_*` functions (as
demonstrated in the provided test).
2024-02-21 15:54:00 -06:00
Sean Allred
5a86dfc172 repository: support the 'worktreeConfig' extension
Now that worktree-level configuration can be read from disk and
manipulated in memory, we should be able to say we support
'extensions.worktreeConfig'.
2024-02-20 21:29:51 -06:00
Sean Allred
aa31120f7c config: introduce GIT_CONFIG_LEVEL_WORKTREE
Introduce the logical concept of a worktree-level config.  The new
value sits between _LOCAL and _APP to allow `git_config_get_*` to
'just work'.

The assumption of how `git_config_get_*` works was tested
experimentally by setting _WORKTREE to some nonsense value (like -3)
and watching the new test fail.
2024-02-20 11:30:34 -06:00
Edward Thomson
e62cdc9bcb Merge pull request #6717 from herrerog/fix-rename-detection
merge: fix incorrect rename detection for empty files.
2024-02-20 16:41:40 +00:00
Edward Thomson
caf1747ed4 Merge pull request #6739 from libgit2/ethomson/safedirectory
More `safe.directory` improvements
2024-02-20 16:34:17 +00:00
Edward Thomson
a204533ded test: completely ignored diff is empty 2024-02-20 14:30:17 +00:00
Edward Thomson
6b54210595 merge: refactor merge tests for empty files treated as renames
Don't munge the "trivial" tests, those are specifically about the
"trivial" resolutions for git's tree merge. (For example, adding a file
in a new branch and making no changes in the HEAD branch is something
that can be handled _trivially_.)

For tests of rename functionality, put them in the trees::rename tests.
2024-02-20 13:47:31 +00:00
Edward Thomson
d30692d3b3 Merge pull request #6744 from libgit2/ethomson/http_proxy
http: support empty http.proxy config setting
2024-02-20 13:04:12 +00:00
Edward Thomson
4a1c2bd8ce diff: fix test for SHA256 support in diff_from_buffer 2024-02-20 12:37:58 +00:00
Edward Thomson
267479dad5 http: support empty http.proxy config setting
An empty `http.proxy` config setting should be treated like a missing
`http.proxy` config setting.
2024-02-20 04:23:38 -08:00
Edward Thomson
2b1d8924e0 Merge pull request #6240 from xphoniex/xphoniex/swap-add-del-eof-nl
Swap `GIT_DIFF_LINE_(ADD|DEL)_EOFNL` to match other Diffs
2024-02-20 12:21:45 +00:00
Edward Thomson
8c9ebf4d12 Merge pull request #6743 from libgit2/ethomson/repo_init_win32
repo: ensure we can initialize win32 paths
2024-02-20 12:05:40 +00:00
Edward Thomson
6e8c09a46f repo: ensure we can initialize win32 paths
Given a win32 path, ensure that we can initialize it. This involves a
posix-style path conversion at the beginning of our initialization.
2024-02-20 11:37:35 +00:00
Edward Thomson
c63eccc3e5 revparse: ensure bare '@' is truly bare
Support a revspec of '@' to mean 'HEAD', but ensure that it's at the
start of the revspec. Previously we were erroneously allowing 'foo@' to
mean 'HEAD' as well. Instead, 'foo@' should be rejected.
2024-02-20 11:35:24 +00:00
Edward Thomson
9c31bd0358 repo: allow safe.directory to be a UNC path
Recent versions of Git for Windows allow a sane UNC style path to be
used directly in `safe.directory` (without needing the `%(prefix)`
silliness). Match that behavior.
2024-02-19 09:06:57 -08:00
Edward Thomson
c1734b5ae4 repo: test for safe.directory with unc paths
On Windows, you may open a repo with UNC path format -- for example
\\share\foo\bar, or as a git-style path, //share/foo/bar. In this world,
Git for Windows expects you to translate this to
$(prefix)//share/foo/bar.

We can test for that by using the fact that local drives are exposed as
hidden shares. For example, C:\Foo is //localhost/C$/Foo/.
2024-02-19 09:06:57 -08:00
Edward Thomson
b19a6a1582 repo: refactor safe directory tests
Provide a helper method in the tests to set up the safe.directory
configuration for a normal and bare repository to avoid some copy/pasta.

(Some copypasta will remain, since there's customizations to the file
that are not trivially abstractable.)
2024-02-19 09:06:57 -08:00
Edward Thomson
d970934b29 repo: test that '%(prefix)/' safe.directory succeeds
Ensure that we can support safe.directory entries that are prefixed with
'%(prefix)/'.
2024-02-19 09:06:57 -08:00
Edward Thomson
57870e9f4d util: clean up test resources in the sandbox
Ensure that we clean up cruft that we create for testing, so that future
tests don't have troubles.
2024-02-19 09:06:57 -08:00
Edward Thomson
bdf4d70a13 util: update win32 p_realpath to canonicalize case
The POSIX `realpath` function canonicalizes relative paths, symbolic links,
and case (on case-insensitive filesystems). For example, on macOS, if you
create some file `/private/tmp/FOO`, and you call `realpath("/tmp/foo")`,
you get _the real path_ returned of `/private/tmp/FOO`.

To emulate this behavior on win32, we call `GetFullPathName` to handle the
relative to absolute path conversion, then call `GetLongPathName` to handle
the case canonicalization.
2024-02-19 09:06:57 -08:00
Edward Thomson
f43aa1adb5 util: move path tests to path::core
Clar handles multiple levels of hierarchy in a test name _but_ it does so
assuming that there are not tests at a parent folder level. In other words,
if you have some tests at path/core.c and path/win32.c, then you cannot have
tests in path.c. If you have tests in path.c, then the things in path/*.c
will be ignored.

Move the tests in path.c into path/core.c.
2024-02-19 16:41:31 +00:00
Edward Thomson
beea99b082 path: provide an is_root helper method
We may quickly want to determine if the given path is the root path
('/') on POSIX, or the root of a drive letter (eg, 'A:/', 'C:\') on
Windows.
2024-02-19 16:41:31 +00:00
Edward Thomson
bec1d7b7b0 path: provide a helper to compute len with trailing slashes
We may need to strip multiple slashes at the end of a path; provide a
method to do so.
2024-02-19 16:41:31 +00:00