chore: cleanup
This commit is contained in:
@@ -942,11 +942,16 @@ export default function Layout(props: ParentProps) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetWorkspace = async (directory: string, sessions: Session[]) => {
|
const resetWorkspace = async (directory: string) => {
|
||||||
const current = currentProject()
|
const current = currentProject()
|
||||||
if (!current) return
|
if (!current) return
|
||||||
if (directory === current.worktree) return
|
if (directory === current.worktree) return
|
||||||
|
|
||||||
|
const sessions = await globalSDK.client.session
|
||||||
|
.list({ directory })
|
||||||
|
.then((x) => x.data ?? [])
|
||||||
|
.catch(() => [])
|
||||||
|
|
||||||
const pending = sessions.filter((session) => session.time.archived === undefined)
|
const pending = sessions.filter((session) => session.time.archived === undefined)
|
||||||
if (pending.length > 0) {
|
if (pending.length > 0) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@@ -1047,12 +1052,13 @@ export default function Layout(props: ParentProps) {
|
|||||||
sessions: [] as Session[],
|
sessions: [] as Session[],
|
||||||
})
|
})
|
||||||
|
|
||||||
const refreshSessions = () => {
|
const refresh = async () => {
|
||||||
const [workspace] = globalSync.child(props.directory)
|
const sessions = await globalSDK.client.session
|
||||||
const sessions = workspace.session
|
.list({ directory: props.directory })
|
||||||
.filter((session) => session.directory === workspace.path.directory)
|
.then((x) => x.data ?? [])
|
||||||
.filter((session) => session.time.archived === undefined)
|
.catch(() => [])
|
||||||
setState({ sessions })
|
const active = sessions.filter((session) => session.time.archived === undefined)
|
||||||
|
setState({ sessions: active })
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -1068,7 +1074,7 @@ export default function Layout(props: ParentProps) {
|
|||||||
const files = x.data ?? []
|
const files = x.data ?? []
|
||||||
const dirty = files.length > 0
|
const dirty = files.length > 0
|
||||||
setState({ status: "ready", dirty })
|
setState({ status: "ready", dirty })
|
||||||
refreshSessions()
|
void refresh()
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setState({ status: "error", dirty: false })
|
setState({ status: "error", dirty: false })
|
||||||
@@ -1076,7 +1082,7 @@ export default function Layout(props: ParentProps) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleReset = async () => {
|
const handleReset = async () => {
|
||||||
await resetWorkspace(props.directory, state.sessions)
|
await resetWorkspace(props.directory)
|
||||||
dialog.close()
|
dialog.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -385,6 +385,11 @@ export namespace Worktree {
|
|||||||
throw new ResetFailedError({ message: errorText(checkout) || `Failed to checkout ${target}` })
|
throw new ResetFailedError({ message: errorText(checkout) || `Failed to checkout ${target}` })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clean = await $`git clean -fd`.quiet().nothrow().cwd(entry.path)
|
||||||
|
if (clean.exitCode !== 0) {
|
||||||
|
throw new ResetFailedError({ message: errorText(clean) || "Failed to clean worktree" })
|
||||||
|
}
|
||||||
|
|
||||||
const worktreeBranch = entry.branch?.replace(/^refs\/heads\//, "")
|
const worktreeBranch = entry.branch?.replace(/^refs\/heads\//, "")
|
||||||
if (!worktreeBranch) {
|
if (!worktreeBranch) {
|
||||||
throw new ResetFailedError({ message: "Worktree branch not found" })
|
throw new ResetFailedError({ message: "Worktree branch not found" })
|
||||||
@@ -395,6 +400,11 @@ export namespace Worktree {
|
|||||||
throw new ResetFailedError({ message: errorText(reset) || "Failed to reset worktree" })
|
throw new ResetFailedError({ message: errorText(reset) || "Failed to reset worktree" })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cleanAfter = await $`git clean -fd`.quiet().nothrow().cwd(entry.path)
|
||||||
|
if (cleanAfter.exitCode !== 0) {
|
||||||
|
throw new ResetFailedError({ message: errorText(cleanAfter) || "Failed to clean worktree" })
|
||||||
|
}
|
||||||
|
|
||||||
const branchReset = await $`git branch -f ${worktreeBranch} ${target}`.quiet().nothrow().cwd(entry.path)
|
const branchReset = await $`git branch -f ${worktreeBranch} ${target}`.quiet().nothrow().cwd(entry.path)
|
||||||
if (branchReset.exitCode !== 0) {
|
if (branchReset.exitCode !== 0) {
|
||||||
throw new ResetFailedError({ message: errorText(branchReset) || "Failed to update worktree branch" })
|
throw new ResetFailedError({ message: errorText(branchReset) || "Failed to update worktree branch" })
|
||||||
|
|||||||
Reference in New Issue
Block a user