]>
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, | |
e730b81d EN |
15 | }; |
16 | ||
17 | extern enum branch_track git_branch_track; | |
18 | ||
c369e7b8 DB |
19 | /* Functions for acting on the information about branches. */ |
20 | ||
e89f151d GC |
21 | /** |
22 | * Sets branch.<new_ref>.{remote,merge} config settings such that | |
23 | * new_ref tracks orig_ref according to the specified tracking mode. | |
24 | * | |
25 | * - new_ref is the name of the branch that we are setting tracking | |
26 | * for. | |
27 | * | |
28 | * - orig_ref is the name of the ref that is 'upstream' of new_ref. | |
29 | * orig_ref will be expanded with DWIM so that the config settings | |
30 | * are in the correct format e.g. "refs/remotes/origin/main" instead | |
31 | * of "origin/main". | |
32 | * | |
33 | * - track is the tracking mode e.g. BRANCH_TRACK_REMOTE causes | |
34 | * new_ref to track orig_ref directly, whereas BRANCH_TRACK_INHERIT | |
35 | * causes new_ref to track whatever orig_ref tracks. | |
36 | * | |
37 | * - quiet suppresses tracking information. | |
38 | */ | |
39 | void dwim_and_setup_tracking(struct repository *r, const char *new_ref, | |
40 | const char *orig_ref, enum branch_track track, | |
41 | int quiet); | |
42 | ||
c369e7b8 | 43 | /* |
4bd488ea JK |
44 | * Creates a new branch, where: |
45 | * | |
4edce172 NTND |
46 | * - r is the repository to add a branch to |
47 | * | |
4bd488ea JK |
48 | * - name is the new branch name |
49 | * | |
50 | * - start_name is the name of the existing branch that the new branch should | |
51 | * start from | |
52 | * | |
53 | * - force enables overwriting an existing (non-head) branch | |
54 | * | |
bc0893cf GC |
55 | * - clobber_head_ok, when enabled with 'force', allows the currently |
56 | * checked out (head) branch to be overwritten | |
f6cea74d | 57 | * |
4bd488ea JK |
58 | * - reflog creates a reflog for the branch |
59 | * | |
f6cea74d KS |
60 | * - quiet suppresses tracking information |
61 | * | |
4bd488ea JK |
62 | * - track causes the new branch to be configured to merge the remote branch |
63 | * that start_name is a tracking branch for (if any). | |
e2bbd0cc | 64 | * |
c369e7b8 | 65 | */ |
4edce172 NTND |
66 | void create_branch(struct repository *r, |
67 | const char *name, const char *start_name, | |
e2bbd0cc KS |
68 | int force, int clobber_head_ok, |
69 | int reflog, int quiet, enum branch_track track); | |
e496c003 | 70 | |
55c4a673 | 71 | /* |
bc1c9c0e JH |
72 | * Check if 'name' can be a valid name for a branch; die otherwise. |
73 | * Return 1 if the named branch already exists; return 0 otherwise. | |
74 | * Fill ref with the full refname for the branch. | |
75 | */ | |
55454427 | 76 | int validate_branchname(const char *name, struct strbuf *ref); |
bc1c9c0e JH |
77 | |
78 | /* | |
79 | * Check if a branch 'name' can be created as a new branch; die otherwise. | |
80 | * 'force' can be used when it is OK for the named branch already exists. | |
81 | * Return 1 if the named branch already exists; return 0 otherwise. | |
82 | * Fill ref with the full refname for the branch. | |
55c4a673 | 83 | */ |
55454427 | 84 | int validate_new_branchname(const char *name, struct strbuf *ref, int force); |
55c4a673 | 85 | |
b6433555 NTND |
86 | /* |
87 | * Remove information about the merge state on the current | |
88 | * branch. (E.g., MERGE_HEAD) | |
89 | */ | |
90 | void remove_merge_branch_state(struct repository *r); | |
91 | ||
c369e7b8 DB |
92 | /* |
93 | * Remove information about the state of working on the current | |
94 | * branch. (E.g., MERGE_HEAD) | |
95 | */ | |
f4a4b9ac | 96 | void remove_branch_state(struct repository *r, int verbose); |
c369e7b8 | 97 | |
a9f2c136 | 98 | /* |
13931236 MM |
99 | * Configure local branch "local" as downstream to branch "remote" |
100 | * from remote "origin". Used by git branch --set-upstream. | |
27852b2c | 101 | * Returns 0 on success. |
a9f2c136 JH |
102 | */ |
103 | #define BRANCH_CONFIG_VERBOSE 01 | |
55454427 | 104 | int install_branch_config(int flag, const char *local, const char *origin, const char *remote); |
a9f2c136 | 105 | |
6f9a3321 JH |
106 | /* |
107 | * Read branch description | |
108 | */ | |
55454427 | 109 | int read_branch_desc(struct strbuf *, const char *branch_name); |
6f9a3321 | 110 | |
ed89f84b ES |
111 | /* |
112 | * Check if a branch is checked out in the main worktree or any linked | |
113 | * worktree and die (with a message describing its checkout location) if | |
114 | * it is. | |
115 | */ | |
55454427 | 116 | void die_if_checked_out(const char *branch, int ignore_current_worktree); |
ed89f84b | 117 | |
70999e9c KY |
118 | /* |
119 | * Update all per-worktree HEADs pointing at the old ref to point the new ref. | |
120 | * This will be used when renaming a branch. Returns 0 if successful, non-zero | |
121 | * otherwise. | |
122 | */ | |
55454427 | 123 | int replace_each_worktree_head_symref(const char *oldref, const char *newref, |
ad6dad09 | 124 | const char *logmsg); |
70999e9c | 125 | |
e496c003 | 126 | #endif |