Daniel Barkalow | e496c00 | 2008-02-07 11:40:08 -0500 | [diff] [blame] | 1 | #ifndef BRANCH_H |
| 2 | #define BRANCH_H |
| 3 | |
Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 06:49:00 +0100 | [diff] [blame] | 4 | struct repository; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 5 | struct strbuf; |
| 6 | |
Elijah Newren | e730b81 | 2018-08-15 10:54:07 -0700 | [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, |
| 13 | BRANCH_TRACK_OVERRIDE |
| 14 | }; |
| 15 | |
| 16 | extern enum branch_track git_branch_track; |
| 17 | |
Daniel Barkalow | c369e7b | 2008-02-07 11:40:16 -0500 | [diff] [blame] | 18 | /* Functions for acting on the information about branches. */ |
| 19 | |
| 20 | /* |
Jeff King | 4bd488e | 2016-11-04 12:30:12 -0400 | [diff] [blame] | 21 | * Creates a new branch, where: |
| 22 | * |
Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 06:49:00 +0100 | [diff] [blame] | 23 | * - r is the repository to add a branch to |
| 24 | * |
Jeff King | 4bd488e | 2016-11-04 12:30:12 -0400 | [diff] [blame] | 25 | * - name is the new branch name |
| 26 | * |
| 27 | * - start_name is the name of the existing branch that the new branch should |
| 28 | * start from |
| 29 | * |
| 30 | * - force enables overwriting an existing (non-head) branch |
| 31 | * |
Kaartic Sivaraam | f6cea74 | 2017-11-18 22:56:45 +0530 | [diff] [blame] | 32 | * - clobber_head_ok allows the currently checked out (hence existing) |
| 33 | * branch to be overwritten; without 'force', it has no effect. |
| 34 | * |
Jeff King | 4bd488e | 2016-11-04 12:30:12 -0400 | [diff] [blame] | 35 | * - reflog creates a reflog for the branch |
| 36 | * |
Kaartic Sivaraam | f6cea74 | 2017-11-18 22:56:45 +0530 | [diff] [blame] | 37 | * - quiet suppresses tracking information |
| 38 | * |
Jeff King | 4bd488e | 2016-11-04 12:30:12 -0400 | [diff] [blame] | 39 | * - track causes the new branch to be configured to merge the remote branch |
| 40 | * that start_name is a tracking branch for (if any). |
Kaartic Sivaraam | e2bbd0c | 2017-11-18 22:56:46 +0530 | [diff] [blame] | 41 | * |
Daniel Barkalow | c369e7b | 2008-02-07 11:40:16 -0500 | [diff] [blame] | 42 | */ |
Nguyễn Thái Ngọc Duy | 4edce17 | 2018-11-10 06:49:00 +0100 | [diff] [blame] | 43 | void create_branch(struct repository *r, |
| 44 | const char *name, const char *start_name, |
Kaartic Sivaraam | e2bbd0c | 2017-11-18 22:56:46 +0530 | [diff] [blame] | 45 | int force, int clobber_head_ok, |
| 46 | int reflog, int quiet, enum branch_track track); |
Daniel Barkalow | e496c00 | 2008-02-07 11:40:08 -0500 | [diff] [blame] | 47 | |
Daniel Barkalow | c369e7b | 2008-02-07 11:40:16 -0500 | [diff] [blame] | 48 | /* |
Junio C Hamano | bc1c9c0 | 2017-10-13 13:45:40 +0900 | [diff] [blame] | 49 | * Check if 'name' can be a valid name for a branch; die otherwise. |
| 50 | * Return 1 if the named branch already exists; return 0 otherwise. |
| 51 | * Fill ref with the full refname for the branch. |
Conrad Irwin | 55c4a67 | 2011-08-20 14:49:48 -0700 | [diff] [blame] | 52 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 53 | int validate_branchname(const char *name, struct strbuf *ref); |
Junio C Hamano | bc1c9c0 | 2017-10-13 13:45:40 +0900 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * Check if a branch 'name' can be created as a new branch; die otherwise. |
| 57 | * 'force' can be used when it is OK for the named branch already exists. |
| 58 | * Return 1 if the named branch already exists; return 0 otherwise. |
| 59 | * Fill ref with the full refname for the branch. |
| 60 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 61 | int validate_new_branchname(const char *name, struct strbuf *ref, int force); |
Conrad Irwin | 55c4a67 | 2011-08-20 14:49:48 -0700 | [diff] [blame] | 62 | |
| 63 | /* |
Nguyễn Thái Ngọc Duy | b643355 | 2019-05-09 17:10:27 +0700 | [diff] [blame] | 64 | * Remove information about the merge state on the current |
| 65 | * branch. (E.g., MERGE_HEAD) |
| 66 | */ |
| 67 | void remove_merge_branch_state(struct repository *r); |
| 68 | |
| 69 | /* |
Daniel Barkalow | c369e7b | 2008-02-07 11:40:16 -0500 | [diff] [blame] | 70 | * Remove information about the state of working on the current |
| 71 | * branch. (E.g., MERGE_HEAD) |
| 72 | */ |
Nguyễn Thái Ngọc Duy | f4a4b9a | 2019-03-29 17:38:59 +0700 | [diff] [blame] | 73 | void remove_branch_state(struct repository *r, int verbose); |
Daniel Barkalow | c369e7b | 2008-02-07 11:40:16 -0500 | [diff] [blame] | 74 | |
Junio C Hamano | a9f2c13 | 2009-03-03 22:29:55 -0800 | [diff] [blame] | 75 | /* |
Matthieu Moy | 1393123 | 2010-11-02 16:31:25 +0100 | [diff] [blame] | 76 | * Configure local branch "local" as downstream to branch "remote" |
| 77 | * from remote "origin". Used by git branch --set-upstream. |
Patrick Steinhardt | 27852b2 | 2016-02-22 12:23:23 +0100 | [diff] [blame] | 78 | * Returns 0 on success. |
Junio C Hamano | a9f2c13 | 2009-03-03 22:29:55 -0800 | [diff] [blame] | 79 | */ |
| 80 | #define BRANCH_CONFIG_VERBOSE 01 |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 81 | int install_branch_config(int flag, const char *local, const char *origin, const char *remote); |
Junio C Hamano | a9f2c13 | 2009-03-03 22:29:55 -0800 | [diff] [blame] | 82 | |
Junio C Hamano | 6f9a332 | 2011-09-21 20:19:38 -0700 | [diff] [blame] | 83 | /* |
| 84 | * Read branch description |
| 85 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 86 | int read_branch_desc(struct strbuf *, const char *branch_name); |
Junio C Hamano | 6f9a332 | 2011-09-21 20:19:38 -0700 | [diff] [blame] | 87 | |
Eric Sunshine | ed89f84 | 2015-07-17 19:00:04 -0400 | [diff] [blame] | 88 | /* |
| 89 | * Check if a branch is checked out in the main worktree or any linked |
| 90 | * worktree and die (with a message describing its checkout location) if |
| 91 | * it is. |
| 92 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 93 | void die_if_checked_out(const char *branch, int ignore_current_worktree); |
Eric Sunshine | ed89f84 | 2015-07-17 19:00:04 -0400 | [diff] [blame] | 94 | |
Kazuki Yamaguchi | 70999e9 | 2016-03-27 23:37:14 +0900 | [diff] [blame] | 95 | /* |
| 96 | * Update all per-worktree HEADs pointing at the old ref to point the new ref. |
| 97 | * This will be used when renaming a branch. Returns 0 if successful, non-zero |
| 98 | * otherwise. |
| 99 | */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 100 | int replace_each_worktree_head_symref(const char *oldref, const char *newref, |
Denton Liu | ad6dad0 | 2019-04-29 04:28:23 -0400 | [diff] [blame] | 101 | const char *logmsg); |
Kazuki Yamaguchi | 70999e9 | 2016-03-27 23:37:14 +0900 | [diff] [blame] | 102 | |
Daniel Barkalow | e496c00 | 2008-02-07 11:40:08 -0500 | [diff] [blame] | 103 | #endif |