worktree.c: add is_main_worktree()
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 3 Jun 2016 12:19:40 +0000 (19:19 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 4 Jun 2016 04:58:35 +0000 (21:58 -0700)
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>
worktree.c
worktree.h
index 0782e00983d5a0dbcbeefa222d21352aa54dc7cc..12a766a38d301e2ab7d6cfc3efadf83d5b8c8953 100644 (file)
@@ -229,6 +229,11 @@ struct worktree *find_worktree(struct worktree **list,
        return *list;
 }
 
+int is_main_worktree(const struct worktree *wt)
+{
+       return !wt->id;
+}
+
 int is_worktree_being_rebased(const struct worktree *wt,
                              const char *target)
 {
index 7ad15da0dcbab77d3baa110cd95a6d23c2ee334a..e1c4715238488c46599c3f3b940a9bbc2ecbecde 100644 (file)
@@ -37,6 +37,11 @@ extern struct worktree *find_worktree(struct worktree **list,
                                      const char *prefix,
                                      const char *arg);
 
+/*
+ * Return true if the given worktree is the main one.
+ */
+extern int is_main_worktree(const struct worktree *wt);
+
 /*
  * Free up the memory for worktree(s)
  */