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