Skip to content

Commit

Permalink
fix: force commit if requested or conflicted (#6411)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 2, 2020
1 parent 75c0ca6 commit 59ea152
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/platform/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type CommitFilesConfig = {
branchName: string;
files: File[];
message: string;
force?: boolean;
};

export interface GotApiOptions {
Expand Down
3 changes: 2 additions & 1 deletion lib/platform/git/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ export class Storage {
branchName,
files,
message,
force = false,
}: CommitFilesConfig): Promise<string | null> {
logger.debug(`Committing files to branch ${branchName}`);
if (!this._privateKeySet) {
Expand Down Expand Up @@ -534,7 +535,7 @@ export class Storage {
}
const commitRes = await this._git.commit(message);
const commit = commitRes?.commit || 'unknown';
if (!(await this.hasDiff(`origin/${branchName}`))) {
if (!force && !(await this.hasDiff(`origin/${branchName}`))) {
logger.debug(
{ branchName, fileNames },
'No file changes detected. Skipping commit'
Expand Down
1 change: 1 addition & 0 deletions lib/workers/branch/__snapshots__/commit.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Array [
"name": "package.json",
},
],
"force": false,
"message": "some commit message",
},
],
Expand Down
1 change: 1 addition & 0 deletions lib/workers/branch/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ export async function commitFilesToBranch(
branchName: config.branchName,
files: updatedFiles,
message: config.commitMessage,
force: !!config.forceCommit,
});
}
3 changes: 2 additions & 1 deletion lib/workers/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ export async function processBranch(
logger.debug('PR has no releaseTimestamp');
}
}

config.forceCommit =
!!masterIssueCheck || config.rebaseRequested || branchPr?.isConflicted;
const commitHash = await commitFilesToBranch(config);
if (!commitHash && !branchExists) {
return 'no-work';
Expand Down
2 changes: 2 additions & 0 deletions lib/workers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ export interface BranchConfig
hasTypes?: boolean;
masterIssueChecks?: Record<string, string>;
releaseTimestamp?: string;
forceCommit?: boolean;
rebaseRequested?: boolean;

res?: ProcessBranchResult;
upgrades: BranchUpgradeConfig[];
Expand Down

0 comments on commit 59ea152

Please sign in to comment.