Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3473,26 +3473,52 @@ export class CommandCenter {
}
}

await worktreeRepository.createStash(undefined, true);
const stashes = await worktreeRepository.getStashes();
const message = l10n.t('There are merge conflicts from migrating changes. Please resolve them before committing.');
await this.migrateStashBetweenRepositories(worktreeRepository, repository, message);
}

private async migrateChangesToWorktree(repository: Repository, worktreePath: string): Promise<void> {
if (repository.indexGroup.resourceStates.length === 0 &&
repository.workingTreeGroup.resourceStates.length === 0 &&
repository.untrackedGroup.resourceStates.length === 0) {
return;
}

await this.model.openRepository(worktreePath, true, true);

const worktreeRepository = this.model.getRepository(worktreePath);
if (!worktreeRepository || worktreeRepository.kind !== 'worktree') {
return;
}

const message = l10n.t('There are merge conflicts from migrating changes to the worktree. Please resolve them before committing.');
await this.migrateStashBetweenRepositories(repository, worktreeRepository, message);
}

private async migrateStashBetweenRepositories(
sourceRepository: Repository,
targetRepository: Repository,
conflictMessage: string
): Promise<void> {
await sourceRepository.createStash(undefined, true);
const stashes = await sourceRepository.getStashes();

try {
await repository.applyStash(stashes[0].index);
worktreeRepository.dropStash(stashes[0].index);
await targetRepository.applyStash(stashes[0].index);
sourceRepository.dropStash(stashes[0].index);
} catch (err) {
if (err.gitErrorCode !== GitErrorCodes.StashConflict) {
await worktreeRepository.popStash();
await sourceRepository.popStash();
throw err;
}
repository.isWorktreeMigrating = true;
targetRepository.isWorktreeMigrating = true;

const message = l10n.t('There are merge conflicts from migrating changes. Please resolve them before committing.');
const show = l10n.t('Show Changes');
const choice = await window.showWarningMessage(message, show);
const choice = await window.showWarningMessage(conflictMessage, show);
if (choice === show) {
await commands.executeCommand('workbench.view.scm');
}
worktreeRepository.dropStash(stashes[0].index);
sourceRepository.dropStash(stashes[0].index);
}
}

Expand All @@ -3515,7 +3541,8 @@ export class CommandCenter {
@command('git.createWorktreeWithDefaults', { repository: true, repositoryFilter: ['repository'] })
async createWorktreeWithDefaults(
repository: Repository,
commitish: string = 'HEAD'
commitish: string = 'HEAD',
migrateUncommittedChanges: boolean = false
): Promise<string | undefined> {
const config = workspace.getConfiguration('git');
const branchPrefix = config.get<string>('branchPrefix', '');
Expand Down Expand Up @@ -3568,6 +3595,11 @@ export class CommandCenter {
this.globalState.update(`${CommandCenter.WORKTREE_ROOT_KEY}:${repository.root}`, worktreeRoot);
}

// Migrate uncommitted changes if requested
if (migrateUncommittedChanges) {
await this.migrateChangesToWorktree(repository, finalWorktreePath);
}

return finalWorktreePath;
} catch (err) {
// Return undefined on failure
Expand All @@ -3584,6 +3616,11 @@ export class CommandCenter {
this.globalState.update(`${CommandCenter.WORKTREE_ROOT_KEY}:${repository.root}`, worktreeRoot);
}

// Migrate uncommitted changes if requested
if (migrateUncommittedChanges) {
await this.migrateChangesToWorktree(repository, defaultWorktreePath);
}

return defaultWorktreePath;
} catch (err) {
// Return undefined on failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ const apiMenus: IAPIMenu[] = [
supportsSubmenus: false,
proposed: 'chatParticipantPrivate'
},
{
key: 'chat/execute',
id: MenuId.ChatExecute,
description: localize('menus.chatExecute', "The Chat Execute menu."),
supportsSubmenus: false,
proposed: 'chatSessionsProvider'
},
{
// TODO: rename this to something like: `chatSessions/item/inline`
key: 'chat/chatSessions',
Expand Down
Loading