Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 18 "Failed to find where HEAD diverged from origin/master" #1055

Open
ivanbanov opened this issue Jan 5, 2023 · 13 comments
Open

Node 18 "Failed to find where HEAD diverged from origin/master" #1055

ivanbanov opened this issue Jan 5, 2023 · 13 comments

Comments

@ivanbanov
Copy link

We use changeset on CI to check the bump plan. It was working as expected on Node 14.
After upgrading to Node 18 the script fails with the following error

Failed to find where HEAD diverged from origin/master. Does origin/master exist?

While debugging it seems like everything is working as expected from the git side, but somehow the status fails internally

npx changeset status --since=origin/master

The logs from the debug

git merge-base master HEAD
6344833a5c76c7b5982061c82a7b064dc971510f

git merge-base origin/master HEAD
6344833a5c76c7b5982061c82a7b064dc971510f

git branch -r
  origin/master
  origin/mds-000-fix-changeset

git branch
  master
* mds-000-fix-changeset

@changeset/git getDivergedCommit()
6344833a5c76c7b5982061c82a7b064dc971510f

status
  stdout: '',
  stderr: '🦋  \x1B[31merror\x1B[39m Error: Failed to find where HEAD diverged from origin/master. Does origin/master exist?\n' +
    '🦋  \x1B[31merror\x1B[39m     at getDivergedCommit (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+git@2.0.0/node_modules/@changesets/git/dist/git.cjs.dev.js:66:11)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async Object.getChangedChangesetFilesSinceRef (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+git@2.0.0/node_modules/@changesets/git/dist/git.cjs.dev.js:221:24)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async filterChangesetsSinceRef (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+read@0.5.9/node_modules/@changesets/read/dist/read.cjs.dev.js:107:25)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async Object.getChangesets [as default] (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+read@0.5.9/node_modules/@changesets/read/dist/read.cjs.dev.js:130:16)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async Object.getReleasePlan [as default] (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+get-release-plan@3.0.16/node_modules/@changesets/get-release-plan/dist/get-release-plan.cjs.dev.js:70:22)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async getStatus (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+cli@2.26.0/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1165:23)\n' +
    '🦋  \x1B[31merror\x1B[39m     at async run$2 (/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1/node_modules/.pnpm/@changesets+cli@2.26.0/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1446:11)\n',

Im scratching my head trying to figure out what could possibly be wrong, any clue?

@williamlmao
Copy link

williamlmao commented Jan 6, 2023

I've got the same issue when trying to publish from the turborepo design system repo https://vercel.com/templates/react/turborepo-design-system

🦋  error Error: Failed to find where HEAD diverged from master. Does master exist?
🦋  error     at getDivergedCommit (/Users/wl/personalprojects/turborepo-design-system/node_modules/@changesets/git/dist/git.cjs.dev.js:66:11)
🦋  error     at async getChangedFilesSince (/Users/wl/personalprojects/turborepo-design-system/node_modules/@changesets/git/dist/git.cjs.dev.js:198:22)
🦋  error     at async Object.getChangedPackagesSinceRef (/Users/wl/personalprojects/turborepo-design-system/node_modules/@changesets/git/dist/git.cjs.dev.js:239:24)
🦋  error     at async add (/Users/wl/personalprojects/turborepo-design-system/node_modules/@changesets/cli/dist/cli.cjs.dev.js:527:29)
🦋  error     at async run$2 (/Users/wl/personalprojects/turborepo-design-system/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1330:5)

but simply renaming the branch to master worked for me
git branch -m main master

@Andarist
Copy link
Member

Andarist commented Jan 6, 2023

@ivanbanov can you check what cwd is used by Changesets here?

@williamlmao most likely you can fix this by using this value in your .changeset/config.json:

{
  "baseBranch": "main"
}

@ivanbanov
Copy link
Author

@Andarist I just got the logs

Node 14 process.cwd()
/var/lib/bamboo-home/local-working-dir/2719746/RTB-DEST391-JOB1

Node 18 process.cwd()
/var/lib/bamboo-home/local-working-dir/131073/RTB-DEST391-JOB1

Note, it works properly on my Mac with Node18

@ivanbanov
Copy link
Author

I thought I should also add my changeset config here, just in case

.changeset/config.json

{
  "$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json",
  "changelog": "@changesets/cli/changelog",
  "commit": false,
  "linked": [],
  "access": "restricted",
  "baseBranch": "origin/master",
  "ignore": [],
  "updateInternalDependencies": "patch",
  "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
    "updateInternalDependents": "always"
  },
  "snapshot": { "useCalculatedVersion": true }
}

