| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 1 | #ifndef BRANCH_H |
| 2 | #define BRANCH_H |
| 3 | |
| Elijah Newren | ef3ca95 | 2018-08-15 17:54:05 | [diff] [blame] | 4 | struct strbuf; |
| 5 | |
| Elijah Newren | e730b81 | 2018-08-15 17:54:07 | [diff] [blame] | 6 | enum 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 | |
| 15 | extern enum branch_track git_branch_track; |
| 16 | |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 17 | /* Functions for acting on the information about branches. */ |
| 18 | |
| 19 | /* |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 20 | * 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 Sivaraam | f6cea74 | 2017-11-18 17:26:45 | [diff] [blame] | 29 | * - clobber_head_ok allows the currently checked out (hence existing) |
| 30 | * branch to be overwritten; without 'force', it has no effect. |
| 31 | * |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 32 | * - reflog creates a reflog for the branch |
| 33 | * |
| Kaartic Sivaraam | f6cea74 | 2017-11-18 17:26:45 | [diff] [blame] | 34 | * - quiet suppresses tracking information |
| 35 | * |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 36 | * - 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 Sivaraam | e2bbd0c | 2017-11-18 17:26:46 | [diff] [blame] | 38 | * |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 39 | */ |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 40 | void create_branch(const char *name, const char *start_name, |
| Kaartic Sivaraam | e2bbd0c | 2017-11-18 17:26:46 | [diff] [blame] | 41 | int force, int clobber_head_ok, |
| 42 | int reflog, int quiet, enum branch_track track); |
| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 43 | |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 44 | /* |
| Junio C Hamano | bc1c9c0 | 2017-10-13 04:45:40 | [diff] [blame] | 45 | * 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 Irwin | 55c4a67 | 2011-08-20 21:49:48 | [diff] [blame] | 48 | */ |
| Junio C Hamano | bc1c9c0 | 2017-10-13 04:45:40 | [diff] [blame] | 49 | extern 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 | */ |
| 57 | extern int validate_new_branchname(const char *name, struct strbuf *ref, int force); |
| Conrad Irwin | 55c4a67 | 2011-08-20 21:49:48 | [diff] [blame] | 58 | |
| 59 | /* |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 60 | * Remove information about the state of working on the current |
| 61 | * branch. (E.g., MERGE_HEAD) |
| 62 | */ |
| 63 | void remove_branch_state(void); |
| 64 | |
| Junio C Hamano | a9f2c13 | 2009-03-04 06:29:55 | [diff] [blame] | 65 | /* |
| Matthieu Moy | 1393123 | 2010-11-02 15:31:25 | [diff] [blame] | 66 | * Configure local branch "local" as downstream to branch "remote" |
| 67 | * from remote "origin". Used by git branch --set-upstream. |
| Patrick Steinhardt | 27852b2 | 2016-02-22 11:23:23 | [diff] [blame] | 68 | * Returns 0 on success. |
| Junio C Hamano | a9f2c13 | 2009-03-04 06:29:55 | [diff] [blame] | 69 | */ |
| 70 | #define BRANCH_CONFIG_VERBOSE 01 |
| Patrick Steinhardt | 27852b2 | 2016-02-22 11:23:23 | [diff] [blame] | 71 | extern int install_branch_config(int flag, const char *local, const char *origin, const char *remote); |
| Junio C Hamano | a9f2c13 | 2009-03-04 06:29:55 | [diff] [blame] | 72 | |
| Junio C Hamano | 6f9a332 | 2011-09-22 03:19:38 | [diff] [blame] | 73 | /* |
| 74 | * Read branch description |
| 75 | */ |
| 76 | extern int read_branch_desc(struct strbuf *, const char *branch_name); |
| 77 | |
| Eric Sunshine | ed89f84 | 2015-07-17 23:00:04 | [diff] [blame] | 78 | /* |
| 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 Duy | 8d9fdd7 | 2016-04-22 13:01:33 | [diff] [blame] | 83 | extern void die_if_checked_out(const char *branch, int ignore_current_worktree); |
| Eric Sunshine | ed89f84 | 2015-07-17 23:00:04 | [diff] [blame] | 84 | |
| Kazuki Yamaguchi | 70999e9 | 2016-03-27 14:37:14 | [diff] [blame] | 85 | /* |
| 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 Meyer | 39ee4c6 | 2017-02-21 01:10:35 | [diff] [blame] | 90 | extern int replace_each_worktree_head_symref(const char *oldref, const char *newref, |
| 91 | const char *logmsg); |
| Kazuki Yamaguchi | 70999e9 | 2016-03-27 14:37:14 | [diff] [blame] | 92 | |
| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 93 | #endif |