summaryrefslogtreecommitdiff
path: root/src/worktree.c
Commit message (Collapse)AuthorAgeFilesLines
* worktree: error out early if given ref is not validPatrick Steinhardt2019-02-141-12/+14
| | | | | | | | | | | | When adding a new worktree, we only verify that an optionally given reference is valid half-way through the function. At this point, some data structures have already been created on-disk. If we bail out due to an invalid reference, these will be left behind and need to be manually cleaned up by the user. Improve the situation by moving the reference checks to the function's preamble. Like this, we error out as early as possible and will not leave behind any files.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-13/+13
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* worktree: unlock should return 1 when the worktree isn't lockedEtienne Samson2018-08-171-1/+1
| | | | | The documentation states that git_worktree_unlock returns 0 on success, and 1 on success if the worktree wasn't locked. Turns out we were returning 0 in any of those cases.
* worktree: don't return "untyped" negative numbers as error codesEtienne Samson2018-06-291-11/+4
|
* worktree: skip building a buffer when validatingEtienne Samson2018-06-291-4/+1
|
* tests: worktree/bare: fix git_worktree_validateEtienne Samson2018-06-291-1/+1
|
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-20/+20
|
* worktree: a worktree can be made from a bare repositoryEtienne Samson2018-05-071-1/+1
|
* Merge pull request #4640 from mkeeler/worktree-convenience2Patrick Steinhardt2018-04-301-1/+15
|\ | | | | worktree: add functions to get name and path
| * worktree: add functions to get name and pathMatt Keeler2018-04-251-1/+15
| |
* | worktree: fix calloc of the wrong object typeEtienne Samson2018-04-201-1/+1
| |
* | Merge pull request #4524 from pks-t/pks/worktree-refsEdward Thomson2018-04-171-7/+24
|\ \ | |/ |/| worktree: add ability to create worktree with pre-existing branch
| * worktree: add ability to create worktree with pre-existing branchPatrick Steinhardt2018-02-091-7/+24
| | | | | | | | | | | | | | | | | | | | | | Currently, we always create a new branch after the new worktree's name when creating a worktree. In some workflows, though, the caller may want to check out an already existing reference instead of creating a new one, which is impossible to do right now. Add a new option `ref` to the options structure for adding worktrees. In case it is set, a branch and not already checked out by another worktree, we will re-use this reference instead of creating a new one.
* | worktree: rename parameter creason to reasonJacques Germishuys2018-03-031-3/+3
| |
* | worktree: lock reason should be constJacques Germishuys2018-03-021-1/+1
|/
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | Next to including several files, our "common.h" header also declares various macros which are then used throughout the project. As such, we have to make sure to always include this file first in all implementation files. Otherwise, we might encounter problems or even silent behavioural differences due to macros or defines not being defined as they should be. So in fact, our header and implementation files should make sure to always include "common.h" first. This commit does so by establishing a common include pattern. Header files inside of "src" will now always include "common.h" as its first other file, separated by a newline from all the other includes to make it stand out as special. There are two cases for the implementation files. If they do have a matching header file, they will always include this one first, leading to "common.h" being transitively included as first file. If they do not have a matching header file, they instead include "common.h" as first file themselves. This fixes the outlined problems and will become our standard practice for header and source files inside of the "src/" from now on.
* worktree: use `git__free` instead of `free`Patrick Steinhardt2017-06-081-1/+1
|
* worktree: switch over worktree pruning to an opts structurePatrick Steinhardt2017-05-051-6/+33
| | | | | | | | | | 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.
* worktree: support creating locked worktreesPatrick Steinhardt2017-05-051-0/+15
| | | | | | | | | | | | | 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.
* worktree: introduce git_worktree_add optionsPatrick Steinhardt2017-05-021-1/+18
| | | | | | | | | 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.
* worktree: unconditionally free the worktree's namePatrick Steinhardt2017-03-241-2/+1
|
* worktree: write resolved paths into link filesPatrick Steinhardt2017-03-171-5/+10
| | | | | | | | 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.
* worktree: rename variable in `git_worktree_add`Patrick Steinhardt2017-03-171-13/+13
|
* worktree: use fully qualified reference name for created HEADPatrick Steinhardt2017-03-171-1/+1
| | | | | | | | | 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.
* worktree: parent path should point to the working dirPatrick Steinhardt2017-03-171-3/+3
| | | | | | | | | 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.
* worktree: implement `git_worktree_open_from_repository`Patrick Steinhardt2017-03-171-0/+33
| | | | | | | | | 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.
* worktree: split off function opening working directoryPatrick Steinhardt2017-03-171-17/+38
| | | | | | 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.
* worktree: have `is_worktree_dir` accept a string instead of bufferPatrick Steinhardt2017-03-171-7/+16
| | | | | This will be used in later commits, where it becomes cumbersome to always pass in a buffer.
* worktree: extract git_worktree_is_prunablePatrick Steinhardt2017-02-131-7/+17
|
* worktree: compute workdir for worktrees opened via their gitdirPatrick Steinhardt2017-02-131-3/+3
| | | | | | | | | | | | | | | | | | | | | 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.
* worktree: implement `git_worktree_prune`Patrick Steinhardt2017-02-131-0/+64
| | | | | | | 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.
* worktree: implement locking mechanismsPatrick Steinhardt2017-02-131-0/+73
| | | | | | 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.
* worktree: implement `git_worktree_add`Patrick Steinhardt2017-02-131-1/+101
| | | | | Implement the `git_worktree_add` function which can be used to create new working trees for a given repository.
* worktree: implement `git_worktree_validate`Patrick Steinhardt2017-02-131-0/+38
| | | | | | 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.
* worktree: introduce `struct git_worktree`Patrick Steinhardt2017-02-131-0/+89
| | | | | | | 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.
* worktree: implement `git_worktree_list`Patrick Steinhardt2017-02-131-0/+58
Add new module for working trees with the `git_worktree_list` function. The function lists names for all working trees of a certain repository.