Commit Graph

2095 Commits

Author SHA1 Message Date
Patrick Steinhardt
3017ba94a3 worktree: implement git_worktree_open_from_repository
While we already provide functionality to look up a worktree from a
repository, we cannot do so the other way round. That is given a
repository, we want to look up its worktree if it actually exists.
Getting the worktree of a repository is useful when we want to get
certain meta information like the parent's location, getting the locked
status, etc.
2017-03-17 09:26:13 +01:00
Patrick Steinhardt
f3c3068670 tests: worktree: use joinpath instead of printf to join paths 2017-03-15 17:16:47 +01:00
Patrick Steinhardt
fdb3e24ac4 tests: worktree: unify init/cleanup in open tests 2017-03-15 14:24:45 +01:00
Patrick Steinhardt
548e5bdf1e tests: worktree: unify init/cleanup in submodule tests 2017-03-15 12:28:05 +01:00
Patrick Steinhardt
aa593a65df tests: worktree: move submodule tests into own suite 2017-03-15 12:01:02 +01:00
Patrick Steinhardt
c0eba379d1 diff_parse: correctly set options for parsed diffs
The function `diff_parsed_alloc` allocates and initializes a
`git_diff_parsed` structure. This structure also contains diff options.
While we initialize its flags, we fail to do a real initialization of
its values. This bites us when we want to actually use the generated
diff as we do not se the option's version field, which is required to
operate correctly.

Fix the issue by executing `git_diff_init_options` on the embedded
struct.
2017-03-14 13:09:35 +01:00
Patrick Steinhardt
ad5a909cfb patch_parse: fix parsing minimal trailing diff line
In a diff, the shortest possible hunk with a modification (that is, no
deletion) results from a file with only one line with a single character
which is removed. Thus the following hunk

    @@ -1 +1 @@
    -a
    +

is the shortest valid hunk modifying a line. The function parsing the
hunk body though assumes that there must always be at least 4 bytes
present to make up a valid hunk, which is obviously wrong in this case.
The absolute minimum number of bytes required for a modification is
actually 2 bytes, that is the "+" and the following newline. Note: if
there is no trailing newline, the assumption will not be offended as the
diff will have a line "\ No trailing newline" at its end.

This patch fixes the issue by lowering the amount of bytes required.
2017-03-14 13:09:13 +01:00
Patrick Steinhardt
ace3508f4c patch_generate: fix git_diff_foreach only working with generated diffs
The current logic of `git_diff_foreach` makes the assumption that all
diffs passed in are actually derived from generated diffs. With these
assumptions we try to derive the actual diff by inspecting either the
working directory files or blobs of a repository. This obviously cannot
work for diffs parsed from a file, where we do not necessarily have a
repository at hand.

Since the introduced split of parsed and generated patches, there are
multiple functions which help us to handle patches generically, being
indifferent from where they stem from. Use these functions and remove
the old logic specific to generated patches. This allows re-using the
same code for invoking the callbacks on the deltas.
2017-03-14 13:08:28 +01:00
Carlos Martín Nieto
53454be87f Merge pull request #4157 from adamniedzielski/4099-git-sort-time-uninteresting
Skip uninteresting commits in revwalk timesort iterator
2017-03-11 19:52:05 +01:00
Edward Thomson
ffd4df6bf2 Merge pull request #4151 from novalis/dturner/rebase-submodule-untracked
rebase: ignore untracked files in submodules
2017-03-09 16:32:38 +00:00
Adam Niedzielski
c11c08a552 Skip uninteresting commits in revwalk timesort iterator
Fixes #4099
2017-03-09 14:01:10 +01:00
Edward Thomson
d24ae06d72 refs::namespace: add namespace tests
These simple tests only ensure that we enforce the existence of a
namespace; these mirror the rugged tests, they are not exhaustive.
2017-03-06 14:11:00 +00:00
David Turner
2270ca9f8f rebase: ignore untracked files in submodules
An untracked file in a submodule should not prevent a rebase from
starting.  Even if the submodule's SHA is changed, and that file would
conflict with a new tracked file, it's still OK to start the rebase
and discover the conflict later.

