mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(vcs): say whether blocked checkout would remove or overwrite the untracked files (#4005)
When git refused a checkout because of untracked files, the notification always said they would be overwritten; git's own reason (removed vs overwritten) is now carried on CheckoutOutcome::UntrackedFiles and the notification uses git's wording for each case. Fixes #3980 Co-authored-by: Inf1mum <8135225+Inf1mum@users.noreply.github.com>
This commit is contained in:
+6
-2
@@ -3293,8 +3293,12 @@ export type CheckoutOptions = {
|
||||
export type CheckoutOutcome = { kind: "done" } |
|
||||
/** These local changes (repository-relative paths) would be overwritten. */
|
||||
{ kind: "localChanges"; files: string[] } |
|
||||
/** These untracked files (repository-relative paths) would be overwritten. */
|
||||
{ kind: "untrackedFiles"; files: string[] } |
|
||||
/**
|
||||
* These untracked files (repository-relative paths) would be overwritten by the
|
||||
* checkout; with `removed`, they would be removed by it (tracked here, absent
|
||||
* from the target).
|
||||
*/
|
||||
{ kind: "untrackedFiles"; files: string[]; removed: boolean } |
|
||||
/** Local branch `local` has commits that remote branch `remote` does not. */
|
||||
{ kind: "localBranchAhead"; local: string; remote: string } |
|
||||
/**
|
||||
|
||||
@@ -219,6 +219,34 @@ it("does not open the worktree when the checkout offer is declined", async () =>
|
||||
expect(mocks.executeAction).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("names the files git would remove when untracked ones block the checkout", async () => {
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "untrackedFiles", files: ["TEST.md"], removed: true }));
|
||||
await checkoutBranch("feature/x");
|
||||
expect(mocks.checkout).toHaveBeenCalledTimes(1);
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
level: "error",
|
||||
title: "Untracked files prevent checkout",
|
||||
body: expect.stringContaining(
|
||||
"The following untracked working tree files would be removed by checkout:\nTEST.md",
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("still says overwritten when untracked files would be overwritten", async () => {
|
||||
mocks.checkout.mockResolvedValue(ok({ kind: "untrackedFiles", files: ["dir/new.txt"], removed: false }));
|
||||
await checkoutBranch("feature/x");
|
||||
expect(mocks.notify).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
level: "error",
|
||||
body: expect.stringContaining(
|
||||
"The following untracked working tree files would be overwritten by checkout:\ndir/new.txt",
|
||||
),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the branch when the worktree question is turned down", async () => {
|
||||
mocks.worktrees.mockResolvedValue(ok([worktree("/p/front-feature-wt", "feature/wt")]));
|
||||
mocks.confirm.mockResolvedValue(false);
|
||||
|
||||
@@ -104,11 +104,17 @@ async function performCheckout(
|
||||
return true;
|
||||
case "untrackedFiles": {
|
||||
const files = outcome.files.join("\n");
|
||||
// git refuses untracked files in two ways: they would be overwritten by the
|
||||
// checkout (present in the target), or removed by it (tracked here, absent
|
||||
// from the target); each names its files the way git's own message does.
|
||||
const body = outcome.removed
|
||||
? tx`The following untracked working tree files would be removed by checkout:\n${files}\nPlease move or remove them before you switch branches.`
|
||||
: tx`The following untracked working tree files would be overwritten by checkout:\n${files}\nPlease move or remove them before you switch branches.`;
|
||||
notifications().notify({
|
||||
group: "vcs",
|
||||
level: "error",
|
||||
title: "Untracked files prevent checkout",
|
||||
body: tx`The following untracked working tree files would be overwritten by checkout:\n${files}\nPlease move or remove them before you switch branches.`,
|
||||
body,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -7001,6 +7001,7 @@
|
||||
"Choose Declaration": "选择声明",
|
||||
"Go to mapping: {target}": "跳转到映射:{target}",
|
||||
"Untracked files prevent checkout": "未跟踪的文件阻止了签出",
|
||||
"The following untracked working tree files would be removed by checkout:\n{files}\nPlease move or remove them before you switch branches.": "签出将删除以下未跟踪的工作区文件:\n{files}\n请在切换分支前移动或删除它们。",
|
||||
"The following untracked working tree files would be overwritten by checkout:\n{files}\nPlease move or remove them before you switch branches.": "签出将覆盖以下未跟踪的工作区文件:\n{files}\n请在切换分支前移动或删除它们。",
|
||||
"Select Target Changelist": "选择目标更改列表",
|
||||
"Rebase undone": "已撤销变基",
|
||||
|
||||
Reference in New Issue
Block a user