Git - fix discard changes when the repository does not have an initial commit (#169397)

This commit is contained in:
Ladislau Szomoru 2022-12-16 14:47:25 +01:00 committed by GitHub
parent cbf23d1500
commit c180a08350
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View file

@ -352,5 +352,6 @@ export const enum GitErrorCodes {
UnknownPath = 'UnknownPath',
EmptyCommitMessage = 'EmptyCommitMessage',
BranchFastForwardRejected = 'BranchFastForwardRejected',
BranchNotYetBorn = 'BranchNotYetBorn',
TagConflict = 'TagConflict'
}

View file

@ -1455,6 +1455,8 @@ export class Repository {
if (/Please,? commit your changes or stash them/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.DirtyWorkTree;
err.gitTreeish = treeish;
} else if (/You are on a branch yet to be born/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.BranchNotYetBorn;
}
throw err;

View file

@ -1457,7 +1457,13 @@ export class Repository implements Disposable {
});
await this.repository.clean(toClean);
await this.repository.checkout('', toCheckout);
try {
await this.repository.checkout('', toCheckout);
} catch (err) {
if (err.gitErrorCode !== GitErrorCodes.BranchNotYetBorn) {
throw err;
}
}
await this.repository.updateSubmodules(submodulesToUpdate);
this.closeDiffEditors([], [...toClean, ...toCheckout]);