Tucker McKnight <tmcknight@instructure.com> | Sat Sep 12 2026
Use `git cherry` to determine which commits are/are not in main branch
188 189 190 191 192 193
return getRefShaAndFileList(tag, 'tag', repoName, repoLocation)
}))
const branchesWithCompareToInfo: Repository['branches'] = branches.map((branch) => {
const branchDescription = branchesAndTags.branches.find(branchToAdd => branchToAdd.name === branch.name)
const compareTo = branchDescription.compareTo || reposConfig.repos[repoName].defaultBranch
const compareToBranch = branches.find((test) => test.name === compareTo)188 189 190 191 192 193
return getRefShaAndFileList(tag, 'tag', repoName, repoLocation)
}))
const branchesWithCompareToInfo: Repository['branches'] = await Promise.all(branches.map(async (branch) => {
const branchDescription = branchesAndTags.branches.find(branchToAdd => branchToAdd.name === branch.name)
const compareTo = branchDescription.compareTo || reposConfig.repos[repoName].defaultBranch
const compareToBranch = branches.find((test) => test.name === compareTo)209 210 211 212 213 214 215 216 217 218 219 220
// At this point, we have all commits in the compareTo branch in one set, and
// all commits from this branch in another set.
const onlyInThisBranch = Array.from(thisBranchCommits).filter((thisBranchCommit) => {
return !commits.get(thisBranchCommit).isMerge && !compareToBranchCommits.has(thisBranchCommit)
}).length
const onlyInCompareToBranch = Array.from(compareToBranchCommits).filter((compareToBranchCommit) => {
return !commits.get(compareToBranchCommit).isMerge && !thisBranchCommits.has(compareToBranchCommit)
}).length
const compareToInfo = {
ahead: onlyInThisBranch,
behind: onlyInCompareToBranch,209 210 211 212 213 214 215 216 217 218
// At this point, we have all commits in the compareTo branch in one set, and
// all commits from this branch in another set.
const onlyInThisBranch = (await exec(`git -C ${repoLocation} cherry ${compareTo} ${branch.name}`))
.stdout.split('\n').filter(line => !line.startsWith('-') && line !== '').length
const onlyInCompareToBranch = (await exec(`git -C ${repoLocation} cherry ${branch.name} ${compareTo}`))
.stdout.trim().split('\n').filter(line => !line.startsWith('-') && line !== '').length
const compareToInfo = {
ahead: onlyInThisBranch,
behind: onlyInCompareToBranch,223 224 225 226 227 228
}
return {...branch, ...compareToInfo}
})
cachedRepos.push({
name: repoName,223 224 225 226 227 228
}
return {...branch, ...compareToInfo}
}))
cachedRepos.push({
name: repoName,