Merge branch 'tb/config-default'
[gitweb.git] / worktree.c
index 0373faf0dc805b78581a92c46149a5bea5567dfe..97cda5f97bbc10b2f5690b945ab42d2beef74e2e 100644 (file)
@@ -267,7 +267,8 @@ static void strbuf_addf_gently(struct strbuf *buf, const char *fmt, ...)
        va_end(params);
 }
 
-int validate_worktree(const struct worktree *wt, struct strbuf *errmsg)
+int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
+                     unsigned flags)
 {
        struct strbuf wt_path = STRBUF_INIT;
        char *path = NULL;
@@ -303,6 +304,12 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg)
                goto done;
        }
 
+       if (flags & WT_VALIDATE_WORKTREE_MISSING_OK &&
+           !file_exists(wt->path)) {
+               ret = 0;
+               goto done;
+       }
+
        if (!file_exists(wt_path.buf)) {
                strbuf_addf_gently(errmsg, _("'%s' does not exist"), wt_path.buf);
                goto done;
@@ -331,7 +338,7 @@ void update_worktree_location(struct worktree *wt, const char *path_)
        struct strbuf path = STRBUF_INIT;
 
        if (is_main_worktree(wt))
-               die("BUG: can't relocate main worktree");
+               BUG("can't relocate main worktree");
 
        strbuf_realpath(&path, path_, 1);
        if (fspathcmp(wt->path, path.buf)) {