]> git.ipfire.org Git - thirdparty/git.git/commitdiff
worktree: prepare for more checks of whether path can become worktree
authorEric Sunshine <sunshine@sunshineco.com>
Tue, 28 Aug 2018 21:20:21 +0000 (17:20 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Aug 2018 16:28:02 +0000 (09:28 -0700)
Certain conditions must be met for a path to be a valid candidate as the
location of a new worktree; for instance, the path must not exist or
must be an empty directory. Although the number of conditions is small,
new conditions will soon be added so factor out the existing checks into
a separate function to avoid further bloating add_worktree().

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/worktree.c

index 0affcb476c15ff6baf2b4c2b4ca73d7a38fb5175..46c93771e8119336c764b5926df24dc0666fce56 100644 (file)
@@ -219,6 +219,12 @@ static const char *worktree_basename(const char *path, int *olen)
        return name;
 }
 
+static void validate_worktree_add(const char *path, const struct add_opts *opts)
+{
+       if (file_exists(path) && !is_empty_dir(path))
+               die(_("'%s' already exists"), path);
+}
+
 static int add_worktree(const char *path, const char *refname,
                        const struct add_opts *opts)
 {
@@ -233,8 +239,7 @@ static int add_worktree(const char *path, const char *refname,
        struct commit *commit = NULL;
        int is_branch = 0;
 
-       if (file_exists(path) && !is_empty_dir(path))
-               die(_("'%s' already exists"), path);
+       validate_worktree_add(path, opts);
 
        /* is 'refname' a branch or commit? */
        if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&