Git - Fix bug related to Stash & Checkout (#171099)

This commit is contained in:
Ladislau Szomoru 2023-01-11 21:07:17 +01:00 committed by GitHub
parent 12515569ae
commit b2b0642c45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2070,11 +2070,12 @@ export class CommandCenter {
await this.cleanAll(repository); await this.cleanAll(repository);
await item.run(opts); await item.run(opts);
} else if (choice === stash || choice === migrate) { } else if (choice === stash || choice === migrate) {
await this.stash(repository); if (await this._stash(repository)) {
await item.run(opts); await item.run(opts);
if (choice === migrate) { if (choice === migrate) {
await this.stashPopLatest(repository); await this.stashPopLatest(repository);
}
} }
} }
} }
@ -2982,7 +2983,7 @@ export class CommandCenter {
await commands.executeCommand('revealFileInOS', resourceState.resourceUri); await commands.executeCommand('revealFileInOS', resourceState.resourceUri);
} }
private async _stash(repository: Repository, includeUntracked = false, staged = false): Promise<void> { private async _stash(repository: Repository, includeUntracked = false, staged = false): Promise<boolean> {
const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0 const noUnstagedChanges = repository.workingTreeGroup.resourceStates.length === 0
&& (!includeUntracked || repository.untrackedGroup.resourceStates.length === 0); && (!includeUntracked || repository.untrackedGroup.resourceStates.length === 0);
const noStagedChanges = repository.indexGroup.resourceStates.length === 0; const noStagedChanges = repository.indexGroup.resourceStates.length === 0;
@ -2990,12 +2991,12 @@ export class CommandCenter {
if (staged) { if (staged) {
if (noStagedChanges) { if (noStagedChanges) {
window.showInformationMessage(l10n.t('There are no staged changes to stash.')); window.showInformationMessage(l10n.t('There are no staged changes to stash.'));
return; return false;
} }
} else { } else {
if (noUnstagedChanges && noStagedChanges) { if (noUnstagedChanges && noStagedChanges) {
window.showInformationMessage(l10n.t('There are no changes to stash.')); window.showInformationMessage(l10n.t('There are no changes to stash.'));
return; return false;
} }
} }
@ -3022,7 +3023,7 @@ export class CommandCenter {
if (pick === saveAndStash) { if (pick === saveAndStash) {
await Promise.all(documents.map(d => d.save())); await Promise.all(documents.map(d => d.save()));
} else if (pick !== stash) { } else if (pick !== stash) {
return; // do not stash on cancel return false; // do not stash on cancel
} }
} }
} }
@ -3040,15 +3041,16 @@ export class CommandCenter {
}); });
if (typeof message === 'undefined') { if (typeof message === 'undefined') {
return; return false;
} }
try { try {
await repository.createStash(message, includeUntracked, staged); await repository.createStash(message, includeUntracked, staged);
return true;
} catch (err) { } catch (err) {
if (/You do not have the initial commit yet/.test(err.stderr || '')) { if (/You do not have the initial commit yet/.test(err.stderr || '')) {
window.showInformationMessage(l10n.t('The repository does not have any commits. Please make an initial commit before creating a stash.')); window.showInformationMessage(l10n.t('The repository does not have any commits. Please make an initial commit before creating a stash.'));
return; return false;
} }
throw err; throw err;
@ -3056,18 +3058,18 @@ export class CommandCenter {
} }
@command('git.stash', { repository: true }) @command('git.stash', { repository: true })
stash(repository: Repository): Promise<void> { async stash(repository: Repository): Promise<void> {
return this._stash(repository); await this._stash(repository);
} }
@command('git.stashStaged', { repository: true }) @command('git.stashStaged', { repository: true })
stashStaged(repository: Repository): Promise<void> { async stashStaged(repository: Repository): Promise<void> {
return this._stash(repository, false, true); await this._stash(repository, false, true);
} }
@command('git.stashIncludeUntracked', { repository: true }) @command('git.stashIncludeUntracked', { repository: true })
stashIncludeUntracked(repository: Repository): Promise<void> { async stashIncludeUntracked(repository: Repository): Promise<void> {
return this._stash(repository, true); await this._stash(repository, true);
} }
@command('git.stashPop', { repository: true }) @command('git.stashPop', { repository: true })