Skip to content

Commit

Permalink
feat(worktrees-dir-path): enhance worktree directory path implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexiszamanidis committed Oct 30, 2022
1 parent e12cddc commit 7f0717e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/helpers/gitWorktreeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as vscode from "vscode";
import {
executeCommand,
getCurrentPath,
worktreesDirPath,
getWorkspaceFilePath,
shouldOpenNewVscodeWindow,
} from "./helpers";
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 7f0717e

Please sign in to comment.