]> git.ipfire.org Git - thirdparty/git.git/blob - branch.h
t5312: prepare for reftable
[thirdparty/git.git] / branch.h
1 #ifndef BRANCH_H
2 #define BRANCH_H
3
4 struct repository;
5 struct strbuf;
6
7 enum 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 };
16
17 extern enum branch_track git_branch_track;
18
19 /* Functions for acting on the information about branches. */
20
21 /*
22 * Creates a new branch, where:
23 *
24 * - r is the repository to add a branch to
25 *
26 * - name is the new branch name
27 *
28 * - start_name is the name of the existing branch that the new branch should
29 * start from
30 *
31 * - force enables overwriting an existing (non-head) branch
32 *
33 * - clobber_head_ok allows the currently checked out (hence existing)
34 * branch to be overwritten; without 'force', it has no effect.
35 *
36 * - reflog creates a reflog for the branch
37 *
38 * - quiet suppresses tracking information
39 *
40 * - track causes the new branch to be configured to merge the remote branch
41 * that start_name is a tracking branch for (if any).
42 *
43 */
44 void create_branch(struct repository *r,
45 const char *name, const char *start_name,
46 int force, int clobber_head_ok,
47 int reflog, int quiet, enum branch_track track);
48
49 /*
50 * Check if 'name' can be a valid name for a branch; die otherwise.
51 * Return 1 if the named branch already exists; return 0 otherwise.
52 * Fill ref with the full refname for the branch.
53 */
54 int validate_branchname(const char *name, struct strbuf *ref);
55
56 /*
57 * Check if a branch 'name' can be created as a new branch; die otherwise.
58 * 'force' can be used when it is OK for the named branch already exists.
59 * Return 1 if the named branch already exists; return 0 otherwise.
60 * Fill ref with the full refname for the branch.
61 */
62 int validate_new_branchname(const char *name, struct strbuf *ref, int force);
63
64 /*
65 * Remove information about the merge state on the current
66 * branch. (E.g., MERGE_HEAD)
67 */
68 void remove_merge_branch_state(struct repository *r);
69
70 /*
71 * Remove information about the state of working on the current
72 * branch. (E.g., MERGE_HEAD)
73 */
74 void remove_branch_state(struct repository *r, int verbose);
75
76 /*
77 * Configure local branch "local" as downstream to branch "remote"
78 * from remote "origin". Used by git branch --set-upstream.
79 * Returns 0 on success.
80 */
81 #define BRANCH_CONFIG_VERBOSE 01
82 int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
83
84 /*
85 * Read branch description
86 */
87 int read_branch_desc(struct strbuf *, const char *branch_name);
88
89 /*
90 * Check if a branch is checked out in the main worktree or any linked
91 * worktree and die (with a message describing its checkout location) if
92 * it is.
93 */
94 void die_if_checked_out(const char *branch, int ignore_current_worktree);
95
96 /*
97 * Update all per-worktree HEADs pointing at the old ref to point the new ref.
98 * This will be used when renaming a branch. Returns 0 if successful, non-zero
99 * otherwise.
100 */
101 int replace_each_worktree_head_symref(const char *oldref, const char *newref,
102 const char *logmsg);
103
104 #endif