Skip to content

Commit

Permalink
merge onboarding into base branch
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh committed Mar 13, 2023
1 parent 919c229 commit b6bc2a6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
36 changes: 36 additions & 0 deletions lib/util/git/index.ts
Expand Up @@ -768,6 +768,42 @@ export async function deleteBranch(branchName: string): Promise<void> {
delete config.branchCommits[branchName];
}

export async function mergeBranchWithoutPushing(
branchName: string
): Promise<void> {
let status: StatusResult | undefined;
try {
await syncGit();
await git.reset(ResetMode.HARD);
await gitRetry(() =>
git.checkout(['-B', branchName, 'origin/' + branchName])
);
await gitRetry(() =>
git.checkout([
'-B',
config.currentBranch,
'origin/' + config.currentBranch,
])
);
status = await git.status();
await gitRetry(() => git.merge([branchName]));
incLimitedValue('Commits');
} catch (err) {
logger.debug(
{
baseBranch: config.currentBranch,
baseSha: config.currentBranchSha,
branchName,
branchSha: getBranchCommit(branchName),
status,
err,
},
'mergeBranch error'
);
throw err;
}
}

export async function mergeBranch(branchName: string): Promise<void> {
let status: StatusResult | undefined;
try {
Expand Down
18 changes: 15 additions & 3 deletions lib/workers/repository/onboarding/branch/index.ts
Expand Up @@ -8,7 +8,12 @@ import {
} from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import { Pr, platform } from '../../../../modules/platform';
import { checkoutBranch, setGitAuthor } from '../../../../util/git';
import { scm } from '../../../../modules/platform/scm';
import {
checkoutBranch,
mergeBranchWithoutPushing,
setGitAuthor,
} from '../../../../util/git';
import { extractAllDependencies } from '../../extract';
import { mergeRenovateConfig } from '../../init/merge';
import { OnboardingState } from '../common';
Expand Down Expand Up @@ -81,9 +86,16 @@ export async function checkOnboardingBranch(
}
}
if (!GlobalConfig.get('dryRun')) {
logger.debug('Checkout onboarding branch.');
// TODO #7154
await checkoutBranch(onboardingBranch!);
if (
await scm.isBranchConflicted(config.baseBranch!, config.onboardingBranch!)
) {
logger.debug('Checkout onboarding branch');
await checkoutBranch(config.onboardingBranch!);
} else {
logger.debug('Merge onboarding branch in default branch');
await mergeBranchWithoutPushing(onboardingBranch!);
}
}
// TODO #7154
const branchList = [onboardingBranch!];
Expand Down

0 comments on commit b6bc2a6

Please sign in to comment.