Commit Graph

2095 Commits

Author SHA1 Message Date
Edward Thomson
dd0aa811dd Merge branch 'pr/4228' 2017-06-04 22:46:07 +01:00
Edward Thomson
82e929a88b Merge pull request #4239 from roblg/toplevel-dir-ignore-fix
Fix issue with directory glob ignore in subdirectories
2017-06-04 19:35:39 +02:00
Edward Thomson
04de614b1f Merge pull request #4243 from pks-t/pks/submodule-workdir
Submodule working directory
2017-06-04 19:03:07 +02:00
Carlos Martín Nieto
a1023a4302 Merge pull request #4179 from libgit2/ethomson/expand_tilde
Introduce home directory expansion function for config files, attribute files
2017-05-20 17:18:07 +02:00
Carlos Martín Nieto
e694e4e954 Merge pull request #4174 from libgit2/ethomson/set_head_to_tag
git_repository_set_head: use tag name in reflog
2017-05-20 14:17:36 +02:00
Carlos Martín Nieto
119bdd8658 Merge pull request #4231 from wabain/open-revrange
revparse: support open-ended ranges
2017-05-20 14:13:27 +02:00
Patrick Steinhardt
2696c5c3ec repository: make check if repo is a worktree more strict
To determine if a repository is a worktree or not, we currently check
for the existence of a "gitdir" file inside of the repository's gitdir.
While this is sufficient for non-broken repositories, we have at least
one case of a subtly broken repository where there exists a gitdir file
inside of a gitmodule. This will cause us to misidentify the submodule
as a worktree.

While this is not really a fault of ours, we can do better here by
observing that a repository can only ever be a worktree iff its common
directory and dotgit directory are different. This allows us to make our
check whether a repo is a worktree or not more strict by doing a simple
string comparison of these two directories. This will also allow us to
do the right thing in the above case of a broken repository, as for
submodules these directories will be the same. At the same time, this
allows us to skip the `stat` check for the "gitdir" file for most
repositories.
2017-05-19 09:44:44 +02:00
Robert Gay
c3b8e8b358 Fix issue with directory glob ignore in subdirectories 2017-05-17 08:24:11 -07:00
Patrick Steinhardt
e526fbc703 tests: add test suite for opening submodules 2017-05-17 09:41:48 +02:00
Patrick Steinhardt
98a5f081c5 tests: threads::basic: remove unused function exit_abruptly 2017-05-15 07:34:04 +02:00
Patrick Steinhardt
7d7f6d332c tests: clone::local: compile UNC functions for Windows only 2017-05-15 07:34:04 +02:00
William Bain
8b107dc5e1 revparse: support open-ended ranges
Support '..' and '...' ranges where one side is not specified.
The unspecified side defaults to HEAD.

Closes #4223
2017-05-05 09:46:56 -06:00
Patrick Steinhardt
883eeb5f90 worktree: switch over worktree pruning to an opts structure
The current signature of `git_worktree_prune` accepts a flags field to
alter its behavior. This is not as flexible as we'd like it to be when
we want to enable passing additional options in the future. As the
function has not been part of any release yet, we are still free to
alter its current signature. This commit does so by using our usual
pattern of an options structure, which is easily extendable without
breaking the API.
2017-05-05 15:39:25 +02:00
Patrick Steinhardt
8264a30f4f worktree: support creating locked worktrees
When creating a new worktree, we do have a potential race with us
creating the worktree and another process trying to delete the same
worktree as it is being created. As such, the upstream git project has
introduced a flag `git worktree add --locked`, which will cause the
newly created worktree to be locked immediately after its creation. This
mitigates the race condition.

We want to be able to mirror the same behavior. As such, a new flag
`locked` is added to the options structure of `git_worktree_add` which
allows the user to enable this behavior.
2017-05-05 15:39:25 +02:00
Patrick Steinhardt
ffd264d9eb tests: repo: fix repo discovery tests on overlayfs
Debian and Ubuntu often use schroot to build their DEB packages in a
controlled environment. Depending on how schroot is configured, our
tests regarding repository discovery break due to not being able to find
the repositories anymore. It turns out that these errors occur when the
schroot is configured to use an overlayfs on the directory structures.

The reason for this failure is that we usually refrain from discovering
repositories across devices. But unfortunately, overlayfs does not have
consistent device identifiers for all its files but will instead use the
device number of the filesystem the file stems from. So whenever we
cross boundaries between the upper and lower layer of the overlay, we
will fail to properly detect the repository and bail out.