Signed-off-by: David Turner <dturner@twosigma.com>
2017-03-03 15:07:54 -05:00
Edward Thomson
52d03f37f7 git_commit_create: freshen tree objects in commit
Freshen the tree object that a commit points to during commit time.
2017-03-03 14:12:00 +00:00
Edward Thomson
d087c8f80e hash: test for sha1 collision attack detection 2017-03-03 10:50:28 +00:00
Edward Thomson
1c04a96b25 Honor core.fsyncObjectFiles 2017-03-02 09:11:33 +00:00
Patrick Steinhardt
5aa1f12a81 tests: refs::create: fix memory leak 2017-03-01 07:45:14 +01:00
Patrick Steinhardt
cf8e9a3ad5 Merge pull request #4143 from richardipsum/issue-4094
Fix: make reflog include "(merge)" for merge commits
2017-03-01 07:35:44 +01:00
Richard Ipsum
397cf1a1f5 Add test for inclusion of (merge) in reflog
This test ensures that the string '(merge)' is included in the reflog
when a merge commit is made.
2017-02-28 22:32:21 +00:00
Edward Thomson
3ac05d1149 win32: don't fsync parent directories on Windows
Windows doesn't support it.
2017-02-28 13:29:01 +00:00
Edward Thomson
2a5ad7d0f2 fsync: call it "synchronous" object writing
Rename `GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION` ->
`GIT_OPT_ENABLE_SYNCHRONOUS_OBJECT_CREATION`.
2017-02-28 13:29:01 +00:00
Edward Thomson
1229e1c4d7 fsync parent directories when fsyncing
When fsync'ing files, fsync the parent directory in the case where we
rename a file into place, or create a new file, to ensure that the
directory entry is flushed correctly.
2017-02-28 13:28:36 +00:00
Edward Thomson
eb56ed81af refdb_fs: optionally fsync packed refs 2017-02-28 13:28:36 +00:00
Edward Thomson
af3dcb0e50 refdb_fs: optionally fsync loose references 2017-02-28 13:28:36 +00:00
Edward Thomson
1c2c0ae2a4 packbuilder: honor git_object__synchronized_writing
Honor `git_object__synchronized_writing` when creating a packfile and
corresponding index.
2017-02-28 13:27:50 +00:00
Edward Thomson
e6ed0d2f03 odb_loose: fsync tests
Introduce a simple counter that `p_fsync` implements.  This is useful
for ensuring that `p_fsync` is called when we expect it to be, for
example when we have enabled an odb backend to perform `fsync`s when
writing objects.
2017-02-28 13:27:49 +00:00
Edward Thomson
a4b5ac643c Merge pull request #4138 from richardipsum/symbolic-create-arbitrary-tgt-test
tests: Add create__symbolic_with_arbitrary_content
2017-02-26 16:12:30 +00:00
Kevin Wojniak
4017017740 Fix inet_pton tests triggering an assert in Haiku
Haiku will assert in a nightly build if the "dst" input to inet_pton() is NULL.
2017-02-25 10:21:59 -08:00
Richard Ipsum
b84e58f45d Whitespace and style fixes
Use C style comments as per style guide,
and fix mismatching indentation.
2017-02-25 14:18:16 +00:00
Richard Ipsum
d2b3a21f2b tests: Add create__symbolic_with_arbitrary_content
This test ensures that it's possible to create a symbolic ref that
has arbitrary data as its target. It also ensures it's possible
to obtain the target of that symbolic reference from the git_reference
object.
2017-02-25 14:18:16 +00:00
Edward Thomson
b13f0da153 Merge pull request #4130 from libgit2/ethomson/clar_messages
Improve clar messages
2017-02-17 16:32:14 +00:00
Edward Thomson
c52480fde5 cl_git_exec -> cl_git_expect 2017-02-17 13:01:49 +00:00
Edward Thomson
a1dcc83030 tests: provide better pass/failure error messages
Provide more detailed messages when conditions pass or fail
unexpectedly.  In particular, this provides the error messages when a
test fails with a different error code than was expected.
2017-02-17 12:58:57 +00:00
Patrick Steinhardt
0d71690549 oidmap: remove GIT__USE_OIDMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
13c3bc9adf strmap: remove GIT__USE_STRMAP macro 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
73028af85c khash: avoid using macro magic to get return address 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
85d2748c6f khash: avoid using kh_key/kh_val as lvalue 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
f31cb45ad2 khash: avoid using kh_put directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
cb18386f72 khash: avoid using kh_val/kh_value directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
a853c52723 khash: avoid using kh_get directly 2017-02-17 11:41:06 +01:00
Patrick Steinhardt
64e46dc3b5 khash: avoid using kh_end directly 2017-02-17 11:41:06 +01:00
Edward Thomson
4f9f8e0dc9 Merge pull request #3436 from pks-t/libgit2-worktree
Worktree implementation
2017-02-13 11:10:49 +00:00
Patrick Steinhardt
3f3a4ce7bc worktree: test opening worktree via gitlink, gitdir and worktree 2017-02-13 11:12:01 +01:00
Patrick Steinhardt
6f6dd17cb2 worktree: test creating and opening submodule worktrees 2017-02-13 11:10:58 +01:00
Patrick Steinhardt
1fd6e035dd worktree: test opening discovered submodule worktrees 2017-02-13 11:09:57 +01:00
Patrick Steinhardt
39abd3adaa worktree: compute workdir for worktrees opened via their gitdir
When opening a worktree via the gitdir of its parent repository
we fail to correctly set up the worktree's working directory. The
problem here is two-fold: we first fail to see that the gitdir
actually is a gitdir of a working tree and then subsequently
fail to determine the working tree location from the gitdir.

