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()
|
||||
if (!current) 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)
|
||||
if (pending.length > 0) {
|
||||
await Promise.all(
|
||||
@@ -1047,12 +1052,13 @@ export default function Layout(props: ParentProps) {
|
||||
sessions: [] as Session[],
|
||||
})
|
||||
|
||||
const refreshSessions = () => {
|
||||
const [workspace] = globalSync.child(props.directory)
|
||||
const sessions = workspace.session
|
||||
.filter((session) => session.directory === workspace.path.directory)
|
||||
.filter((session) => session.time.archived === undefined)
|
||||
setState({ sessions })
|
||||
const refresh = async () => {
|
||||
const sessions = await globalSDK.client.session
|
||||
.list({ directory: props.directory })
|
||||
.then((x) => x.data ?? [])
|
||||
.catch(() => [])
|
||||
const active = sessions.filter((session) => session.time.archived === undefined)
|
||||
setState({ sessions: active })
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
@@ -1068,7 +1074,7 @@ export default function Layout(props: ParentProps) {
|
||||
const files = x.data ?? []
|
||||
const dirty = files.length > 0
|
||||
setState({ status: "ready", dirty })
|
||||
refreshSessions()
|
||||
void refresh()
|
||||
})
|
||||
.catch(() => {
|
||||
setState({ status: "error", dirty: false })
|
||||
@@ -1076,7 +1082,7 @@ export default function Layout(props: ParentProps) {
|
||||
})
|
||||
|
||||
const handleReset = async () => {
|
||||
await resetWorkspace(props.directory, state.sessions)
|
||||
await resetWorkspace(props.directory)
|
||||
dialog.close()
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +385,11 @@ export namespace Worktree {
|
||||
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\//, "")
|
||||
if (!worktreeBranch) {
|
||||
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" })
|
||||
}
|
||||
|
||||
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)
|
||||
if (branchReset.exitCode !== 0) {
|
||||
throw new ResetFailedError({ message: errorText(branchReset) || "Failed to update worktree branch" })
|
||||
|
||||
Reference in New Issue
Block a user