Skip to content

Commit 1b76c02

Browse files
committed
check merge base
1 parent ff73e76 commit 1b76c02

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tools/npmono/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const router = t.router({
1111
.meta({default: true})
1212
.input(PublishInput) //
1313
.mutation(async ({input}) => {
14-
return publish(input)
14+
await publish(input)
1515
}),
1616

1717
prebuilt: t.procedure

tools/npmono/src/publish.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export const publish = async (input: PublishInput) => {
435435
}
436436

437437
if (leftRef && rightRef) {
438-
await execa('git', ['diff', rightRef, leftRef, '--', '.'], {
438+
await execa('git', ['diff', leftRef, rightRef, '--', '.'], {
439439
cwd: pkg.path,
440440
stdout: {
441441
file: path.join(changesFolder, 'source.diff'),
@@ -684,7 +684,7 @@ function getWorkspaceRoot() {
684684

685685
/** "Pessimistic" comparison ref. Tries to use the registry package.json's `git.sha` property, and uses the first ever commit to the package folder if that can't be found. */
686686
async function getPackageLastPublishRef(pkg: Pkg) {
687-
const packageJson = loadRHSPackageJson(pkg)
687+
const packageJson = loadLHSPackageJson(pkg)
688688
return await getPackageJsonGitSha(pkg, packageJson)
689689
}
690690

@@ -768,9 +768,17 @@ async function getPackageRevList(pkg: Pkg) {
768768
const localRef = pkg.shas.right
769769
const {stdout} = await execa(
770770
'git',
771-
['rev-list', '--ancestry-path', `${fromRef}..${localRef}`, '--format=oneline', '--abbrev-commit', '--', '.'],
771+
['rev-list', '--ancestry-path', `${fromRef}...${localRef}`, '--format=oneline', '--abbrev-commit', '--', '.'],
772772
{cwd: pkg.path},
773773
)
774+
775+
const {stdout: mergeBase} = await execa('git', ['merge-base', fromRef, localRef])
776+
let mergeBaseNote = ''
777+
if (mergeBase !== fromRef) {
778+
const {stdout: mergeBaseSummary} = await execa('git', ['log', '-n', '1', '--format=%h %s (%ad)', mergeBase])
779+
mergeBaseNote = `\n🚧🚧 NOTE 🚧🚧: ${localRef} (current) is not a descendant of ${fromRef} (last publish). The last publish may have beendone on a separate branch. The merge base is:\n${mergeBaseSummary}`
780+
}
781+
774782
const {stdout: uncommitedChanges} = await execa('git', ['status', '--porcelain', '--', '.'], {
775783
cwd: pkg.path,
776784
})
@@ -783,11 +791,14 @@ async function getPackageRevList(pkg: Pkg) {
783791
commitBullets.length > 0 && `<h3 data-commits>Commits</h3>\n`,
784792
...commitBullets,
785793
uncommitedChanges.trim() && 'Uncommitted changes:\n' + uncommitedChanges,
794+
mergeBaseNote,
786795
]
787796
return {
788797
// commitComparisonString,
789798
// versionComparisonString,
790-
markdown: sections.filter(Boolean).join('\n').trim() || `No ${pkg.name} changes since last publish.`,
799+
markdown:
800+
sections.filter(Boolean).join('\n').trim() ||
801+
`Unable to list commits to ${pkg.name} between ${fromRef} (last publish) and ${localRef} (current). Was ${fromRef} on a different branch?`,
791802
}
792803
}
793804

0 commit comments

Comments
 (0)