This commit fixes the issue by enabling cross-device discovery in our
tests. While it would be preferable to have this turned off, it probably
won't do much harm anyway as we set up our tests in a temporary location
outside of the parent repository.
2017-05-03 15:04:46 +02:00
Patrick Steinhardt
a7aa73a535 worktree: introduce git_worktree_add options
The `git_worktree_add` function currently accepts only a path and name
for the new work tree. As we may want to expand these parameters in
future versions without adding additional parameters to the function for
every option, this commit introduces our typical pattern of an options
struct. Right now, this structure is still empty, which will change with
the next commit.
2017-05-02 12:39:29 +02:00
Edward Thomson
1dc89aab24 object validation: free some memleaks 2017-05-01 22:55:12 +01:00
Edward Thomson
13c1bf0718 Merge pull request #4197 from pks-t/pks/verify-object-hashes
Verify object hashes
2017-05-01 16:17:48 +01:00
Edward Thomson
5700ee9c23 Merge pull request #4216 from pks-t/pks/debian-test-failures
Debian HTTPS feature test failure
2017-05-01 16:10:50 +01:00
Patrick Steinhardt
35079f507b odb: add option to turn off hash verification
Verifying hashsums of objects we are reading from the ODB may be costly
as we have to perform an additional hashsum calculation on the object.
Especially when reading large objects, the penalty can be as high as
35%, as can be seen when executing the equivalent of `git cat-file` with
and without verification enabled. To mitigate for this, we add a global
option for libgit2 which enables the developer to turn off the
verification, e.g. when he can be reasonably sure that the objects on
disk won't be corrupted.
2017-04-28 14:05:45 +02: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
Patrick Steinhardt
d59dabe5cb tests: object: test looking up corrupted objects
We currently have no tests which check whether we fail reading corrupted
objects. Add one which modifies contents of an object stored on disk and
then tries to read the object.
2017-04-28 14:05:45 +02:00
Patrick Steinhardt
86c035526d tests: object: create sandbox
The object::lookup tests do use the "testrepo.git" repository in a
read-only way, so we do not set up the repository as a sandbox but
simply open it. But in a future commit, we will want to test looking up
objects which are corrupted in some way, which requires us to modify the
on-disk data. Doing this in a repository without creating the sandbox
will modify contents of our libgit2 repository, though.

Create the repository in a sandbox to avoid this.
2017-04-28 14:05:44 +02:00
Patrick Steinhardt
e29e802966 tests: odb: make hash of fake backend configurable
In the odb::backend::nonrefreshing test suite, we set up a fake backend
so that we are able to determine if backend functions are called
correctly. During the setup, we also parse an OID which is later on used
to read out the pseudo-object. While this procedure works right now, it
will create problems later when we implement hash verification for
looked up objects. The current OID ("deadbeef") will not match the hash
of contents we give back to the ODB layer and thus cannot be verified.

Make the hash configurable so that we can simply switch the returned for
single tests.
2017-04-28 14:05:44 +02:00
Edward Thomson
7df580fae6 Merge pull request #4191 from pks-t/pks/wt-ref-renames
Branch renames with worktrees
2017-04-28 11:58:49 +01:00
Patrick Steinhardt
2a7086fa89 tests: config: verify functionality with read-only backends 2017-04-26 09:35:11 +02:00
Patrick Steinhardt
417319cc86 tests: core::features: only check for HTTPS if it is supported 2017-04-25 10:15:59 +02:00
Patrick Steinhardt
a4de1ae389 cmake: define GIT_HTTPS when HTTPS is supported 2017-04-25 10:15:59 +02:00
Patrick Steinhardt
13c275aba5 tests: threads::diff: fix warning for unused variable
The threads::diff test suite has a static variable `_retries`, which is
used on Windows platforms only. As it is unused on other systems, the
compiler throws a warning there. Fix the warning by wrapping the
declaration in an ifdef.
2017-04-21 07:49:08 +00:00
Carlos Martín Nieto
8d89e40961 Merge pull request #4192 from libgit2/ethomson/win32_posix
Refactor some of the win32 POSIX emulation
2017-04-17 17:19:03 +02:00
Patrick Steinhardt
cf07db2f1b filter: only close filter if it's been initialized correctly
In the function `git_filter_list_stream_data`, we initialize, write and
subesquently close the stream which should receive content processed by
the filter. While we skip writing to the stream if its initialization
failed, we still try to close it unconditionally -- even if the
initialization failed, where the stream might not be set at all, leading
us to segfault.

Semantics in this code is not really clear. The function handling the
same logic for files instead of data seems to do the right thing here in
only closing the stream when initialization succeeded. When stepping
back a bit, this is only reasonable: if a stream cannot be initialized,
the caller would not expect it to be closed again. So actually, both
callers of `stream_list_init` fail to do so. The data streaming function
will always close the stream and the file streaming function will not
close the stream if writing to it has failed.

The fix is thus two-fold:

- callers of `stream_list_init` now close the stream iff it has been
  initialized
- `stream_list_init` now closes the lastly initialized stream if
  the current stream in the chain failed to initialize

