🌐 AI搜索 & 代理 主页
blob: 5cace4581fe43aa5fdc20b4315cee6eff1034003 [file] [log] [blame]
Daniel Barkalowe496c002008-02-07 16:40:081#ifndef BRANCH_H
2#define BRANCH_H
3
Elijah Newrenef3ca952018-08-15 17:54:054struct strbuf;
5
Elijah Newrene730b812018-08-15 17:54:076enum branch_track {
7 BRANCH_TRACK_UNSPECIFIED = -1,
8 BRANCH_TRACK_NEVER = 0,
9 BRANCH_TRACK_REMOTE,
10 BRANCH_TRACK_ALWAYS,
11 BRANCH_TRACK_EXPLICIT,
12 BRANCH_TRACK_OVERRIDE
13};
14
15extern enum branch_track git_branch_track;
16
Daniel Barkalowc369e7b2008-02-07 16:40:1617/* Functions for acting on the information about branches. */
18
19/*
Jeff King4bd488e2016-11-04 16:30:1220 * Creates a new branch, where:
21 *
22 * - name is the new branch name
23 *
24 * - start_name is the name of the existing branch that the new branch should
25 * start from
26 *
27 * - force enables overwriting an existing (non-head) branch
28 *
Kaartic Sivaraamf6cea742017-11-18 17:26:4529 * - clobber_head_ok allows the currently checked out (hence existing)
30 * branch to be overwritten; without 'force', it has no effect.
31 *
Jeff King4bd488e2016-11-04 16:30:1232 * - reflog creates a reflog for the branch
33 *
Kaartic Sivaraamf6cea742017-11-18 17:26:4534 * - quiet suppresses tracking information
35 *
Jeff King4bd488e2016-11-04 16:30:1236 * - track causes the new branch to be configured to merge the remote branch
37 * that start_name is a tracking branch for (if any).
Kaartic Sivaraame2bbd0c2017-11-18 17:26:4638 *
Daniel Barkalowc369e7b2008-02-07 16:40:1639 */
Jeff King4bd488e2016-11-04 16:30:1240void create_branch(const char *name, const char *start_name,
Kaartic Sivaraame2bbd0c2017-11-18 17:26:4641 int force, int clobber_head_ok,
42 int reflog, int quiet, enum branch_track track);
Daniel Barkalowe496c002008-02-07 16:40:0843
Daniel Barkalowc369e7b2008-02-07 16:40:1644/*
Junio C Hamanobc1c9c02017-10-13 04:45:4045 * Check if 'name' can be a valid name for a branch; die otherwise.
46 * Return 1 if the named branch already exists; return 0 otherwise.
47 * Fill ref with the full refname for the branch.
Conrad Irwin55c4a672011-08-20 21:49:4848 */
Junio C Hamanobc1c9c02017-10-13 04:45:4049extern int validate_branchname(const char *name, struct strbuf *ref);
50
51/*
52 * Check if a branch 'name' can be created as a new branch; die otherwise.
53 * 'force' can be used when it is OK for the named branch already exists.
54 * Return 1 if the named branch already exists; return 0 otherwise.
55 * Fill ref with the full refname for the branch.
56 */
57extern int validate_new_branchname(const char *name, struct strbuf *ref, int force);
Conrad Irwin55c4a672011-08-20 21:49:4858
59/*
Daniel Barkalowc369e7b2008-02-07 16:40:1660 * Remove information about the state of working on the current
61 * branch. (E.g., MERGE_HEAD)
62 */
63void remove_branch_state(void);
64
Junio C Hamanoa9f2c132009-03-04 06:29:5565/*
Matthieu Moy13931232010-11-02 15:31:2566 * Configure local branch "local" as downstream to branch "remote"
67 * from remote "origin". Used by git branch --set-upstream.
Patrick Steinhardt27852b22016-02-22 11:23:2368 * Returns 0 on success.
Junio C Hamanoa9f2c132009-03-04 06:29:5569 */
70#define BRANCH_CONFIG_VERBOSE 01
Patrick Steinhardt27852b22016-02-22 11:23:2371extern int install_branch_config(int flag, const char *local, const char *origin, const char *remote);
Junio C Hamanoa9f2c132009-03-04 06:29:5572
Junio C Hamano6f9a3322011-09-22 03:19:3873/*
74 * Read branch description
75 */
76extern int read_branch_desc(struct strbuf *, const char *branch_name);
77
Eric Sunshineed89f842015-07-17 23:00:0478/*
79 * Check if a branch is checked out in the main worktree or any linked
80 * worktree and die (with a message describing its checkout location) if
81 * it is.
82 */
Nguyễn Thái Ngọc Duy8d9fdd72016-04-22 13:01:3383extern void die_if_checked_out(const char *branch, int ignore_current_worktree);
Eric Sunshineed89f842015-07-17 23:00:0484
Kazuki Yamaguchi70999e92016-03-27 14:37:1485/*
86 * Update all per-worktree HEADs pointing at the old ref to point the new ref.
87 * This will be used when renaming a branch. Returns 0 if successful, non-zero
88 * otherwise.
89 */
Kyle Meyer39ee4c62017-02-21 01:10:3590extern int replace_each_worktree_head_symref(const char *oldref, const char *newref,
91 const char *logmsg);
Kazuki Yamaguchi70999e92016-03-27 14:37:1492
Daniel Barkalowe496c002008-02-07 16:40:0893#endif