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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 3, 2016 at 19:19 UTC 984ad9e56c9d884f7f1aa7d6b2052f3fb082ee5d
2 files changed +10
worktree.c
+5
@@ -229,6 +229,11 @@ struct worktree *find_worktree(struct worktree **list,
229 return *list;
230 }
231
232 +int is_main_worktree(const struct worktree *wt)
233 +{
234 + return !wt->id;
235 +}
236 +
237 int is_worktree_being_rebased(const struct worktree *wt,
238 const char *target)
239 {
worktree.h
+5
@@ -37,6 +37,11 @@ extern struct worktree *find_worktree(struct worktree **list,
37 const char *prefix,
38 const char *arg);
39
40 +/*
41 + * Return true if the given worktree is the main one.
42 + */
43 +extern int is_main_worktree(const struct worktree *wt);
44 +
45 /*
46 * Free up the memory for worktree(s)
47 */