11 char *head_ref
; /* NULL if HEAD is broken or detached */
12 char *lock_reason
; /* private - use worktree_lock_reason */
13 char *prune_reason
; /* private - use worktree_prune_reason */
14 struct object_id head_oid
;
18 int lock_reason_valid
; /* private */
19 int prune_reason_valid
; /* private */
23 * Get the worktrees. The primary worktree will always be the first returned,
24 * and linked worktrees will follow in no particular order.
26 * The caller is responsible for freeing the memory from the returned
27 * worktrees by calling free_worktrees().
29 struct worktree
**get_worktrees(void);
32 * Returns 1 if linked worktrees exist, 0 otherwise.
34 int submodule_uses_worktrees(const char *path
);
37 * Return git dir of the worktree. Note that the path may be relative.
38 * If wt is NULL, git dir of current worktree is returned.
40 const char *get_worktree_git_dir(const struct worktree
*wt
);
43 * Search for the worktree identified unambiguously by `arg` -- typically
44 * supplied by the user via the command-line -- which may be a pathname or some
45 * shorthand uniquely identifying a worktree, thus making it convenient for the
46 * user to specify a worktree with minimal typing. For instance, if the last
47 * component (say, "foo") of a worktree's pathname is unique among worktrees
48 * (say, "work/foo" and "work/bar"), it can be used to identify the worktree
51 * `prefix` should be the `prefix` handed to top-level Git commands along with
54 * Return the worktree identified by `arg`, or NULL if not found.
56 struct worktree
*find_worktree(struct worktree
**list
,
61 * Return the worktree corresponding to `path`, or NULL if no such worktree
64 struct worktree
*find_worktree_by_path(struct worktree
**, const char *path
);
67 * Return true if the given worktree is the main one.
69 int is_main_worktree(const struct worktree
*wt
);
72 * Return the reason string if the given worktree is locked or NULL
75 const char *worktree_lock_reason(struct worktree
*wt
);
78 * Return the reason string if the given worktree should be pruned, otherwise
79 * NULL if it should not be pruned. `expire` defines a grace period to prune
80 * the worktree when its path does not exist.
82 const char *worktree_prune_reason(struct worktree
*wt
, timestamp_t expire
);
85 * Return true if worktree entry should be pruned, along with the reason for
86 * pruning. Otherwise, return false and the worktree's path in `wtpath`, or
87 * NULL if it cannot be determined. Caller is responsible for freeing
90 * `expire` defines a grace period to prune the worktree when its path
93 int should_prune_worktree(const char *id
,
94 struct strbuf
*reason
,
98 #define WT_VALIDATE_WORKTREE_MISSING_OK (1 << 0)
101 * Return zero if the worktree is in good condition. Error message is
102 * returned if "errmsg" is not NULL.
104 int validate_worktree(const struct worktree
*wt
,
105 struct strbuf
*errmsg
,
109 * Update worktrees/xxx/gitdir with the new path.
111 void update_worktree_location(struct worktree
*wt
,
114 typedef void (* worktree_repair_fn
)(int iserr
, const char *path
,
115 const char *msg
, void *cb_data
);
118 * Visit each registered linked worktree and repair corruptions. For each
119 * repair made or error encountered while attempting a repair, the callback
120 * function, if non-NULL, is called with the path of the worktree and a
121 * description of the repair or error, along with the callback user-data.
123 void repair_worktrees(worktree_repair_fn
, void *cb_data
);
126 * Repair administrative files corresponding to the worktree at the given path.
127 * The worktree's .git file pointing at the repository must be intact for the
128 * repair to succeed. Useful for re-associating an orphaned worktree with the
129 * repository if the worktree has been moved manually (without using "git
130 * worktree move"). For each repair made or error encountered while attempting
131 * a repair, the callback function, if non-NULL, is called with the path of the
132 * worktree and a description of the repair or error, along with the callback
135 void repair_worktree_at_path(const char *, worktree_repair_fn
, void *cb_data
);
138 * Free up the memory for worktree(s)
140 void free_worktrees(struct worktree
**);
143 * Check if a per-worktree symref points to a ref in the main worktree
144 * or any linked worktree, and return the worktree that holds the ref,
147 const struct worktree
*find_shared_symref(struct worktree
**worktrees
,
152 * Similar to head_ref() for all HEADs _except_ one from the current
153 * worktree, which is covered by head_ref().
155 int other_head_refs(each_ref_fn fn
, void *cb_data
);
157 int is_worktree_being_rebased(const struct worktree
*wt
, const char *target
);
158 int is_worktree_being_bisected(const struct worktree
*wt
, const char *target
);
161 * Similar to git_path() but can produce paths for a specified
162 * worktree instead of current one
164 const char *worktree_git_path(const struct worktree
*wt
,
165 const char *fmt
, ...)
166 __attribute__((format (printf
, 2, 3)));
169 * Return a refname suitable for access from the current ref store.
171 void strbuf_worktree_ref(const struct worktree
*wt
,
173 const char *refname
);
176 * Enable worktree config for the first time. This will make the following
179 * 1. Add extensions.worktreeConfig=true in the common config file.
181 * 2. If the common config file has a core.worktree value, then that value
182 * is moved to the main worktree's config.worktree file.
184 * 3. If the common config file has a core.bare enabled, then that value
185 * is moved to the main worktree's config.worktree file.
187 * If extensions.worktreeConfig is already true, then this method
188 * terminates early without any of the above steps. The existing config
189 * arrangement is assumed to be intentional.
191 * Returns 0 on success. Reports an error message and returns non-zero
192 * if any of these steps fail.
194 int init_worktree_config(struct repository
*r
);