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