Skip to content

Commit 9f33be1

Browse files
authored
coding agent: swap back to base branch (#7065)
1 parent 08a0ab0 commit 9f33be1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/github/copilotRemoteAgent.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,25 @@ export class CopilotRemoteAgentManager extends Disposable {
197197
await repository.commit('Checkpoint for Copilot Agent async session', { signCommit: false });
198198
}
199199
await repository.push(remote, asyncBranch, true);
200+
ref = asyncBranch;
200201
} catch (e) {
201202
return { error: vscode.l10n.t(`Could not auto-commit pending changes. Please disable GPG signing, or manually commit/stash your changes before starting the remote agent. Error: ${e.message}`), state: 'error' };
203+
} finally {
204+
// Swap back to the original branch without your pending changes
205+
// TODO: Better if we show a confirmation dialog in chat
206+
if (repository.state.HEAD?.name !== baseRef) {
207+
// show notification asking the user if they want to switch back to the original branch
208+
const SWAP_BACK_TO_ORIGINAL_BRANCH = vscode.l10n.t(`Swap back to '{0}'`, baseRef);
209+
vscode.window.showInformationMessage(
210+
vscode.l10n.t(`Your pending changes have been pushed to remote branch '{0}.`, ref),
211+
SWAP_BACK_TO_ORIGINAL_BRANCH,
212+
).then(async (selection) => {
213+
if (selection === SWAP_BACK_TO_ORIGINAL_BRANCH) {
214+
await repository.checkout(baseRef);
215+
}
216+
});
217+
}
202218
}
203-
ref = `refs/heads/${asyncBranch}`;
204219
}
205220

206221
const payload: RemoteAgentJobPayload = {

0 commit comments

Comments
 (0)