summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2018-08-28 21:20:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-30 16:28:02 (GMT)
commit45059e6468ab5710748c8827d5bf1f4c7c69d6d1 (patch)
treeaef9bf3305497bbe1f730bc42c0a4db86684b0f7 /builtin
parent602aaed03f7f82323d88703d6fa2263a13c37907 (diff)
downloadgit-45059e6468ab5710748c8827d5bf1f4c7c69d6d1.zip
git-45059e6468ab5710748c8827d5bf1f4c7c69d6d1.tar.gz
git-45059e6468ab5710748c8827d5bf1f4c7c69d6d1.tar.bz2
worktree: prepare for more checks of whether path can become worktree
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/worktree.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 0affcb4..46c9377 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -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) &&