2022-10-30 23:50:33 -06:00
|
|
|
import { logger } from '../../logger';
|
|
|
|
import { getCache } from '../cache/repository';
|
|
|
|
import type { BranchCache } from '../cache/repository/types';
|
|
|
|
import { getBranchCommit } from '.';
|
2022-10-05 22:37:47 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a new commit is added to branch
|
|
|
|
*
|
|
|
|
* ie. when branch is created/updated
|
|
|
|
*/
|
|
|
|
export function setBranchNewCommit(
|
|
|
|
branchName: string,
|
|
|
|
baseBranch: string,
|
2023-11-07 08:50:29 -07:00
|
|
|
commitSha: string,
|
2022-10-05 22:37:47 -06:00
|
|
|
): void {
|
|
|
|
logger.debug('setBranchCommit()');
|
|
|
|
const cache = getCache();
|
|
|
|
cache.branches ??= [];
|
|
|
|
let branch = cache.branches.find((br) => br.branchName === branchName);
|
|
|
|
if (!branch) {
|
|
|
|
logger.debug(`setBranchCommit(): Branch cache not present`); // should never be called
|
|
|
|
branch = {
|
|
|
|
branchName,
|
|
|
|
baseBranch,
|
|
|
|
} as BranchCache;
|
|
|
|
cache.branches.push(branch);
|
|
|
|
}
|
|
|
|
|
|
|
|
const baseBranchSha = getBranchCommit(baseBranch);
|
|
|
|
|
|
|
|
branch.baseBranchSha = baseBranchSha;
|
|
|
|
branch.isBehindBase = false;
|
2022-10-26 00:11:51 -06:00
|
|
|
branch.isConflicted = false;
|
2022-10-05 22:37:47 -06:00
|
|
|
branch.isModified = false;
|
2022-11-20 00:10:25 -07:00
|
|
|
branch.pristine = true;
|
2022-10-26 00:11:51 -06:00
|
|
|
branch.sha = commitSha;
|
2022-10-05 22:37:47 -06:00
|
|
|
}
|