The first problem of not noticing a gitdir belongs to a worktree
can be solved by checking for the existence of a `gitdir` file in
the gitdir. This file points back to the gitlink file located in
the working tree's working directory. As this file only exists
for worktrees, it should be sufficient indication of the gitdir
belonging to a worktree.

The second problem, that is determining the location of the
worktree's working directory, can then be solved by reading the
`gitdir` file in the working directory's gitdir. When we now
resolve relative paths and strip the final `.git` component, we
have the actual worktree's working directory location.
2017-02-13 11:08:57 +01:00
Patrick Steinhardt
84f56cb05a repository: rename path_repository and path_gitlink
The `path_repository` variable is actually confusing to think
about, as it is not always clear what the repository actually is.
It may either be the path to the folder containing worktree and
.git directory, the path to .git itself, a worktree or something
entirely different. Actually, the intent of the variable is to
hold the path to the gitdir, which is either the .git directory
or the bare repository.

Rename the variable to `gitdir` to avoid confusion. While at it,
also rename `path_gitlink` to `gitlink` to improve consistency.
2017-02-13 11:07:52 +01:00
Patrick Steinhardt
384518d09d repository: restrict checking out checked out branches
If a branch is already checked out in a working tree we are not
allowed to check out that branch in another repository. Introduce
this restriction when setting a repository's HEAD.
2017-02-13 11:06:52 +01:00
Patrick Steinhardt
143e539fd0 branch: restrict branch deletion for worktrees
Restrict the ability to delete branches that are checked out in
any linked repository.
2017-02-13 11:05:57 +01:00
Patrick Steinhardt
4321595dcb worktree: test basic merge functionality 2017-02-13 11:04:04 +01:00
Patrick Steinhardt
04fb12abb2 worktree: implement functions reading HEAD
Implement `git_repository_head_for_worktree` and
`git_repository_head_detached_for_worktree` for directly accessing a
worktree's HEAD without opening it as a `git_repository` first.
2017-02-13 11:03:01 +01:00
Patrick Steinhardt
f0cfc34105 worktree: implement git_worktree_prune
Implement the `git_worktree_prune` function. This function can be
used to delete working trees from a repository. According to the
flags passed to it, it can either delete the working tree's
gitdir only or both gitdir and the working directory.
2017-02-13 11:02:03 +01:00
Patrick Steinhardt
2a503485fa worktree: implement locking mechanisms
Working trees support locking by creating a file `locked` inside
the tree's gitdir with an optional reason inside. Support this
feature by adding functions to get and set the locking status.
2017-02-13 11:01:09 +01:00
Patrick Steinhardt
dea7488e93 worktree: implement git_worktree_add
Implement the `git_worktree_add` function which can be used to create
new working trees for a given repository.
2017-02-13 11:00:17 +01: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
Patrick Steinhardt
8c8d726ef7 worktree: implement git_repository_open_from_worktree
Add function `git_repository_open_from_worktree`, which allows to open a
`git_worktree` as repository.
2017-02-13 10:59:04 +01:00
Patrick Steinhardt
a6bddf605d tests: fix permissions on testrepo.git index file 2017-02-13 10:34:08 +01:00
Patrick Steinhardt
d3bc09e816 worktree: introduce struct git_worktree
Introduce a new `struct git_worktree`, which holds information
about a possible working tree connected to a repository.
Introduce functions to allow opening working trees for a
repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
45f2b7a43f worktree: implement git_worktree_list
Add new module for working trees with the `git_worktree_list`
function. The function lists names for all working trees of a
certain repository.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
4292837d50 config: open configuration in commondir
A repository's configuartion file can always be found in the
GIT_COMMON_DIR, which has been newly introduced. For normal
repositories this does change nothing, but for working trees this
change allows to access the shared configuration file.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e9403024fe refdb: look for reflog in commondir 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
e0a6c28eb3 refdb: introduce commondir awareness
The refdb_fs_backend is not aware of the git commondir, which
stores common objects like the o bject database and packed/loose
refereensces when worktrees are used.

