From 7f0717e845d637f0833edaec01b989891683e719 Mon Sep 17 00:00:00 2001 From: alexiszamanidis Date: Sun, 30 Oct 2022 16:59:24 +0200 Subject: [PATCH] feat(worktrees-dir-path): enhance worktree directory path implementation --- src/helpers/gitWorktreeHelpers.ts | 13 +++++++++++++ src/helpers/helpers.ts | 2 +- yarn.lock | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/helpers/gitWorktreeHelpers.ts b/src/helpers/gitWorktreeHelpers.ts index aea3fea..565f273 100644 --- a/src/helpers/gitWorktreeHelpers.ts +++ b/src/helpers/gitWorktreeHelpers.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import { executeCommand, getCurrentPath, + worktreesDirPath, getWorkspaceFilePath, shouldOpenNewVscodeWindow, } from "./helpers"; @@ -223,6 +224,18 @@ export const removeWorktree = async (worktree: SelectedWorktree) => { export const calculateNewWorktreePath = async (branch: string) => { try { + // If a worktrees path is defined, wee need to move the new worktree there + if (worktreesDirPath) { + const path = `${worktreesDirPath}/${branch}`; + + // check if directory exists + if (fs.existsSync(path)) { + throw new Error(`Directory '${path}' already exists.`); + } + + return path; + } + const getGitCommonDirPathCommand = "git rev-parse --path-format=absolute --git-common-dir"; const { stdout: gitCommonDirPath } = await executeCommand(getGitCommonDirPathCommand); let path = removeNewLine(gitCommonDirPath); diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 9b35a75..3572458 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -90,5 +90,5 @@ export const shouldRemoveStalledBranches = export const shouldOpenNewVscodeWindow = vscode.workspace.getConfiguration().get("vsCodeGitWorktrees.move.openNewVscodeWindow") ?? true; -export const getWorktreesDirPath = +export const worktreesDirPath = vscode.workspace.getConfiguration().get("vsCodeGitWorktrees.worktrees.dir.path") ?? null; diff --git a/yarn.lock b/yarn.lock index a665c6e..bce140b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3056,7 +3056,7 @@ semver-compare@^1.0.0: resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w= -semver-regex@^3.1.4: +semver-regex@^3.1.2: version "3.1.4" resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-3.1.4.tgz#13053c0d4aa11d070a2f2872b6b1e3ae1e1971b4" integrity sha512-6IiqeZNgq01qGf0TId0t3NvKzSvUsjcpdEO3AQNeIjR6A2+ckTnQlDpl4qu1bjRv0RzN3FP9hzFmws3lKqRWkA==