Skip to content

Commit 984ad9e

Browse files
pcloudsgitster
authored andcommitted
worktree.c: add is_main_worktree()
Main worktree _is_ different. You can lock (*) a linked worktree but not the main one, for example. Provide an API for checking that. (*) Add the file $GIT_DIR/worktrees/xxx/locked to avoid worktree xxx from being removed or moved. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6835314 commit 984ad9e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

worktree.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ struct worktree *find_worktree(struct worktree **list,
229229
return *list;
230230
}
231231

232+
int is_main_worktree(const struct worktree *wt)
233+
{
234+
return !wt->id;
235+
}
236+
232237
int is_worktree_being_rebased(const struct worktree *wt,
233238
const char *target)
234239
{

worktree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ extern struct worktree *find_worktree(struct worktree **list,
3737
const char *prefix,
3838
const char *arg);
3939

40+
/*
41+
* Return true if the given worktree is the main one.
42+
*/
43+
extern int is_main_worktree(const struct worktree *wt);
44+
4045
/*
4146
* Free up the memory for worktree(s)
4247
*/

0 commit comments

Comments
 (0)