Skip to content

Commit

Permalink
fix(git): Don't fetch if push has failed (#13997)
Browse files Browse the repository at this point in the history
* fix(git): Don't fetch if push has failed

* Fix coverage
  • Loading branch information
zharinov committed Feb 4, 2022
1 parent 2a013b3 commit 99c30be
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/util/git/index.ts
Expand Up @@ -815,9 +815,10 @@ export async function prepareCommit({
export async function pushCommit({
branchName,
files,
}: CommitFilesConfig): Promise<void> {
}: CommitFilesConfig): Promise<boolean> {
await syncGit();
logger.debug(`Pushing branch ${branchName}`);
let result = false;
try {
const pushOptions: TaskOptions = {
'--force-with-lease': null,
Expand All @@ -835,9 +836,11 @@ export async function pushCommit({
delete pushRes.repo;
logger.debug({ result: pushRes }, 'git push');
incLimitedValue(Limit.Commits);
result = true;
} catch (err) /* istanbul ignore next */ {
handleCommitError(files, branchName, err);
}
return result;
}

export async function fetchCommit({
Expand All @@ -862,11 +865,13 @@ export async function commitFiles(
config: CommitFilesConfig
): Promise<CommitSha | null> {
const commitResult = await prepareCommit(config);
if (!commitResult) {
return null;
if (commitResult) {
const pushResult = await pushCommit(config);
if (pushResult) {
return fetchCommit(config);
}
}
await pushCommit(config);
return fetchCommit(config);
return null;
}

export function getUrl({
Expand Down

0 comments on commit 99c30be

Please sign in to comment.