Compare commits
No commits in common. "1549ddc4e6ba61ff1e0a45c3ae2c2213c604c9d9" and "e8318f68b0a9185f73df034f737c4d7bac98b008" have entirely different histories.
1549ddc4e6
...
e8318f68b0
|
|
@ -97,10 +97,8 @@ export async function action(
|
||||||
}
|
}
|
||||||
|
|
||||||
const spin = spinner("Creating worktree", branch)
|
const spin = spinner("Creating worktree", branch)
|
||||||
let branchCreated = false
|
|
||||||
try {
|
try {
|
||||||
const wt = await git.createWorktree(branch, worktreeAbs, root)
|
await git.createWorktree(branch, worktreeAbs, root)
|
||||||
branchCreated = wt.branchCreated
|
|
||||||
const symlinkPath = join(root, '.sandlot', branch)
|
const symlinkPath = join(root, '.sandlot', branch)
|
||||||
await mkdir(dirname(symlinkPath), { recursive: true })
|
await mkdir(dirname(symlinkPath), { recursive: true })
|
||||||
await symlink(worktreeAbs, symlinkPath)
|
await symlink(worktreeAbs, symlinkPath)
|
||||||
|
|
@ -111,7 +109,7 @@ export async function action(
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
spin.fail(String((err as Error).message ?? err))
|
spin.fail(String((err as Error).message ?? err))
|
||||||
await git.removeWorktree(worktreeAbs, root).catch(() => {})
|
await git.removeWorktree(worktreeAbs, root).catch(() => {})
|
||||||
if (branchCreated) await git.deleteLocalBranch(branch, root).catch(() => {})
|
await git.deleteLocalBranch(branch, root).catch(() => {})
|
||||||
await unlinkSessionSymlink(root, branch)
|
await unlinkSessionSymlink(root, branch)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,13 @@ export async function action(branch: string, extra: string | undefined, opts: {
|
||||||
let prompt = `
|
let prompt = `
|
||||||
You're a grumpy old senior software engineer. You need to review some code my co-worker wrote.
|
You're a grumpy old senior software engineer. You need to review some code my co-worker wrote.
|
||||||
|
|
||||||
Launch four agents to review the changes between this branch and main with the following specializations:
|
Launch three code review agents to review the changes between this branch and main with the following specializations:
|
||||||
|
|
||||||
1. Checks CLAUDE.md compliance
|
1. Checks CLAUDE.md compliance
|
||||||
2. Looks specifically for bugs
|
2. Looks specifically for bugs
|
||||||
3. Also looks specifically for bugs
|
3. Looks for opportunities to simplify code
|
||||||
4. Looks for opportunities to simplify code
|
|
||||||
|
|
||||||
Each one should deliver you a report in this format (the <tags> are just for you, not part of their output):
|
Then look at all their suggestions and let me know what you think.
|
||||||
|
|
||||||
<agentOutput>
|
|
||||||
# Problem Identified
|
|
||||||
|
|
||||||
Description of problem.
|
|
||||||
</agentOutput>
|
|
||||||
|
|
||||||
Once the agents are done, look at all their suggestions and let me know what you think.
|
|
||||||
`
|
`
|
||||||
if (extra) prompt += "\n\n" + extra
|
if (extra) prompt += "\n\n" + extra
|
||||||
|
|
||||||
|
|
|
||||||
24
src/git.ts
24
src/git.ts
|
|
@ -36,7 +36,7 @@ export async function branchExists(branch: string, cwd?: string, opts?: { fetch?
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a worktree for the given branch. */
|
/** Create a worktree for the given branch. */
|
||||||
export async function createWorktree(branch: string, worktreePath: string, cwd: string): Promise<{ branchCreated: boolean }> {
|
export async function createWorktree(branch: string, worktreePath: string, cwd: string): Promise<void> {
|
||||||
// Clean up stale worktree path if it exists
|
// Clean up stale worktree path if it exists
|
||||||
if (existsSync(worktreePath)) {
|
if (existsSync(worktreePath)) {
|
||||||
await $`git worktree remove ${worktreePath} --force`.cwd(cwd).nothrow().quiet()
|
await $`git worktree remove ${worktreePath} --force`.cwd(cwd).nothrow().quiet()
|
||||||
|
|
@ -49,20 +49,7 @@ export async function createWorktree(branch: string, worktreePath: string, cwd:
|
||||||
const exists = await branchExists(branch, cwd, { fetch: true })
|
const exists = await branchExists(branch, cwd, { fetch: true })
|
||||||
|
|
||||||
let result
|
let result
|
||||||
let switchedFromBranch = false
|
|
||||||
if (exists === "local") {
|
if (exists === "local") {
|
||||||
const main = await mainBranch(cwd)
|
|
||||||
if (branch === main) {
|
|
||||||
throw new Error(`Cannot create a worktree for the main branch "${main}".`)
|
|
||||||
}
|
|
||||||
// If the branch is checked out in the main worktree, switch it to main first
|
|
||||||
if (await currentBranch(cwd) === branch) {
|
|
||||||
if (await isDirty(cwd)) {
|
|
||||||
throw new Error(`Cannot move branch "${branch}" to a worktree: the main worktree has uncommitted changes. Commit or stash them first.`)
|
|
||||||
}
|
|
||||||
await checkout(main, cwd)
|
|
||||||
switchedFromBranch = true
|
|
||||||
}
|
|
||||||
result = await $`git worktree add ${worktreePath} ${branch}`.cwd(cwd).nothrow().quiet()
|
result = await $`git worktree add ${worktreePath} ${branch}`.cwd(cwd).nothrow().quiet()
|
||||||
} else if (exists === "remote") {
|
} else if (exists === "remote") {
|
||||||
result = await $`git worktree add ${worktreePath} -b ${branch} origin/${branch}`.cwd(cwd).nothrow().quiet()
|
result = await $`git worktree add ${worktreePath} -b ${branch} origin/${branch}`.cwd(cwd).nothrow().quiet()
|
||||||
|
|
@ -71,10 +58,8 @@ export async function createWorktree(branch: string, worktreePath: string, cwd:
|
||||||
result = await $`git worktree add -b ${branch} ${worktreePath}`.cwd(cwd).nothrow().quiet()
|
result = await $`git worktree add -b ${branch} ${worktreePath}`.cwd(cwd).nothrow().quiet()
|
||||||
}
|
}
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
if (switchedFromBranch) await checkout(branch, cwd).catch(() => {})
|
|
||||||
throw new Error(`Failed to create worktree for "${branch}": ${result.stderr.toString().trim()}`)
|
throw new Error(`Failed to create worktree for "${branch}": ${result.stderr.toString().trim()}`)
|
||||||
}
|
}
|
||||||
return { branchCreated: exists !== "local" }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a worktree. Silently succeeds if the worktree is already gone. */
|
/** Remove a worktree. Silently succeeds if the worktree is already gone. */
|
||||||
|
|
@ -243,9 +228,6 @@ export async function branchDiff(branch: string, main: string, cwd: string): Pro
|
||||||
/** Detect the main branch name (main or master). */
|
/** Detect the main branch name (main or master). */
|
||||||
export async function mainBranch(cwd?: string): Promise<string> {
|
export async function mainBranch(cwd?: string): Promise<string> {
|
||||||
const dir = cwd ?? "."
|
const dir = cwd ?? "."
|
||||||
const main = await $`git -C ${dir} rev-parse --verify --quiet refs/heads/main`.nothrow().quiet()
|
const result = await $`git -C ${dir} rev-parse --verify --quiet refs/heads/main`.nothrow().quiet()
|
||||||
if (main.exitCode === 0) return "main"
|
return result.exitCode === 0 ? "main" : "master"
|
||||||
const master = await $`git -C ${dir} rev-parse --verify --quiet refs/heads/master`.nothrow().quiet()
|
|
||||||
if (master.exitCode === 0) return "master"
|
|
||||||
throw new Error("Could not detect main branch: neither \"main\" nor \"master\" exists.")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user