From 14c95f270460927e24fe16c97c5450edab432e55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Mon, 24 Jan 2022 17:03:37 +0100 Subject: [PATCH] Fix worktree creation handling --- src/lib.rs | 11 ++++++----- src/repo.rs | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3bc321b..0facb54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -474,15 +474,16 @@ pub fn add_worktree( let config = repo::read_worktree_root_config(directory)?; - let path = match subdirectory { - Some(dir) => dir.join(name), - None => Path::new(name).to_path_buf(), - }; - if repo.find_worktree(&path).is_ok() { + if repo.find_worktree(&name).is_ok() { return Err(format!("Worktree {} already exists", &name)); } + let path = match subdirectory { + Some(dir) => directory.join(dir).join(name), + None => directory.join(Path::new(name).to_path_buf()), + }; + let mut remote_branch_exists = false; let default_checkout = || repo.default_branch()?.to_commit(); diff --git a/src/repo.rs b/src/repo.rs index a680014..33a0899 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -672,9 +672,9 @@ impl Repo { self.0.config().map_err(convert_libgit2_error) } - pub fn find_worktree(&self, path: &Path) -> Result<(), String> { + pub fn find_worktree(&self, name: &str) -> Result<(), String> { self.0 - .find_worktree(path.to_str().expect("Worktree path is not valid utf-8")) + .find_worktree(&name) .map_err(convert_libgit2_error)?; Ok(()) }