Skip to content
Snippets Groups Projects
Unverified Commit 99c30be2 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

fix(git): Don't fetch if push has failed (#13997)

* fix(git): Don't fetch if push has failed

* Fix coverage
parent 2a013b3c
No related branches found
No related tags found
No related merge requests found
...@@ -815,9 +815,10 @@ export async function prepareCommit({ ...@@ -815,9 +815,10 @@ export async function prepareCommit({
export async function pushCommit({ export async function pushCommit({
branchName, branchName,
files, files,
}: CommitFilesConfig): Promise<void> { }: CommitFilesConfig): Promise<boolean> {
await syncGit(); await syncGit();
logger.debug(`Pushing branch ${branchName}`); logger.debug(`Pushing branch ${branchName}`);
let result = false;
try { try {
const pushOptions: TaskOptions = { const pushOptions: TaskOptions = {
'--force-with-lease': null, '--force-with-lease': null,
...@@ -835,9 +836,11 @@ export async function pushCommit({ ...@@ -835,9 +836,11 @@ export async function pushCommit({
delete pushRes.repo; delete pushRes.repo;
logger.debug({ result: pushRes }, 'git push'); logger.debug({ result: pushRes }, 'git push');
incLimitedValue(Limit.Commits); incLimitedValue(Limit.Commits);
result = true;
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
handleCommitError(files, branchName, err); handleCommitError(files, branchName, err);
} }
return result;
} }
export async function fetchCommit({ export async function fetchCommit({
...@@ -862,12 +865,14 @@ export async function commitFiles( ...@@ -862,12 +865,14 @@ export async function commitFiles(
config: CommitFilesConfig config: CommitFilesConfig
): Promise<CommitSha | null> { ): Promise<CommitSha | null> {
const commitResult = await prepareCommit(config); const commitResult = await prepareCommit(config);
if (!commitResult) { if (commitResult) {
return null; const pushResult = await pushCommit(config);
} if (pushResult) {
await pushCommit(config);
return fetchCommit(config); return fetchCommit(config);
} }
}
return null;
}
export function getUrl({ export function getUrl({
protocol, protocol,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment