Skip to content

Worktree fixes#4163

Merged
ethomson merged 13 commits into
libgit2:masterfrom
pks-t:pks/submodules-with-worktrees
Mar 22, 2017
Merged

Worktree fixes#4163
ethomson merged 13 commits into
libgit2:masterfrom
pks-t:pks/submodules-with-worktrees

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Mar 17, 2017

So this is the first batch of fixes for the worktree implementation. Fixes:

  • the parent path inside of the git_worktree path now correctly points to the parent repository, that is it will usually point to the parent working directory
  • resolving relative URLs for a working tree of a submodule now correctly resolves the URL relative to the working tree's parent working directory
  • a new function git_worktree_open_from_repository has been added to retrieve the worktree structure from a repository, if it actually is a working tree
  • non-per-worktree file references are now actually created in the common directory instead of the gitdir. This was a major oversight
  • worktree link files are now resolved so that we write absolute paths instead of relative paths
  • the HEAD reference for newly created worktrees now contains the fully qualified reference

pks-t added 13 commits March 15, 2017 12:01
This will be used in later commits, where it becomes cumbersome to
always pass in a buffer.
Separate the logic of finding the worktree directory of a repository and
actually opening the working tree's directory. This is a preparatory
step for opening the worktree structure of a repository itself.
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.
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.
When creating a new worktree, we have to set up the initial data
structures. Next to others, this also includes the HEAD pseudo-ref.
We currently set it to the worktree respectively branch name, which is
actually not fully qualified.

Use the fully qualified branch name instead.
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.
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.
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.
@ethomson ethomson merged commit f623cf8 into libgit2:master Mar 22, 2017
@pks-t pks-t deleted the pks/submodules-with-worktrees branch March 28, 2017 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants