| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 1 | #ifndef BRANCH_H |
| 2 | #define BRANCH_H |
| 3 | |
| Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 05:49:00 | [diff] [blame] | 4 | struct repository; |
| Elijah Newren | ef3ca95 | 2018-08-15 17:54:05 | [diff] [blame] | 5 | struct strbuf; |
| 6 | |
| Elijah Newren | e730b81 | 2018-08-15 17:54:07 | [diff] [blame] | 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, |
| Josh Steadmon | d311566 | 2021-12-21 03:30:23 | [diff] [blame] | 13 | BRANCH_TRACK_OVERRIDE, |
| 14 | BRANCH_TRACK_INHERIT, |
| Elijah Newren | e730b81 | 2018-08-15 17:54:07 | [diff] [blame] | 15 | }; |
| 16 | |
| 17 | extern enum branch_track git_branch_track; |
| 18 | |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 19 | /* Functions for acting on the information about branches. */ |
| 20 | |
| 21 | /* |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 22 | * Creates a new branch, where: |
| 23 | * |
| Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 05:49:00 | [diff] [blame] | 24 | * - r is the repository to add a branch to |
| 25 | * |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 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 | * |
| Kaartic Sivaraam | f6cea74 | 2017-11-18 17:26:45 | [diff] [blame] | 33 | * - clobber_head_ok allows the currently checked out (hence existing) |
| 34 | * branch to be overwritten; without 'force', it has no effect. |
| 35 | * |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 36 | * - reflog creates a reflog for the branch |
| 37 | * |
| Kaartic Sivaraam | f6cea74 | 2017-11-18 17:26:45 | [diff] [blame] | 38 | * - quiet suppresses tracking information |
| 39 | * |
| Jeff King | 4bd488e | 2016-11-04 16:30:12 | [diff] [blame] | 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). |
| Kaartic Sivaraam | e2bbd0c | 2017-11-18 17:26:46 | [diff] [blame] | 42 | * |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 43 | */ |
| Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 05:49:00 | [diff] [blame] | 44 | void create_branch(struct repository *r, |
| 45 | const char *name, const char *start_name, |
| Kaartic Sivaraam | e2bbd0c | 2017-11-18 17:26:46 | [diff] [blame] | 46 | int force, int clobber_head_ok, |
| 47 | int reflog, int quiet, enum branch_track track); |
| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 48 | |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 49 | /* |
| Junio C Hamano | bc1c9c0 | 2017-10-13 04:45:40 | [diff] [blame] | 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. |
| Conrad Irwin | 55c4a67 | 2011-08-20 21:49:48 | [diff] [blame] | 53 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 54 | int validate_branchname(const char *name, struct strbuf *ref); |
| Junio C Hamano | bc1c9c0 | 2017-10-13 04:45:40 | [diff] [blame] | 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 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 62 | int validate_new_branchname(const char *name, struct strbuf *ref, int force); |
| Conrad Irwin | 55c4a67 | 2011-08-20 21:49:48 | [diff] [blame] | 63 | |
| 64 | /* |
| Nguyễn Thái Ngọc Duy | b643355 | 2019-05-09 10:10:27 | [diff] [blame] | 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 | /* |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 71 | * Remove information about the state of working on the current |
| 72 | * branch. (E.g., MERGE_HEAD) |
| 73 | */ |
| Nguyễn Thái Ngọc Duy | f4a4b9a | 2019-03-29 10:38:59 | [diff] [blame] | 74 | void remove_branch_state(struct repository *r, int verbose); |
| Daniel Barkalow | c369e7b | 2008-02-07 16:40:16 | [diff] [blame] | 75 | |
| Junio C Hamano | a9f2c13 | 2009-03-04 06:29:55 | [diff] [blame] | 76 | /* |
| Matthieu Moy | 1393123 | 2010-11-02 15:31:25 | [diff] [blame] | 77 | * Configure local branch "local" as downstream to branch "remote" |
| 78 | * from remote "origin". Used by git branch --set-upstream. |
| Patrick Steinhardt | 27852b2 | 2016-02-22 11:23:23 | [diff] [blame] | 79 | * Returns 0 on success. |
| Junio C Hamano | a9f2c13 | 2009-03-04 06:29:55 | [diff] [blame] | 80 | */ |
| 81 | #define BRANCH_CONFIG_VERBOSE 01 |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 82 | 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] | 83 | |
| Junio C Hamano | 6f9a332 | 2011-09-22 03:19:38 | [diff] [blame] | 84 | /* |
| 85 | * Read branch description |
| 86 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 87 | int read_branch_desc(struct strbuf *, const char *branch_name); |
| Junio C Hamano | 6f9a332 | 2011-09-22 03:19:38 | [diff] [blame] | 88 | |
| Eric Sunshine | ed89f84 | 2015-07-17 23:00:04 | [diff] [blame] | 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 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 94 | void die_if_checked_out(const char *branch, int ignore_current_worktree); |
| Eric Sunshine | ed89f84 | 2015-07-17 23:00:04 | [diff] [blame] | 95 | |
| Kazuki Yamaguchi | 70999e9 | 2016-03-27 14:37:14 | [diff] [blame] | 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 | */ |
| Denton Liu | 5545442 | 2019-04-29 08:28:14 | [diff] [blame] | 101 | int replace_each_worktree_head_symref(const char *oldref, const char *newref, |
| Denton Liu | ad6dad0 | 2019-04-29 08:28:23 | [diff] [blame] | 102 | const char *logmsg); |
| Kazuki Yamaguchi | 70999e9 | 2016-03-27 14:37:14 | [diff] [blame] | 103 | |
| Daniel Barkalow | e496c00 | 2008-02-07 16:40:08 | [diff] [blame] | 104 | #endif |