Make refdb_fs_backend aware of the common directory by
introducing a new commonpath variable that points to the actual
common path of the database and using it instead of the gitdir
for the mentioned objects.
2017-02-13 10:28:15 +01:00
Patrick Steinhardt
79ab3ef69f repository: introduce is_worktree variable 2017-02-13 10:28:15 +01:00
Patrick Steinhardt
c09fd54e2e repository: introduce commondir variable
The commondir variable stores the path to the common directory.
The common directory is used to store objects and references
shared across multiple repositories. A current use case is the
newly introduced `git worktree` feature, which sets up a separate
working copy, where the backing git object store and references
are pointed to by the common directory.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
807d57e7df tests: implement worktree helpers 2017-02-13 10:13:02 +01:00
Patrick Steinhardt
8acc3b16ef tests: add merge-conflict branch for testrepo
Add a new branch that causes a merge conflict to `testrepo` so
that we are able to test merging in worktrees.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
e5a620de80 tests: add submodule worktree test data
Create worktrees for submodule repositories. The worktrees are
created for the parent repository (e.g. the one containing
submodules) and for the contained child repository.
2017-02-13 10:13:02 +01:00
Patrick Steinhardt
bd9f4fd24c tests: add worktree test data 2017-02-13 10:13:02 +01:00
Edward Thomson
683ff4f323 Merge pull request #4111 from pks-t/pks/dos-prefix
dirname with DOS prefixes
2017-02-10 11:01:23 +00:00
Edward Thomson
49806e9bc4 merge_trees: introduce test for submodule renames
Test that shows that submodules are incorrectly considered in renames,
and `git_merge_trees` will fail to lookup the submodule as a blob.
2017-02-09 18:13:06 +00:00
Patrick Steinhardt
3428a52359 tests: repo: assert discovery starting at Win32 roots finishes
As of recently, we failed to correctly discover repositories at a
Win32 system root. Instead of aborting the upwards-traversal of
the file system, we were looping infinitely when traversal
started at either a Win32 drive prefix ("C:/") or a network path
("//somehost").