Add a test which segfaulted previous to these changes.
2017-04-07 16:34:47 +02:00
Patrick Steinhardt
2a485dabc0 refs: update worktree HEADs when renaming branches
Whenever we rename a branch, we update the repository's symbolic HEAD
reference if it currently points to the branch that is to be renamed.
But with the introduction of worktrees, we also have to iterate over all
HEADs of linked worktrees to adjust them. Do so.
2017-04-05 13:50:38 +02:00
Patrick Steinhardt
602972560a tests: worktree::refs: convert spaces to tabs 2017-04-05 13:44:52 +02:00
Edward Thomson
48f09c6c47 win32: only set git_win32__retries where it exists 2017-04-05 11:59:03 +01:00
Edward Thomson
89d403cce2 win32: enable p_utimes for readonly files
Instead of failing to set the timestamp of a read-only file (like any
object file), set it writable temporarily to update the timestamp.
2017-04-05 11:04:29 +01:00
Edward Thomson
7ece906598 win32: make posix emulation retries configurable
POSIX emulation retries should be configurable so that tests can disable
them.  In particular, maniacally threading tests may end up trying to
open locked files and need retries, which will slow continuous
integration tests significantly.
2017-04-03 23:14:24 +01:00
Edward Thomson
e86d02f92d git_repository_set_head: use remote name in reflog
When `git_repository_set_head` is provided a remote reference, update
the reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout remote`.
2017-04-03 00:10:47 +01:00
Edward Thomson
ed812ee725 config::include: sanitize homedir
Sanitize the home directory to ensure that we do not accidentally locate
a file called `~/.nonexistentfile`.
2017-03-23 12:12:39 +00:00
Sim Domingo
047fe29c4f add failing test to include a missing config file relative to home dir 2017-03-23 12:12:38 +00:00
Edward Thomson
6ad091dceb Merge pull request #4176 from libgit2/ethomson/3872
inet_pton: don't assume addr families don't exist
2017-03-23 09:33:09 +00:00
Edward Thomson
f623cf894a Merge pull request #4163 from pks-t/pks/submodules-with-worktrees
Worktree fixes
2017-03-22 20:32:55 +00:00
Edward Thomson
6fd6c67824 Merge pull request #4030 from libgit2/ethomson/fsync
fsync all the things
2017-03-22 20:29:22 +00:00
Edward Thomson
983979fa0d inet_pton: don't assume addr families don't exist
Address family 5 might exist on some crazy system like Haiku.
Use `INT_MAX-1` as an unsupported address family.
2017-03-22 19:52:38 +00:00
Edward Thomson
ea3bb5c0bb git_repository_set_head: use tag name in reflog
When `git_repository_set_head` is provided a tag reference, update the
reflog with the tag name, like we do with a branch.  This helps
consumers match the semantics of `git checkout tag`.
2017-03-21 18:12:02 +00:00
Patrick Steinhardt
31059923bd Merge pull request #4169 from csware/absolute-symlink 2017-03-20 12:16:18 +01:00
Patrick Steinhardt
c10ce7c21a tests: filebuf: test writing to symlink with absolute paths 2017-03-20 12:14:07 +01:00
Patrick Steinhardt
b0c9bc920f submodule: resolve URLs relative to main worktree
It is possible to specify submodule URLs relative to the repository
location. E.g. having a submodule with URL "../submodule" will look for
the submodule at "repo/../submodule".

With the introduction of worktrees, though, we cannot simply resolve the
URL relative to the repository location itself. If the repository for
which a URL is to be resolved is a working tree, we have to resolve the
URL relative to the parent's repository path. Otherwise, the URL would
change depending on where the working tree is located.

Fix this by special-casing when we have a working tree while getting the
URL base.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
097f0105b4 refdb: create references in commondir
References for a repository are usually created inside of its gitdir.
When using worktrees, though, these references are not to be created
inside the worktree gitdir, but instead inside the gitdir of its parent
repository, which is the commondir. Like this, branches will still be
available after the worktree itself has been deleted.

The filesystem refdb currently still creates new references inside of
the gitdir. Fix this and have it create references in commondir.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
8f154be3eb worktree: write resolved paths into link files
The three link files "worktree/.git", ".git/worktrees/<name>/commondir"
and ".git/worktrees/<name>/gitdir" should always contain absolute and
resolved paths. Adjust the logic creating new worktrees to first use
`git_path_prettify_dir` before writing out these files, so that paths
are resolved first.
2017-03-17 09:27:56 +01:00
Patrick Steinhardt
20a368e2d7 worktree: parent path should point to the working dir
The working tree's parent path should not point to the parent's gitdir,
but to the parent's working directory. Pointing to the gitdir would not
make any sense, as the parent's working directory is actually equal to
both repository's common directory.

Fix the issue.
2017-03-17 09:27:55 +01:00