@coreybruyere
Copy link

@williamlmao where are you changing your branch to master. I've cloned turbo-repo-designsystem and am having the same issue.

@sscaff1
Copy link

sscaff1 commented Feb 22, 2023

Locally this ran fine for me. In a gitlab pipeline, this was failing to run. Changing baseBranch to "origin/main" resolved my issue (previously it was "main").

@ben-laird
Copy link

This is failing for me in CI where I check if a PR has a changeset in it. I've tried pretty much all the solutions provided in this issue, like changing the baseBranch property to "main" or "origin/main" to changing it in the command running in ci. My default "master branch" whenever I make a new git repository locally is "main", so I haven't tried changing the name of any branches because there's no need to for my use case. Is there something I'm not seeing?

.github/workflows/pr.yml:

name: Pull Request CI

on:
  pull_request:
    branches:
      - main

jobs:
  pr-check:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16.x.x]
    steps:
      - uses: actions/checkout@v3
      - uses: pnpm/action-setup@v2
        with:
          version: 7
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: "pnpm"
      - name: Install Dependencies
        run: pnpm install

      - name: Check if PR has Changeset
        run: pnpm changeset status

.changeset/config.json:

{
  "$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
  "changelog": "@changesets/cli/changelog",
  "baseBranch": "main",
  "commit": false,
  "fixed": [],
  "linked": [],
  "access": "public",
  "updateInternalDependencies": "patch",
  "ignore": [],
  "privatePackages": { "version": true, "tag": true }
}

Error/Call Stack (some directories replaced by <other-folders> for brevity/security):

🦋  error Error: Failed to find where HEAD diverged from main. Does main exist?
🦋  error     at getDivergedCommit (/home/runner/work/<other-folders>/node_modules/.pnpm/@changesets+git@2.0.0/node_modules/@changesets/git/dist/git.cjs.dev.js:66:11)
🦋  error     at async getChangedFilesSince (/home/runner/work/<other-folders>/node_modules/.pnpm/@changesets+git@2.0.0/node_modules/@changesets/git/dist/git.cjs.dev.js:198:22)
🦋  error     at async Object.getChangedPackagesSinceRef (/home/runner/work/<other-folders>/node_modules/.pnpm/@changesets+git@2.0.0/node_modules/@changesets/git/dist/git.cjs.dev.js:239:24)
🦋  error     at async getStatus (/home/runner/work/<other-folders>/node_modules/.pnpm/@changesets+cli@2.26.0/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1170:27)
🦋  error     at async run$2 (/home/runner/work/<other-folders>/node_modules/.pnpm/@changesets+cli@2.26.0/node_modules/@changesets/cli/dist/cli.cjs.dev.js:1446:11)
Error: Process completed with exit code 1.

@mckelveygreg
Copy link

Thankfully i don't need to run this in a node 18 environment, but other steps of my code do. So setting my builder for node-16.18.0 is at least a work around

@davidwincent
Copy link

I thought I should also add my changeset config here, just in case

.changeset/config.json

{
  "$schema": "https://unpkg.com/@changesets/config@1.6.3/schema.json",
  "changelog": "@changesets/cli/changelog",
  "commit": false,
  "linked": [],
  "access": "restricted",
  "baseBranch": "origin/master",
  "ignore": [],
  "updateInternalDependencies": "patch",
  "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
    "updateInternalDependents": "always"
  },
  "snapshot": { "useCalculatedVersion": true }
}

This makes much more sense than the default config. You can't always assume local branches are up to date.

@thundermiracle
Copy link

Checkout with full history and set baseBranch to origin/main will solve this problem. Hope help someone.

In your ci.yaml

    steps:
      - uses: actions/checkout@v3
        with:
          # check out full history
          fetch-depth: 0

      # set baseBranch to origin/main
      - run: pnpm changeset status --since origin/main

@voronin-ivan
Copy link

In case the options above don't help you, try to use the last published tag:

last_tag=$(git describe --tags --abbrev=0)
pnpm changeset status --since $last_tag

@mborysenko
Copy link

I'm getting the same error message when I introduce changes during build job, for example I have overrides that I copy to the main folder during job execution, basically those are uncommitted changes. If I do that locally and commit and push changes to the branch, issue is gone.

@mborysenko
Copy link

I'm getting the same error message when I introduce changes during build job, for example I have overrides that I copy to the main folder during job execution, basically those are uncommitted changes. If I do that locally and commit and push changes to the branch, issue is gone.

BTW, job is running on node 16.13.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests