@damper/cli 0.2.1 → 0.2.2

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/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { startCommand } from './commands/start.js';
4
4
  import { statusCommand } from './commands/status.js';
5
5
  import { cleanupCommand } from './commands/cleanup.js';
6
6
  import { setupCommand } from './commands/setup.js';
7
- const VERSION = '0.2.1';
7
+ const VERSION = '0.2.2';
8
8
  function showHelp() {
9
9
  console.log(`
10
10
  ${pc.bold('@damper/cli')} - Agent orchestration for Damper tasks
@@ -126,6 +126,21 @@ function findEnvFiles(projectRoot) {
126
126
  }
127
127
  return envFiles;
128
128
  }
129
+ /**
130
+ * Check if a git branch exists
131
+ */
132
+ async function branchExists(branchName, projectRoot) {
133
+ try {
134
+ await execa('git', ['rev-parse', '--verify', branchName], {
135
+ cwd: projectRoot,
136
+ stdio: 'pipe',
137
+ });
138
+ return true;
139
+ }
140
+ catch {
141
+ return false;
142
+ }
143
+ }
129
144
  /**
130
145
  * Create a new git worktree for a task
131
146
  */
@@ -144,12 +159,57 @@ export async function createWorktree(options) {
144
159
  const slug = slugify(taskTitle);
145
160
  const worktreePath = path.resolve(projectRoot, '..', `${projectName}-${slug}`);
146
161
  const branchName = `feature/${slug}`;
162
+ // Check if worktree directory already exists
163
+ if (fs.existsSync(worktreePath)) {
164
+ console.log(pc.dim(`Worktree directory already exists at ${worktreePath}`));
165
+ // Check if it's a valid worktree and has the expected branch
166
+ try {
167
+ const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
168
+ cwd: worktreePath,
169
+ stdio: 'pipe',
170
+ });
171
+ const currentBranch = stdout.trim();
172
+ console.log(pc.dim(`Using existing worktree on branch ${currentBranch}`));
173
+ // Save to state if not tracked
174
+ const worktreeState = {
175
+ taskId,
176
+ path: worktreePath,
177
+ branch: currentBranch,
178
+ projectRoot,
179
+ createdAt: new Date().toISOString(),
180
+ };
181
+ addWorktree(worktreeState);
182
+ return {
183
+ path: worktreePath,
184
+ branch: currentBranch,
185
+ isNew: false,
186
+ };
187
+ }
188
+ catch {
189
+ // Not a valid git worktree, remove it
190
+ console.log(pc.dim(`Removing invalid directory at ${worktreePath}...`));
191
+ fs.rmSync(worktreePath, { recursive: true });
192
+ }
193
+ }
194
+ // Check if branch already exists
195
+ const branchAlreadyExists = await branchExists(branchName, projectRoot);
147
196
  // Create worktree
148
197
  console.log(pc.dim(`Creating worktree at ${worktreePath}...`));
149
- await execa('git', ['worktree', 'add', worktreePath, '-b', branchName], {
150
- cwd: projectRoot,
151
- stdio: 'pipe',
152
- });
198
+ if (branchAlreadyExists) {
199
+ // Use existing branch
200
+ console.log(pc.dim(`Using existing branch ${branchName}`));
201
+ await execa('git', ['worktree', 'add', worktreePath, branchName], {
202
+ cwd: projectRoot,
203
+ stdio: 'pipe',
204
+ });
205
+ }
206
+ else {
207
+ // Create new branch
208
+ await execa('git', ['worktree', 'add', worktreePath, '-b', branchName], {
209
+ cwd: projectRoot,
210
+ stdio: 'pipe',
211
+ });
212
+ }
153
213
  // Symlink node_modules
154
214
  const nodeModulesDirs = findNodeModulesDirs(projectRoot);
155
215
  for (const dir of nodeModulesDirs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damper/cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "CLI tool for orchestrating Damper task workflows with Claude Code",
5
5
  "author": "Damper <hello@usedamper.com>",
6
6
  "repository": {