interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / branch.h

169 lines · 5754 bytes Raw Blame History
1#ifndef BRANCH_H
2#define BRANCH_H
3
4struct repository;
5struct strbuf;
6
7enum branch_track {
8 BRANCH_TRACK_UNSPECIFIED = -1,
9 BRANCH_TRACK_NEVER = 0,
10 BRANCH_TRACK_REMOTE,
11 BRANCH_TRACK_ALWAYS,
12 BRANCH_TRACK_EXPLICIT,
13 BRANCH_TRACK_OVERRIDE,
14 BRANCH_TRACK_INHERIT,
15 BRANCH_TRACK_SIMPLE,
16};
17
18/* Functions for acting on the information about branches. */
19
20/**
21 * Sets branch.<new_ref>.{remote,merge} config settings such that
22 * new_ref tracks orig_ref according to the specified tracking mode.
23 *
24 * - new_ref is the name of the branch that we are setting tracking
25 * for.
26 *
27 * - orig_ref is the name of the ref that is 'upstream' of new_ref.
28 * orig_ref will be expanded with DWIM so that the config settings
29 * are in the correct format e.g. "refs/remotes/origin/main" instead
30 * of "origin/main".
31 *
32 * - track is the tracking mode e.g. BRANCH_TRACK_REMOTE causes
33 * new_ref to track orig_ref directly, whereas BRANCH_TRACK_INHERIT
34 * causes new_ref to track whatever orig_ref tracks.
35 *
36 * - quiet suppresses tracking information.
37 *
38 * Returns 0 on success, or -1 if the tracking configuration could not be
39 * written.
40 */
41int dwim_and_setup_tracking(struct repository *r, const char *new_ref,
42 const char *orig_ref, enum branch_track track,
43 int quiet);
44
45/*
46 * Creates a new branch, where:
47 *
48 * - r is the repository to add a branch to
49 *
50 * - name is the new branch name
51 *
52 * - start_name is the name of the existing branch that the new branch should
53 * start from
54 *
55 * - force enables overwriting an existing (non-head) branch
56 *
57 * - clobber_head_ok, when enabled with 'force', allows the currently
58 * checked out (head) branch to be overwritten
59 *
60 * - reflog creates a reflog for the branch
61 *
62 * - quiet suppresses tracking information
63 *
64 * - track causes the new branch to be configured to merge the remote branch
65 * that start_name is a tracking branch for (if any).
66 *
67 * - dry_run causes the branch to be validated but not created.
68 *
69 * Returns 0 on success, or -1 if the tracking configuration could not be
70 * written.
71 */
72int create_branch(struct repository *r,
73 const char *name, const char *start_name,
74 int force, int clobber_head_ok,
75 int reflog, int quiet, enum branch_track track,
76 int dry_run);
77
78/*
79 * Creates a new branch in a repository and its submodules (and its
80 * submodules, recursively). The parameters are mostly analogous to
81 * those of create_branch() except for start_name, which is represented
82 * by two different parameters:
83 *
84 * - start_committish is the commit-ish, in repository r, that determines
85 * which commits the branches will point to. The superproject branch
86 * will point to the commit of start_committish and the submodule
87 * branches will point to the gitlink commit oids in start_committish's
88 * tree.
89 *
90 * - tracking_name is the name of the ref, in repository r, that will be
91 * used to set up tracking information. This value is propagated to
92 * all submodules, which will evaluate the ref using their own ref
93 * stores. If NULL, this defaults to start_committish.
94 *
95 * When this function is called on the superproject, start_committish
96 * can be any user-provided ref and tracking_name can be NULL (similar
97 * to create_branches()). But when recursing through submodules,
98 * start_committish is the plain gitlink commit oid. Since the oid cannot
99 * be used for tracking information, tracking_name is propagated and
100 * used for tracking instead.
101 */
102void create_branches_recursively(struct repository *r, const char *name,
103 const char *start_committish,
104 const char *tracking_name, int force,
105 int reflog, int quiet, enum branch_track track,
106 int dry_run);
107
108/*
109 * If the branch at 'refname' is currently checked out in a worktree,
110 * then return the path to that worktree.
111 */
112const char *branch_checked_out(const char *refname);
113
114/*
115 * If the branch at 'refname' is currently used for bisecting in a
116 * worktree, then return the path to that worktree.
117 */
118const char *branch_bisecting(const char *refname);
119
120/*
121 * Check if 'name' can be a valid name for a branch; die otherwise.
122 * Return 1 if the named branch already exists; return 0 otherwise.
123 * Fill ref with the full refname for the branch.
124 */
125int validate_branchname(const char *name, struct strbuf *ref);
126
127/*
128 * Check if a branch 'name' can be created as a new branch; die otherwise.
129 * 'force' can be used when it is OK for the named branch already exists.
130 * Return 1 if the named branch already exists; return 0 otherwise.
131 * Fill ref with the full refname for the branch.
132 */
133int validate_new_branchname(const char *name, struct strbuf *ref, int force);
134
135#define REMOVE_BRANCH_STATE_VERBOSE (1u << 0)
136#define REMOVE_BRANCH_STATE_PRESERVE_CONFLICT_LABELS (1u << 1)
137/*
138 * Remove information about the merge state on the current
139 * branch. (E.g., MERGE_HEAD)
140 */
141void remove_merge_branch_state(struct repository *r);
142
143/*
144 * Remove information about the state of working on the current
145 * branch. (E.g., MERGE_HEAD)
146 */
147void remove_branch_state(struct repository *r, unsigned flags);
148
149/*
150 * Configure local branch "local" as downstream to branch "remote"
151 * from remote "origin". Used by git branch --set-upstream.
152 * Returns 0 on success.
153 */
154#define BRANCH_CONFIG_VERBOSE 01
155int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
156
157/*
158 * Read branch description
159 */
160int read_branch_desc(struct strbuf *, const char *branch_name);
161
162/*
163 * Check if a branch is checked out in the main worktree or any linked
164 * worktree and die (with a message describing its checkout location) if
165 * it is.
166 */
167void die_if_checked_out(const char *branch, int ignore_current_worktree);
168
169#endif