Skip to content

Commit 5b21f2e

Browse files
committed
fix: handle nothing to commit when autocrlf is set
1 parent 20dac2e commit 5b21f2e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

dist/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exports.createOrUpdateBranch = exports.tryFetch = exports.getWorkingBaseAndType
3939
const core = __importStar(__nccwpck_require__(2186));
4040
const uuid_1 = __nccwpck_require__(5840);
4141
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
42+
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
4243
var WorkingBaseType;
4344
(function (WorkingBaseType) {
4445
WorkingBaseType["Branch"] = "branch";
@@ -138,7 +139,11 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
138139
if (signoff) {
139140
popts.push('--signoff');
140141
}
141-
yield git.commit(popts);
142+
const commitResult = yield git.commit(popts, true);
143+
// 'nothing to commit' can occur when core.autocrlf is set to true
144+
if (commitResult.exitCode != 0 && !commitResult.stdout.includes(NOTHING_TO_COMMIT)) {
145+
throw new Error(`Unexpected error: ${commitResult.stderr}`);
146+
}
142147
}
143148
// Remove uncommitted tracked and untracked changes
144149
yield git.exec(['reset', '--hard']);
@@ -674,7 +679,7 @@ class GitCommandManager {
674679
return yield this.exec(args, allowAllExitCodes);
675680
});
676681
}
677-
commit(options) {
682+
commit(options, allowAllExitCodes = false) {
678683
return __awaiter(this, void 0, void 0, function* () {
679684
const args = ['commit'];
680685
if (this.identityGitOptions) {
@@ -683,7 +688,7 @@ class GitCommandManager {
683688
if (options) {
684689
args.push(...options);
685690
}
686-
yield this.exec(args);
691+
return yield this.exec(args, allowAllExitCodes);
687692
});
688693
}
689694
config(configKey, configValue, globalConfig) {

src/create-or-update-branch.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {v4 as uuidv4} from 'uuid'
44

55
const CHERRYPICK_EMPTY =
66
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
7+
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'
78

89
export enum WorkingBaseType {
910
Branch = 'branch',
@@ -134,7 +135,14 @@ export async function createOrUpdateBranch(
134135
if (signoff) {
135136
popts.push('--signoff')
136137
}
137-
await git.commit(popts)
138+
const commitResult = await git.commit(popts, true)
139+
// 'nothing to commit' can occur when core.autocrlf is set to true
140+
if (
141+
commitResult.exitCode != 0 &&
142+
!commitResult.stdout.includes(NOTHING_TO_COMMIT)
143+
) {
144+
throw new Error(`Unexpected error: ${commitResult.stderr}`)
145+
}
138146
}
139147

140148
// Remove uncommitted tracked and untracked changes

src/git-command-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ export class GitCommandManager {
5353
return await this.exec(args, allowAllExitCodes)
5454
}
5555

56-
async commit(options?: string[]): Promise<void> {
56+
async commit(
57+
options?: string[],
58+
allowAllExitCodes = false
59+
): Promise<GitOutput> {
5760
const args = ['commit']
5861
if (this.identityGitOptions) {
5962
args.unshift(...this.identityGitOptions)
@@ -63,7 +66,7 @@ export class GitCommandManager {
6366
args.push(...options)
6467
}
6568

66-
await this.exec(args)
69+
return await this.exec(args, allowAllExitCodes)
6770
}
6871

6972
async config(

0 commit comments

Comments
 (0)