stash and restore uncommitted changes

This commit is contained in:
Peter Evans 2022-11-29 14:48:18 +09:00
parent 87923ad652
commit fa545b74a7
4 changed files with 141 additions and 6 deletions

28
dist/index.js vendored
View file

@ -158,9 +158,8 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
throw new Error(`Unexpected error: ${commitResult.stderr}`);
}
}
// Remove uncommitted tracked and untracked changes
yield git.exec(['reset', '--hard']);
yield git.exec(['clean', '-f', '-d']);
// Stash any uncommitted tracked and untracked changes
const stashed = yield git.stashPush(['--include-untracked']);
// Perform fetch and reset the working base
// Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) {
@ -260,6 +259,10 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
yield git.exec(['branch', '--delete', '--force', tempBranch]);
// Checkout the working base to leave the local repository as it was found
yield git.checkout(workingBase);
// Restore any stashed changes
if (stashed) {
yield git.stashPop();
}
return result;
});
}
@ -844,6 +847,25 @@ class GitCommandManager {
return output.stdout.trim();
});
}
stashPush(options) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['stash', 'push'];
if (options) {
args.push(...options);
}
const output = yield this.exec(args);
return output.stdout.trim() !== 'No local changes to save';
});
}
stashPop(options) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['stash', 'pop'];
if (options) {
args.push(...options);
}
yield this.exec(args);
});
}
status(options) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['status'];