worktree-add 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,7 +9,7 @@ Running `worktree-add <branch>` from inside a repo:
9
9
  1. Normalizes `<branch>` (supports `origin/foo`, `refs/heads/foo`, etc.).
10
10
  2. Refuses if that branch is already checked out in any worktree.
11
11
  3. Picks a destination next to your current repo: `../<repo>-<safe-branch>`.
12
- 4. If the destination exists, asks before removing it with `rm -rf`.
12
+ 4. If the destination exists, asks before moving it to the system trash.
13
13
  5. Fetches `origin/<branch>` when needed and creates a git worktree:
14
14
  - reuses an existing local branch
15
15
  - or creates a tracking branch from `origin/<branch>`
@@ -27,7 +27,6 @@ Your original checkout is left untouched.
27
27
 
28
28
  - Node.js ≥ 22.14.0
29
29
  - Git with `git worktree` support
30
- - POSIX‑like shell (uses `rm -rf` for cleaning the destination)
31
30
 
32
31
  ## Install / run
33
32
 
@@ -3,7 +3,19 @@
3
3
  *
4
4
  * Utilities for managing worktree directories
5
5
  */
6
- import { spawnSync } from "node:child_process";
6
+ /**
7
+ * Cross-platform trash functionality using the trash package.
8
+ *
9
+ * Platform-specific behavior:
10
+ * - macOS: Uses Finder's trash (~/.Trash)
11
+ * - Windows: Uses Recycle Bin
12
+ * - Linux: Uses freedesktop.org trash specification (~/.local/share/Trash)
13
+ *
14
+ * Note: On headless/CI systems, the trash directory is still created but
15
+ * may not be visible in a GUI. Files can be recovered by navigating to
16
+ * the platform-specific trash location.
17
+ */
18
+ import trash from "trash";
7
19
  import path from "node:path";
8
20
  import { fileExists, confirm, exitWithMessage } from "../git/git.js";
9
21
  /**
@@ -14,20 +26,20 @@ export async function handleExistingDirectory(destinationDirectory) {
14
26
  if (!(await fileExists(destinationDirectory))) {
15
27
  return;
16
28
  }
17
- const proceed = await confirm(`Directory '${path.basename(destinationDirectory)}' already exists. Remove and recreate?`);
29
+ const proceed = await confirm(`Directory '${path.basename(destinationDirectory)}' already exists. Move to trash and recreate? (You can restore it from your system trash if needed)`);
18
30
  if (!proceed) {
19
31
  console.log("Operation cancelled.");
20
32
  // eslint-disable-next-line unicorn/no-process-exit -- User requested cancellation
21
33
  process.exit(0);
22
34
  }
23
- // Remove the existing directory
24
- console.log(`➤ Removing existing directory...`);
25
- const result = spawnSync("rm", ["-rf", destinationDirectory], {
26
- encoding: "utf8",
27
- });
28
- if (result.error)
29
- throw result.error;
30
- if (result.status !== 0) {
31
- exitWithMessage(`Failed to remove existing directory: ${result.stderr}`);
35
+ // Move the existing directory to trash
36
+ console.log(`➤ Moving existing directory to trash...`);
37
+ try {
38
+ await trash(destinationDirectory);
39
+ console.log("✓ Directory moved to trash successfully");
40
+ }
41
+ catch (error) {
42
+ console.error("Error details:", error);
43
+ exitWithMessage(`Failed to move existing directory to trash: ${error instanceof Error ? error.message : String(error)}`);
32
44
  }
33
45
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "worktree-add",
3
3
  "author": "Łukasz Jerciński",
4
4
  "license": "MIT",
5
- "version": "1.1.1",
5
+ "version": "1.2.0",
6
6
  "description": "Create a Git worktree next to your current repo for a branch, copy useful local files, install deps, and open it in your editor.",
7
7
  "repository": {
8
8
  "type": "git",
@@ -53,7 +53,8 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "commander": "^14.0.2",
56
- "package-manager-detector": "^1.5.0"
56
+ "package-manager-detector": "^1.5.0",
57
+ "trash": "^10.0.0"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@commitlint/cli": "^20.1.0",