Commit Graph

2005 Commits

Author SHA1 Message Date
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