Skip to content

Commit

Permalink
Inhibit server restarts during bisect/cherry-pick as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Earlopain committed Sep 11, 2024
1 parent 9e03d14 commit 005c19e
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Workspace implements WorkspaceInterface {
private readonly isMainWorkspace: boolean;
private readonly telemetry: vscode.TelemetryLogger;
private needsRestart = false;
#rebaseInProgress = false;
#inhibitRestart = false;
#error = false;

constructor(
Expand All @@ -44,7 +44,12 @@ export class Workspace implements WorkspaceInterface {
this.isMainWorkspace = isMainWorkspace;

this.registerRestarts(context);
this.registerRebaseWatcher(context);
this.registerCreateDeleteWatcher(
context,
".git/{rebase-merge,rebase-apply}",
);
this.registerCreateDeleteWatcher(context, ".git/BISECT_START");
this.registerCreateDeleteWatcher(context, ".git/CHERRY_PICK_HEAD");
}

async start() {
Expand Down Expand Up @@ -139,7 +144,7 @@ export class Workspace implements WorkspaceInterface {

async restart() {
try {
if (this.#rebaseInProgress) {
if (this.#inhibitRestart) {
return;
}

Expand Down Expand Up @@ -266,8 +271,8 @@ export class Workspace implements WorkspaceInterface {
this.#error = value;
}

get rebaseInProgress() {
return this.#rebaseInProgress;
get inhibitRestart() {
return this.#inhibitRestart;
}

async execute(command: string, log = false) {
Expand Down Expand Up @@ -335,35 +340,32 @@ export class Workspace implements WorkspaceInterface {
);
}

private registerRebaseWatcher(context: vscode.ExtensionContext) {
private registerCreateDeleteWatcher(
context: vscode.ExtensionContext,
glob: string,
) {
const parentWatcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
this.workspaceFolder,
"../.git/{rebase-merge,rebase-apply}",
),
new vscode.RelativePattern(this.workspaceFolder, `../${glob}`),
);
const workspaceWatcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(
this.workspaceFolder,
".git/{rebase-merge,rebase-apply}",
),
new vscode.RelativePattern(this.workspaceFolder, glob),
);

const startRebase = () => {
this.#rebaseInProgress = true;
const start = () => {
this.#inhibitRestart = true;
};
const stopRebase = async () => {
this.#rebaseInProgress = false;
const stop = async () => {
this.#inhibitRestart = false;
await this.restart();
};

context.subscriptions.push(
workspaceWatcher,
parentWatcher,
// When one of the rebase files are created, we set this flag to prevent restarting during the rebase
workspaceWatcher.onDidCreate(startRebase),
// Once they are deleted and the rebase is complete, then we restart
workspaceWatcher.onDidDelete(stopRebase),
// When one of the 'inhibit restart' files are created, we set this flag to prevent restarting during that action
workspaceWatcher.onDidCreate(start),
// Once they are deleted and the action is complete, then we restart
workspaceWatcher.onDidDelete(stop),
);
}
}

0 comments on commit 005c19e

Please sign in to comment.