@damper/cli 0.2.1 → 0.2.3
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 +1 -1
- package/dist/services/worktree.js +67 -5
- package/package.json +1 -1
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.
|
|
7
|
+
const VERSION = '0.2.3';
|
|
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
|
*/
|
|
@@ -141,15 +156,62 @@ export async function createWorktree(options) {
|
|
|
141
156
|
};
|
|
142
157
|
}
|
|
143
158
|
const projectName = getProjectName(projectRoot);
|
|
159
|
+
const shortTaskId = taskId.slice(0, 8);
|
|
144
160
|
const slug = slugify(taskTitle);
|
|
145
|
-
|
|
161
|
+
// Use short task ID for directory (keeps paths short), full slug for branch (more descriptive)
|
|
162
|
+
const worktreePath = path.resolve(projectRoot, '..', `${projectName}-${shortTaskId}`);
|
|
146
163
|
const branchName = `feature/${slug}`;
|
|
164
|
+
// Check if worktree directory already exists
|
|
165
|
+
if (fs.existsSync(worktreePath)) {
|
|
166
|
+
console.log(pc.dim(`Worktree directory already exists at ${worktreePath}`));
|
|
167
|
+
// Check if it's a valid worktree and has the expected branch
|
|
168
|
+
try {
|
|
169
|
+
const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
|
170
|
+
cwd: worktreePath,
|
|
171
|
+
stdio: 'pipe',
|
|
172
|
+
});
|
|
173
|
+
const currentBranch = stdout.trim();
|
|
174
|
+
console.log(pc.dim(`Using existing worktree on branch ${currentBranch}`));
|
|
175
|
+
// Save to state if not tracked
|
|
176
|
+
const worktreeState = {
|
|
177
|
+
taskId,
|
|
178
|
+
path: worktreePath,
|
|
179
|
+
branch: currentBranch,
|
|
180
|
+
projectRoot,
|
|
181
|
+
createdAt: new Date().toISOString(),
|
|
182
|
+
};
|
|
183
|
+
addWorktree(worktreeState);
|
|
184
|
+
return {
|
|
185
|
+
path: worktreePath,
|
|
186
|
+
branch: currentBranch,
|
|
187
|
+
isNew: false,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
// Not a valid git worktree, remove it
|
|
192
|
+
console.log(pc.dim(`Removing invalid directory at ${worktreePath}...`));
|
|
193
|
+
fs.rmSync(worktreePath, { recursive: true });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Check if branch already exists
|
|
197
|
+
const branchAlreadyExists = await branchExists(branchName, projectRoot);
|
|
147
198
|
// Create worktree
|
|
148
199
|
console.log(pc.dim(`Creating worktree at ${worktreePath}...`));
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
200
|
+
if (branchAlreadyExists) {
|
|
201
|
+
// Use existing branch
|
|
202
|
+
console.log(pc.dim(`Using existing branch ${branchName}`));
|
|
203
|
+
await execa('git', ['worktree', 'add', worktreePath, branchName], {
|
|
204
|
+
cwd: projectRoot,
|
|
205
|
+
stdio: 'pipe',
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
// Create new branch
|
|
210
|
+
await execa('git', ['worktree', 'add', worktreePath, '-b', branchName], {
|
|
211
|
+
cwd: projectRoot,
|
|
212
|
+
stdio: 'pipe',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
153
215
|
// Symlink node_modules
|
|
154
216
|
const nodeModulesDirs = findNodeModulesDirs(projectRoot);
|
|
155
217
|
for (const dir of nodeModulesDirs) {
|