Skip to content
Snippets Groups Projects
Unverified Commit 67a7dd4a authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

refactor: remove unnecessary if from git.setBranch (#6815)

parent 0a222b82
No related branches found
No related tags found
No related merge requests found
...@@ -114,6 +114,9 @@ describe('platform/git', () => { ...@@ -114,6 +114,9 @@ describe('platform/git', () => {
}); });
}); });
describe('isBranchStale()', () => { describe('isBranchStale()', () => {
beforeEach(async () => {
await git.setBranch('master');
});
it('should return false if same SHA as master', async () => { it('should return false if same SHA as master', async () => {
expect(await git.isBranchStale('renovate/future_branch')).toBe(false); expect(await git.isBranchStale('renovate/future_branch')).toBe(false);
}); });
......
...@@ -308,22 +308,19 @@ export async function getCommitMessages(): Promise<string[]> { ...@@ -308,22 +308,19 @@ export async function getCommitMessages(): Promise<string[]> {
} }
export async function setBranch(branchName: string): Promise<string> { export async function setBranch(branchName: string): Promise<string> {
if (branchName) {
if (!(await branchExists(branchName))) { if (!(await branchExists(branchName))) {
throwBranchValidationError(branchName); throwBranchValidationError(branchName);
} }
logger.debug(`Setting current branch to ${branchName}`); logger.debug(`Setting current branch to ${branchName}`);
config.currentBranch = branchName;
try { try {
if (branchName !== 'master') { config.currentBranch = branchName;
config.currentBranchSha = ( config.currentBranchSha = (
await git.raw(['rev-parse', 'origin/' + branchName]) await git.raw(['rev-parse', 'origin/' + branchName])
).trim(); ).trim();
}
await git.checkout([branchName, '-f']); await git.checkout([branchName, '-f']);
await git.reset(ResetMode.HARD);
const latestCommitDate = (await git.log({ n: 1 })).latest.date; const latestCommitDate = (await git.log({ n: 1 })).latest.date;
logger.debug({ branchName, latestCommitDate }, 'latest commit'); logger.debug({ branchName, latestCommitDate }, 'latest commit');
await git.reset(ResetMode.HARD);
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err); checkForPlatformFailure(err);
if ( if (
...@@ -336,7 +333,6 @@ export async function setBranch(branchName: string): Promise<string> { ...@@ -336,7 +333,6 @@ export async function setBranch(branchName: string): Promise<string> {
} }
throw err; throw err;
} }
}
return ( return (
config.currentBranchSha || config.currentBranchSha ||
(await git.raw(['rev-parse', 'origin/master'])).trim() (await git.raw(['rev-parse', 'origin/master'])).trim()
...@@ -396,7 +392,7 @@ export async function isBranchStale(branchName: string): Promise<boolean> { ...@@ -396,7 +392,7 @@ export async function isBranchStale(branchName: string): Promise<boolean> {
'--remotes', '--remotes',
'--verbose', '--verbose',
'--contains', '--contains',
config.currentBranchSha || `origin/${config.currentBranch}`, config.currentBranchSha,
]); ]);
return !branches.all.map(localName).includes(branchName); return !branches.all.map(localName).includes(branchName);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment