summaryrefslogtreecommitdiff
path: root/src/branch.c
Commit message (Collapse)AuthorAgeFilesLines
* str: introduce `git_str` for internal, `git_buf` is externalethomson/gitstrEdward Thomson2021-10-171-107/+145
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* branch: git branch upstream with format format name parameter has been added.Dmitry Lobanov2021-05-181-28/+3
|
* branch: git branch upstream functions layouts have been fixed.Dmitry Lobanov2021-05-161-4/+6
|
* branch: git branch upstream format enum has been added.Dmitry Lobanov2021-05-161-4/+27
|
* branch: git branch upstream functions layouts have been fixed.Dmitry Lobanov2021-05-161-2/+4
|
* branch: git branch upstream merge has been exposed.Dmitry Lobanov2021-05-121-0/+8
|
* branch: git branch upstream with format has been added.Dmitry Lobanov2021-05-121-2/+2
|
* buffer: git_buf_sanitize should return a valueEdward Thomson2020-11-251-5/+6
| | | | | | `git_buf_sanitize` is called with user-input, and wants to sanity-check that input. Allow it to return a value if the input was malformed in a way that we cannot cope.
* branch: use GIT_ASSERTEdward Thomson2020-11-251-10/+22
|
* Add git_branch_name_is_validSven Strickroth2020-10-251-0/+29
| | | | Signed-off-by: Sven Strickroth <email@cs-ware.de>
* branch: determine whether a branch is checked out via refdbPatrick Steinhardt2020-07-121-20/+18
| | | | | | | | | | We currently determine whether a branch is checked out via `git_repository_foreach_head`. As this function reads references directly from the disk, it breaks our refdb abstraction in case the repository uses a different reference backend implementation than the filesystem-based one. So let's use `git_repository_foreach_worktree` instead -- while it's less efficient, it is at least correct in all corner cases.
* strarray: we should `dispose` instead of `free`Edward Thomson2020-06-011-1/+1
| | | | | | We _dispose_ the contents of objects; we _free_ objects (and their contents). Update `git_strarray_free` to be `git_strarray_dispose`. `git_strarray_free` remains as a deprecated proxy function.
* branch: clarify documentation around branchesEtienne Samson2019-12-071-27/+31
|
* branch: have git_branch_lookup accept GIT_BRANCH_ALLAugustin Fabre2019-02-221-2/+16
|
* branch: fix `branch_is_checked_out` with bare reposPatrick Steinhardt2019-02-141-2/+9
| | | | | | | | | | In a bare repository, HEAD usually points to the branch that is considered the "default" branch. As the current implementation for `git_branch_is_checked_out` only does a comparison of HEAD with the branch that is to be checked, it will say that the branch pointed to by HEAD in such a bare repo is checked out. Fix this by skipping the main repo's HEAD when it is bare.
* branches: introduce flag to skip enumeration of certain HEADsPatrick Steinhardt2019-02-141-1/+1
| | | | | | | Right now, the function `git_repository_foreach_head` will always iterate over all HEADs of the main repository and its worktrees. In some cases, it might be required to skip either of those, though. Add a flag in preparation for the following commit that enables this behaviour.
* branches: do not assert that the given ref is a branchPatrick Steinhardt2019-02-141-1/+4
| | | | | | | | | | | | | | | | | Libraries should use assert(3P) only very scarcely. First, we usually shouldn't cause the caller of our library to abort in case where the assert fails. Second, if code is compiled with -DNDEBUG, then the assert will not be included at all. In our `git_branch_is_checked_out` function, we have an assert that verifies that the given reference parameter is non-NULL and in fact a branch. While the first check is fine, the second is not. E.g. when compiled with -DNDEBUG, we'd proceed and treat the given reference as a branch in all cases. Fix the issue by instead treating a non-branch reference as not being checked out. This is the obvious solution, as references other than branches cannot be directly checked out.
* git_error: use new names in internal APIs and usageEdward Thomson2019-01-221-17/+17
| | | | | Move to the `git_error` name in the internal API for error-related functions.
* references: use new names in internal usageethomson/git_refEdward Thomson2019-01-171-1/+1
| | | | Update internal usage to use the `git_reference` names for constants.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-20/+20
|
* branch: refuse creating branches named 'HEAD'Patrick Steinhardt2018-01-191-0/+6
| | | | | | | | Since a625b092c (branch: correctly reject refs/heads/{-dash,HEAD}, 2017-11-14), which is included in v2.16.0, upstream git refuses to create branches which are named HEAD to avoid ambiguity with the symbolic HEAD reference. Adjust our own code to match that behaviour and reject creating branches names HEAD.
* Make sure to always include "common.h" firstPatrick Steinhardt2017-07-031-1/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* worktrees: cleanup some memory leaksEdward Thomson2017-05-011-4/+6
| | | | | Be sure to clean up looked up references. Free buffers instead of merely clearing them. Use `git__free` instead of `free`.
* branch: use `foreach_head` to see if a branch is checked outPatrick Steinhardt2017-04-051-49/+16
| | | | | Previously, we have extracted the logic to find and iterate over all HEADs of a repository. Use this function in `git_branch_is_checked_out`.
* branch: restrict branch deletion for worktreesPatrick Steinhardt2017-02-131-0/+6
| | | | | Restrict the ability to delete branches that are checked out in any linked repository.
* branch: implement `git_branch_is_checked_out`Patrick Steinhardt2017-02-131-0/+57
| | | | | | | | Implement a new function that is able to determine if a branch is checked out in any repository connected to the current repository. In particular, this is required to check if for a given repository and branch, there exists any working tree connected to that repository that is referencing this branch.
* giterr_set: consistent error messagesEdward Thomson2016-12-291-10/+10
| | | | | | | | Error messages should be sentence fragments, and therefore: 1. Should not begin with a capital letter, 2. Should not conclude with punctuation, and 3. Should not end a sentence and begin a new one
* branch: fix forced branch creation on HEAD of a bare repoJohn Fultz2016-11-041-4/+5
| | | | | | | | | | | | | The code correctly detects that forced creation of a branch on a nonbare repo should not be able to overwrite a branch which is the HEAD reference. But there's no reason to prevent this on a bare repo, and in fact, git allows this. I.e., git branch -f master new_sha works on a bare repo with HEAD set to master. This change fixes that problem, and updates tests so that, for this case, both the bare and nonbare cases are checked for correct behavior.
* annotated_commit: provide refs and descriptionethomson/annotated_commit_refsEdward Thomson2016-04-261-1/+2
| | | | | | | | | | | Differentiate between the ref_name used to create an annotated_commit (that can subsequently be used to look up the reference) and the description that we resolved this with (which _cannot_ be looked up). The description is used for things like reflogs (and may be a ref name, and ID something that we revparsed to get here), while the ref name must actually be a reference name, and is used for things like rebase to return to the initial branch.
* refdb: delete a ref's reflog upon deletioncmn/reflog-del-backendCarlos Martín Nieto2015-07-121-12/+1
| | | | | | Removing a reflog upon ref deletion is something which only some backends might wish to do. Backends which are database-backed may wish to archive a reflog, log-based ones may not need to do anything.
* branch: error out if we cannot find the remotecmn/upstream-matching-pushCarlos Martín Nieto2015-05-221-3/+6
| | | | | | | | | | | When we look for which remote corresponds to a remote-tracking branch, we look in the refspecs to see which ones matches. If none do, we should abort. We currently ignore the error message from this operation, so let's not do that anymore. As part of the test we're writing, let's test for the expected behaviour if we cannot find a refspec which tells us what the remote-tracking branch for a remote would look like.
* Add annotated commit versions of reflog-modifying functionsCarlos Martín Nieto2015-03-161-2/+24
| | | | | | | We do not always want to put the id directly into the reflog, but we want to speicfy what a user typed. For this use-case we provide annotated version of a few functions which let the caller specify what user-friendly name was used when asking for the operation.
* Drop trailing whitespacesntk/reflog_branch_createnulltoken2015-03-041-1/+1
|
* branch: fix generated reflog message upon renamingnulltoken2015-03-041-1/+1
|
* branch: fix generated reflog message upon creationnulltoken2015-03-041-1/+1
|
* config: borrow refcounted referencescmn/config-borrow-entryCarlos Martín Nieto2015-03-031-20/+19
| | | | | | | | | | | | | | | This changes the get_entry() method to return a refcounted version of the config entry, which you have to free when you're done. This allows us to avoid freeing the memory in which the entry is stored on a refresh, which may happen at any time for a live config. For this reason, get_string() has been forbidden on live configs and a new function get_string_buf() has been added, which stores the string in a git_buf which the user then owns. The functions which parse the string value takea advantage of the borrowing to parse safely and then release the entry.
* branch: don't accept a reflog message overrideCarlos Martín Nieto2015-03-031-18/+11
| | | | | | | This namespace is about behaving like git's branch command, so let's do exactly that instead of taking a reflog message. This override is still available via the reference namespace.
* Remove the signature from ref-modifying functionsCarlos Martín Nieto2015-03-031-4/+2
| | | | | | | | | | The signature for the reflog is not something which changes dynamically. Almost all uses will be NULL, since we want for the repository's default identity to be used, making it noise. In order to allow for changing the identity, we instead provide git_repository_set_ident() and git_repository_ident() which allow a user to override the choice of signature.
* branch: do capture the error codeCarlos Martín Nieto2015-03-031-1/+1
| | | | | We want to ignore GIT_ENOTFOUND, but for that we need to capture the error code from the reflog deletion.
* git_branch_delete() should ignore errors from non-existing reflogsPierre-Olivier Latour2015-03-021-1/+6
|
* branch: consider an empty upstream remote config as not foundCarlos Martín Nieto2014-11-171-0/+6
|
* Merge pull request #2698 from libgit2/cmn/fetchhead-refactorEdward Thomson2014-11-081-0/+23
|\ | | | | Refactor fetchhead
| * branch: add getter for the upstream remote nameCarlos Martín Nieto2014-11-081-0/+23
| | | | | | | | This gets the value from branch.<foo>.remote.
* | remote: rename _load() to _lookup()cmn/remote-lookupCarlos Martín Nieto2014-11-081-3/+3
|/ | | | This brings it in line with the rest of the lookup functions.
* repository: introduce a convenience config snapshot methodcmn/config-snapshotCarlos Martín Nieto2014-05-071-5/+2
| | | | | | Accessing the repository's config and immediately taking a snapshot of it is a common operation, so let's provide a convenience function for it.
* Use config snapshottingCarlos Martín Nieto2014-04-181-7/+11
| | | | | This way we can assume we have a consistent view of the config situation when we're looking up remote, branch, pack-objects, etc.
* Const correctness!Jacques Germishuys2014-04-031-3/+5
|
* branch: constness fixesCarlos Martín Nieto2014-03-171-1/+1
|
* branch: fix leak when checking against HEADCarlos Martín Nieto2014-03-071-5/+11
| | | | | | | | We look up a reference in order to figure out if it's the current branch, which we need to free once we're done with the check. As a bonus, only perform the check when we're passed the force flag, as it's a useless check otherwise.
* Do not allow git_branch_create() to force update branchLinquize2014-02-271-0/+13
|