fix: handle nothing to commit when autocrlf is set (#1211)

This commit is contained in:
Peter Evans 2022-08-18 17:20:00 +09:00 committed by GitHub
parent 20dac2ed48
commit 2721abb4d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

11
dist/index.js vendored
View file

@ -39,6 +39,7 @@ exports.createOrUpdateBranch = exports.tryFetch = exports.getWorkingBaseAndType
const core = __importStar(__nccwpck_require__(2186));
const uuid_1 = __nccwpck_require__(5840);
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
var WorkingBaseType;
(function (WorkingBaseType) {
WorkingBaseType["Branch"] = "branch";
@ -138,7 +139,11 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
if (signoff) {
popts.push('--signoff');
}
yield git.commit(popts);
const commitResult = yield git.commit(popts, true);
// 'nothing to commit' can occur when core.autocrlf is set to true
if (commitResult.exitCode != 0 && !commitResult.stdout.includes(NOTHING_TO_COMMIT)) {
throw new Error(`Unexpected error: ${commitResult.stderr}`);
}
}
// Remove uncommitted tracked and untracked changes
yield git.exec(['reset', '--hard']);
@ -674,7 +679,7 @@ class GitCommandManager {
return yield this.exec(args, allowAllExitCodes);
});
}
commit(options) {
commit(options, allowAllExitCodes = false) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['commit'];
if (this.identityGitOptions) {
@ -683,7 +688,7 @@ class GitCommandManager {
if (options) {
args.push(...options);
}
yield this.exec(args);
return yield this.exec(args, allowAllExitCodes);
});
}
config(configKey, configValue, globalConfig) {