The issue has been fixed, so add a test to catch regressions.
2017-02-08 12:06:05 +01:00
Patrick Steinhardt
9e8d75c7d4 path: ensure dirname on Win32 prefix always has a trailing '/'
When calling `git_path_dirname_r` on a Win32 prefix, e.g. a drive
or network share prefix, we always want to return the trailing
'/'. This does not work currently when passing in a path like
'C:', where the '/' would not be appended correctly.

Fix this by appending a '/' if we try to normalize a Win32 prefix
and there is no trailing '/'.
2017-02-08 12:05:47 +01:00
Patrick Steinhardt
5d59520ccd path: get correct dirname for Windows root
Getting the dirname of a filesystem root should return the filesystem
root itself. E.g. the dirname of "/" is always "/". On Windows, we
emulate this behavior and as such, we should return e.g. "C:/" if
calling dirname on "C:/". But we currently fail to do so and instead
return ".", as we do not check if we actually have a Windows prefix
before stripping off the last directory component.

Fix this by calling out to `win32_prefix_length` immediately after
stripping trailing slashes, returning early if we have a prefix.
2017-02-08 12:03:49 +01:00
Adam Niedzielski
390431c322 revwal: add failing test for walking with topo-sort 2017-02-02 16:01:37 +01:00
Edward Thomson
1f813cf2b8 checkout::tree test: cleanup memory leak 2017-01-23 17:32:13 -06:00
Edward Thomson
98f5387233 Merge pull request #4016 from novalis/submodule-optimization
Submodule optimization
2017-01-21 18:57:28 +00:00
Edward Thomson
52949c806b Merge branch 'pr/4060' 2017-01-21 18:30:12 +00:00
Brock Peabody
4d99c4cfc6 Allow for caching of submodules.
Added `git_repository_submodule_cache_all` to initialze a cache of
submodules on the repository so that operations looking up N
submodules are O(N) and not O(N^2).  Added a
`git_repository_submodule_cache_clear` function to remove the cache.

Also optimized the function that loads all submodules as it was itself
O(N^2) w.r.t the number of submodules, having to loop through the
`.gitmodules` file once per submodule.  I changed it to process the
`.gitmodules` file once, into a map.

Signed-off-by: David Turner <dturner@twosigma.com>
2017-01-20 17:33:56 -05:00
Edward Thomson
cb76eed5ce Merge pull request #4054 from jfultz/jfultz/fix_GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
2017-01-14 17:41:49 +00:00
Carlos Martín Nieto
2854e61956 Merge pull request #4061 from libgit2/ethomson/merge_opts
merge: set default rename threshold
2017-01-14 17:12:23 +00:00
lhchavez
f5586f5c73 Addressed review feedback 2017-01-14 16:37:00 +00:00
Carlos Martín Nieto
a6d833a29e Merge pull request #4049 from libgit2/ethomson/error_msgs
giterr_set: consistent error messages
2017-01-13 17:05:58 +01:00
Carlos Martín Nieto
2ac57aa89b https: don't test that RC4 is invalid
None of our crypto backends actually reject RC4 as a cipher so don't
test for it and instead keep it as something we'd like to do.
2017-01-09 18:32:11 +00:00
Carlos Martín Nieto
3829ba2e71 http: correct the expected error for RC4
We must make sure that we're getting a certificate error from the
library so we know that we're testing the right thing.
2017-01-09 17:58:58 +00:00
Carlos Martín Nieto
98d66240ec http: perform 'badssl' check also via certificate callback
Make sure that the callbacks do also get a 'valid' value of zero when
the certificate we're looking at is in valid and assert that within the
test.
2017-01-06 17:09:52 +00:00
lhchavez
a7ff6e5e5e Fix the memory leak 2017-01-03 18:24:51 -08:00
lhchavez
def644e48a Add a test 2017-01-01 17:35:29 -08:00
Edward Thomson
19ed4d0ca3 merge: set default rename threshold
When `GIT_MERGE_FIND_RENAMES` is set, provide a default for
`rename_threshold` when it is unset.
2017-01-01 22:34:43 +00:00
John Fultz
5f959dca0d Fix handling of GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH flag.
git_checkout_tree() sets up its working directory iterator to respect the
pathlist if GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH is present, which is great.
What's not so great is that this iterator is then used side-by-side with
an iterator created by git_checkout_iterator(), which did not set up its
pathlist appropriately (although the iterator mirrors all other iterator
options).

