summaryrefslogtreecommitdiff
path: root/src/worktree.c
Commit message (Collapse)AuthorAgeFilesLines
* worktree: checkout options suggestions from code reviewEdward Thomson2021-12-231-6/+6
|
* Change default checkout strategy from FORCE to SAFEpunkymaniac2021-12-231-2/+0
| | | | | | Since we are able to give our own git checkout options, the default git checkout strategy will be the same as initialized in a new git_checkout_options struct.
* Allow user checkout options on git_worktree_addpunkymaniac2021-12-231-1/+4
| | | | | | Extend the `git_worktree_add_options` to include `git_checkout_options`. github issue #5949
* path: use new length validation functionsEdward Thomson2021-11-091-1/+2
|
* path: separate git-specific path functions from utilEdward Thomson2021-11-091-24/+24
| | | | | | Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path).
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-65/+85
| | | | | | | | | | | | | | | | | | | | | | | | | | | libgit2 has two distinct requirements that were previously solved by `git_buf`. We require: 1. A general purpose string class that provides a number of utility APIs for manipulating data (eg, concatenating, truncating, etc). 2. A structure that we can use to return strings to callers that they can take ownership of. By using a single class (`git_buf`) for both of these purposes, we have confused the API to the point that refactorings are difficult and reasoning about correctness is also difficult. Move the utility class `git_buf` to be called `git_str`: this represents its general purpose, as an internal string buffer class. The name also is an homage to Junio Hamano ("gitstr"). The public API remains `git_buf`, and has a much smaller footprint. It is generally only used as an "out" param with strict requirements that follow the documentation. (Exceptions exist for some legacy APIs to avoid breaking callers unnecessarily.) Utility functions exist to convert a user-specified `git_buf` to a `git_str` so that we can call internal functions, then converting it back again.
* bugfix: don't generate paths with empty segmentsPeter Pettersson2021-08-081-3/+3
|
* worktree: validate worktree pathsEdward Thomson2021-04-281-2/+5
| | | | | Worktree paths need to fix within MAX_PATH always, regardless of `core.longpaths` setting.
* worktree: use GIT_ASSERTEdward Thomson2020-11-271-11/+19
|
* Apply suggestions from code reviewEdward Thomson2020-11-211-1/+1
|
* worktree: Added worktree_dir checkReginald McLean2020-11-061-1/+8
| | | | Fixes #5280
* tree-wide: do not compile deprecated functions with hard deprecationPatrick Steinhardt2020-06-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | When compiling libgit2 with -DDEPRECATE_HARD, we add a preprocessor definition `GIT_DEPRECATE_HARD` which causes the "git2/deprecated.h" header to be empty. As a result, no function declarations are made available to callers, but the implementations are still available to link against. This has the problem that function declarations also aren't visible to the implementations, meaning that the symbol's visibility will not be set up correctly. As a result, the resulting library may not expose those deprecated symbols at all on some platforms and thus cause linking errors. Fix the issue by conditionally compiling deprecated functions, only. While it becomes impossible to link against such a library in case one uses deprecated functions, distributors of libgit2 aren't expected to pass -DDEPRECATE_HARD anyway. Instead, users of libgit2 should manually define GIT_DEPRECATE_HARD to hide deprecated functions. Using "real" hard deprecation still makes sense in the context of CI to test we don't use deprecated symbols ourselves and in case a dependant uses libgit2 in a vendored way and knows it won't ever use any of the deprecated symbols anyway.
* Fix typo causing removal of symbol 'git_worktree_prune_init_options'Seth Junot2020-04-041-1/+1
| | | | | | Commit 0b5ba0d replaced this function with an "option_init" equivallent, but misspelled the replacement function. As a result, this symbol has been missing from libgit2.so ever since.
* worktree: report errors when unable to read locking reasonPatrick Steinhardt2020-02-071-28/+44
| | | | | | | | | | | | | | Git worktree's have the ability to be locked in order to spare them from deletion, e.g. if a worktree is absent due to being located on a removable disk it is a good idea to lock it. When locking such worktrees, it is possible to give a locking reason in order to help the user later on when inspecting status of any such locked trees. The function `git_worktree_is_locked` serves to read out the locking status. It currently does not properly report any errors when reading the reason file, and callers are unexpecting of any negative return values, too. Fix this by converting callers to expect error codes and checking the return code of `git_futils_readbuffer`.
* worktree: use size_t for sizesEdward Thomson2019-06-241-1/+1
|
* errors: use lowercaseethomson/error_messagesEdward Thomson2019-06-231-7/+7
| | | | Use lowercase for our error messages, per our custom.
* Rename opt init functions to `options_init`Edward Thomson2019-06-141-2/+14
| | | | | | | | | | | | | In libgit2 nomenclature, when we need to verb a direct object, we name a function `git_directobject_verb`. Thus, if we need to init an options structure named `git_foo_options`, then the name of the function that does that should be `git_foo_options_init`. The previous names of `git_foo_init_options` is close - it _sounds_ as if it's initializing the options of a `foo`, but in fact `git_foo_options` is its own noun that should be respected. Deprecate the old names; they'll now call directly to the new ones.
* 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.