Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions dist/index.js
Expand Up @@ -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";
Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion src/create-or-update-branch.ts
Expand Up @@ -4,6 +4,7 @@ import {v4 as uuidv4} from 'uuid'

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'

export enum WorkingBaseType {
Branch = 'branch',
Expand Down Expand Up @@ -134,7 +135,14 @@ export async function createOrUpdateBranch(
if (signoff) {
popts.push('--signoff')
}
await git.commit(popts)
const commitResult = await 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
Expand Down
7 changes: 5 additions & 2 deletions src/git-command-manager.ts
Expand Up @@ -53,7 +53,10 @@ export class GitCommandManager {
return await this.exec(args, allowAllExitCodes)
}

async commit(options?: string[]): Promise<void> {
async commit(
options?: string[],
allowAllExitCodes = false
): Promise<GitOutput> {
const args = ['commit']
if (this.identityGitOptions) {
args.unshift(...this.identityGitOptions)
Expand All @@ -63,7 +66,7 @@ export class GitCommandManager {
args.push(...options)
}

await this.exec(args)
return await this.exec(args, allowAllExitCodes)
}

async config(
Expand Down