Files
archived-orca/src/shared/source-control-entry-actions.ts
T
OrcaWinandOrcaWin 5f155d3df8 fix(source-control): hide discard for present submodule gitlinks (#34991)
* fix(source-control): hide discard for present submodule gitlinks

Parent git restore --worktree without --recurse-submodules leaves a dirty or moved submodule untouched, so Discard reported success while the row stayed. Hide row/section discard for present gitlinks and submodule children; deleted submodule dirs and staged gitlink discard (which unstages) keep working.

* fix(source-control): keep submodule discard when submodule.recurse is on

Plain git restore recurses into active submodules when submodule.recurse=true, so status now stamps restoreRecurses on gitlink entries and the shared discard guards keep those rows discardable.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-30 05:31:21 -07:00

43 lines
1.5 KiB
TypeScript

import type { GitStatusEntry } from './git-status-types'
import {
isStageableStatusEntry,
isWorktreeUndiscardableGitlink
} from './source-control-discard-all-sequence'
/** Share row/bulk eligibility; submodule-internal rows are read-only because parent Git cannot mutate their working tree. */
export function canStageStatusEntry(entry: GitStatusEntry): boolean {
return isStageableStatusEntry(entry)
}
export function canUnstageStatusEntry(entry: GitStatusEntry): boolean {
return entry.area === 'staged' && !entry.submoduleRoot
}
export function canDiscardStatusEntry(entry: GitStatusEntry): boolean {
return (
entry.conflictStatus !== 'unresolved' &&
entry.conflictStatus !== 'resolved_locally' &&
!entry.submoduleRoot &&
!isWorktreeUndiscardableGitlink(entry) &&
(entry.area === 'unstaged' || entry.area === 'untracked')
)
}
export const CONFLICT_RESOLUTIONS = ['mark_resolved', 'keep_file', 'keep_deletion'] as const
export type ConflictResolution = (typeof CONFLICT_RESOLUTIONS)[number]
/** Staging the worktree is Git's resolution; a missing worktree file can only resolve as a deletion. */
export function getConflictResolutions(entry: GitStatusEntry): ConflictResolution[] {
if (entry.conflictStatus !== 'unresolved' || !entry.conflictKind || entry.submoduleRoot) {
return []
}
if (entry.status === 'deleted') {
return ['keep_deletion']
}
if (entry.conflictKind === 'deleted_by_us' || entry.conflictKind === 'deleted_by_them') {
return ['keep_file', 'keep_deletion']
}
return ['mark_resolved']
}