This could cause git_checkout_tree() to delete working tree files which
were not specified in the pathlist when GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH
was used, as the unsynchronized iterators causes git_checkout_tree() to think
that files have been deleted between the two trees.  Oops.

And added a test which fails without this fix (specifically, the final check
for "testrepo/README" to still be present fails).
2016-12-29 20:13:03 -06:00
Edward Thomson
8f0d5cdef9 tests: update error message checking 2016-12-29 12:55:49 +00:00
Edward Thomson
8d7717c471 Merge pull request #4034 from libgit2/cmn/sysdir-no-reguess
sysdir: don't re-guess when using variable substitution
2016-12-20 15:32:49 +00:00
Carlos Martín Nieto
410855fc4b sysdir: add failing test for variable substitution
When given $PATH as part of a search path, we guess again instead of
substituting what the user already set.
2016-12-18 14:47:27 +00:00
Carlos Martín Nieto
f7dcd58cc7 rebase: plug a leak in the tests 2016-12-17 00:55:06 +00:00
Edward Thomson
c5e6ba2892 Merge pull request #4029 from libgit2/cmn/windows-no-concurrent-compress
refdb: disable concurrent compress in the threading tests on Windows
2016-12-15 18:19:49 -06:00
Carlos Martín Nieto
b31283a658 refdb: disable concurrent compress in the threading tests on Windows
This is far from an ideal situation, but this causes issues on Windows which
make it harder to develop anything, as these tests hit issues which relate
specifically to the Windows filesystem like permission errors for files we
should be able to access. There is an issue likely related to the ordering of
the repack, but there's enough noise that it does not currently help us to run
this aspect of the test in CI.
2016-12-12 17:09:12 +00:00
Patrick Steinhardt
ab0cc5a059 clar: mark cl_git_thread_check() as inline
The function `cl_git_thread_check()` is defined as static. As the
function is defined in a header file which is included by our
tests, this can result in warnings for every test file where
`cl_git_thread_check` is never used.

Fix the issue by marking it as inline instead.
2016-12-12 09:16:33 +01:00
David Turner
4db1fc7e5e git_rebase_init: correctly handle detached HEAD
git_rebase_finish relies on head_detached being set, but
rebase_init_merge was only setting it when branch->ref_name was unset.
But branch->ref_name would be set to "HEAD" in the case of detached
HEAD being either implicitly (NULL) or explicitly passed to
git_rebase_init.
2016-12-01 23:11:57 -05:00
Edward Thomson
6367c58cd4 tests: handle life without threads 2016-11-18 19:00:14 +00:00
Edward Thomson
6a05c7a0ef threads::refdb tests: use new threaded clar assert 2016-11-18 16:52:28 +00:00
Edward Thomson
bbf22f8229 clar: Introduce assertion helpers for threads
Don't `cl_git_pass` in a child thread.  When the assertion fails, clar
will `longjmp` to its error handler, but:

> The effect of a call to longjmp() where initialization of the jmp_buf
> structure was not performed in the calling thread is undefined.

Instead, set up an error context that threads can populate, and the
caller can check.
2016-11-18 16:52:28 +00:00