fix: allow git checkout with uncommitted files (#945)
This commit is contained in:
@@ -1057,10 +1057,6 @@ export const GitView: React.FC = () => {
|
||||
}, [currentDirectory, selectedPaths, settingsGitmojiEnabled, gitmojiEmojis, scrollActionPanelToBottom]);
|
||||
|
||||
const formatBlockingReason = (reason: ReturnType<typeof getMutationBlockingReasons>[number]): string => {
|
||||
if (reason.reason === 'dirty') {
|
||||
const count = typeof reason.dirtyFiles === 'number' ? reason.dirtyFiles : null;
|
||||
return count != null ? `${count} uncommitted file${count === 1 ? '' : 's'}` : 'uncommitted changes';
|
||||
}
|
||||
if (reason.reason === 'attention') {
|
||||
return `${reason.attentionReason} in progress`;
|
||||
}
|
||||
@@ -1073,7 +1069,7 @@ export const GitView: React.FC = () => {
|
||||
const handleCreateBranch = async (branchName: string, remote?: GitRemote) => {
|
||||
if (!currentDirectory || !status) return;
|
||||
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment ?? null, status);
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment);
|
||||
if (blockingReasons.length > 0) {
|
||||
toast.error(`Cannot create branch: ${formatBlockingReason(blockingReasons[0])}`);
|
||||
return;
|
||||
@@ -1127,7 +1123,7 @@ export const GitView: React.FC = () => {
|
||||
const handleRenameBranch = async (oldName: string, newName: string) => {
|
||||
if (!currentDirectory) return;
|
||||
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment ?? null, status);
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment);
|
||||
if (blockingReasons.length > 0) {
|
||||
toast.error(`Cannot rename branch: ${formatBlockingReason(blockingReasons[0])}`);
|
||||
return;
|
||||
@@ -1149,7 +1145,7 @@ export const GitView: React.FC = () => {
|
||||
if (!currentDirectory) return;
|
||||
|
||||
// Block mutation if worktree is in an attention-required state
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment ?? null, status);
|
||||
const blockingReasons = getMutationBlockingReasons(worktreeAttachment);
|
||||
if (blockingReasons.length > 0) {
|
||||
toast.error(`Cannot checkout: ${formatBlockingReason(blockingReasons[0])}`);
|
||||
return;
|
||||
|
||||
@@ -167,24 +167,14 @@ export function getSessionWorktreeRepairActions(
|
||||
}
|
||||
|
||||
export type MutationBlockingReason =
|
||||
| { reason: 'dirty'; dirtyFiles?: number }
|
||||
| { reason: 'attention'; attentionReason: NonNullable<SessionWorktreeAttachment['attentionReason']> }
|
||||
| { reason: 'missing' }
|
||||
| { reason: 'invalid' };
|
||||
|
||||
export type GitStatusForBlocking = {
|
||||
isClean: boolean;
|
||||
files?: unknown[];
|
||||
};
|
||||
|
||||
export function getMutationBlockingReasons(
|
||||
attachment: SessionWorktreeAttachment | null | undefined,
|
||||
gitStatus?: GitStatusForBlocking | null
|
||||
attachment: SessionWorktreeAttachment | null | undefined
|
||||
): MutationBlockingReason[] {
|
||||
const reasons: MutationBlockingReason[] = [];
|
||||
if (gitStatus && !gitStatus.isClean) {
|
||||
reasons.push({ reason: 'dirty', dirtyFiles: Array.isArray(gitStatus.files) ? gitStatus.files.length : undefined });
|
||||
}
|
||||
if (!attachment) return reasons;
|
||||
if (attachment.worktreeStatus === 'missing') {
|
||||
reasons.push({ reason: 'missing' });
|
||||
|
||||
Reference in New Issue
Block a user