chore: cleanup
This commit is contained in:
@@ -952,15 +952,15 @@ export default function Layout(props: ParentProps) {
|
|||||||
.then((x) => x.data ?? [])
|
.then((x) => x.data ?? [])
|
||||||
.catch(() => [])
|
.catch(() => [])
|
||||||
|
|
||||||
const pending = sessions.filter((session) => session.time.archived === undefined)
|
if (sessions.length > 0) {
|
||||||
if (pending.length > 0) {
|
const archivedAt = Date.now()
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
pending.map((session) =>
|
sessions.map((session) =>
|
||||||
globalSDK.client.session
|
globalSDK.client.session
|
||||||
.update({
|
.update({
|
||||||
sessionID: session.id,
|
sessionID: session.id,
|
||||||
directory: session.directory,
|
directory: session.directory,
|
||||||
time: { archived: Date.now() },
|
time: { archived: archivedAt },
|
||||||
})
|
})
|
||||||
.catch(() => undefined),
|
.catch(() => undefined),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -380,41 +380,45 @@ export namespace Worktree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkout = await $`git checkout ${target}`.quiet().nothrow().cwd(entry.path)
|
if (!entry.path) {
|
||||||
if (checkout.exitCode !== 0) {
|
throw new ResetFailedError({ message: "Worktree path not found" })
|
||||||
throw new ResetFailedError({ message: errorText(checkout) || `Failed to checkout ${target}` })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const clean = await $`git clean -fd`.quiet().nothrow().cwd(entry.path)
|
const worktreePath = entry.path
|
||||||
|
|
||||||
|
const resetToTarget = await $`git reset --hard ${target}`.quiet().nothrow().cwd(worktreePath)
|
||||||
|
if (resetToTarget.exitCode !== 0) {
|
||||||
|
throw new ResetFailedError({ message: errorText(resetToTarget) || "Failed to reset worktree to target" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const clean = await $`git clean -fdx`.quiet().nothrow().cwd(worktreePath)
|
||||||
if (clean.exitCode !== 0) {
|
if (clean.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: errorText(clean) || "Failed to clean worktree" })
|
throw new ResetFailedError({ message: errorText(clean) || "Failed to clean worktree" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const worktreeBranch = entry.branch?.replace(/^refs\/heads\//, "")
|
const update = await $`git submodule update --init --recursive --force`.quiet().nothrow().cwd(worktreePath)
|
||||||
if (!worktreeBranch) {
|
if (update.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: "Worktree branch not found" })
|
throw new ResetFailedError({ message: errorText(update) || "Failed to update submodules" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const reset = await $`git reset --hard ${target}`.quiet().nothrow().cwd(entry.path)
|
const subReset = await $`git submodule foreach --recursive git reset --hard`.quiet().nothrow().cwd(worktreePath)
|
||||||
if (reset.exitCode !== 0) {
|
if (subReset.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: errorText(reset) || "Failed to reset worktree" })
|
throw new ResetFailedError({ message: errorText(subReset) || "Failed to reset submodules" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanAfter = await $`git clean -fd`.quiet().nothrow().cwd(entry.path)
|
const subClean = await $`git submodule foreach --recursive git clean -fdx`.quiet().nothrow().cwd(worktreePath)
|
||||||
if (cleanAfter.exitCode !== 0) {
|
if (subClean.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: errorText(cleanAfter) || "Failed to clean worktree" })
|
throw new ResetFailedError({ message: errorText(subClean) || "Failed to clean submodules" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const branchReset = await $`git branch -f ${worktreeBranch} ${target}`.quiet().nothrow().cwd(entry.path)
|
const status = await $`git status --porcelain=v1`.quiet().nothrow().cwd(worktreePath)
|
||||||
if (branchReset.exitCode !== 0) {
|
if (status.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: errorText(branchReset) || "Failed to update worktree branch" })
|
throw new ResetFailedError({ message: errorText(status) || "Failed to read git status" })
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkoutBranch = await $`git checkout ${worktreeBranch}`.quiet().nothrow().cwd(entry.path)
|
const dirty = outputText(status.stdout)
|
||||||
if (checkoutBranch.exitCode !== 0) {
|
if (!dirty) return true
|
||||||
throw new ResetFailedError({ message: errorText(checkoutBranch) || "Failed to checkout worktree branch" })
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
throw new ResetFailedError({ message: `Worktree reset left local changes:\n${dirty}` })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user