worktree.c: add validate_worktree()

This function is later used by "worktree move" and "worktree remove"
to ensure that we have a good connection between the repository and
the worktree. For example, if a worktree is moved manually, the
worktree location recorded in $GIT_DIR/worktrees/.../gitdir is
incorrect and we should not move that one.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2018-01-24 16:53:51 +07:00
committed by Junio C Hamano
parent 8279ed033f
commit 4ddddc1f1d
2 changed files with 81 additions and 0 deletions

View File

@@ -3,6 +3,8 @@
#include "refs.h"
struct strbuf;
struct worktree {
char *path;
char *id;
@@ -59,6 +61,13 @@ extern int is_main_worktree(const struct worktree *wt);
*/
extern const char *is_worktree_locked(struct worktree *wt);
/*
* Return zero if the worktree is in good condition. Error message is
* returned if "errmsg" is not NULL.
*/
extern int validate_worktree(const struct worktree *wt,
struct strbuf *errmsg);
/*
* Free up the memory for worktree(s)
*/