Skip to content

Commit

Permalink
Cherry diff with merge base instead of default branch (#36)
Browse files Browse the repository at this point in the history
* Use merge base to avoid false positive

* Fix args
  • Loading branch information
CuadrosNicolas authored Jan 22, 2024
1 parent 8a7aeb6 commit 66af9ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export default function (program) {

// TODO: If a file has been provided, then we can skip the merge base logic
if (!inputFile) {
await git.checkout(await git.getDefaultBranchName())
const defaultBranchName = await git.getDefaultBranchName()
const baseBranchCommit = await git.getMergeBase(initialBranch, defaultBranchName)
await git.checkout(baseBranchCommit)
previousOccurrences = await findOccurrences({
configuration,
files: await getFiles(),
Expand Down
5 changes: 5 additions & 0 deletions src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export const getDefaultBranchName = async () => {
return defaultBranch.replace('origin/', '').trim()
}

export const getMergeBase = async (currentBranchName, defaultBranchName) => {
const mergeBase = (await git(`merge-base ${currentBranchName} ${defaultBranchName}`)).toString()
return mergeBase.trim()
}

export const authorName = async (sha) => (await git(`show ${sha} --format=%an --no-patch`))[0]

export const authorEmail = async (sha) => (await git(`show ${sha} --format=%ae --no-patch`))[0]
Expand Down

0 comments on commit 66af9ff

Please sign in to comment.