berry icon indicating copy to clipboard operation
berry copied to clipboard

[Bug?]: `yarn version <semver> --immediate` shouldn't use Git

Open PayBas opened this issue 2 months ago • 1 comments

Self-service

  • [ ] I'd be willing to implement a fix

Describe the bug

In CI/CD pipelines for big Git repositories it's very common to use a very limited Git refspec and shallow clone depth to reduce Git clone data transfer etc.

But the simple operation of yarn version 1.2.3 -i will fail with:

Usage Error: No ancestor could be found between any of HEAD and master, origin/master, upstream/master, main, origin/main, upstream/main

As far as I can tell this is because of https://github.com/yarnpkg/berry/blob/%40yarnpkg/cli/4.10.3/packages/plugin-version/sources/versionUtils.ts#L177-L185

But why would this be necessary? When providing an explicit valid SemVer version to yarn version and using the --immediate flag, I don't see why any Git operations would be necessary.

Right now I'm having to resort to stupid workarounds like:

mv .git ..git
yarn version 1.2.3 -i
mv ..git .git

To reproduce

Git clone without any refs to master, origin/master, upstream/master, main, origin/main, upstream/main.

yarn version 1.2.3 -i

Environment

System:
  OS: Linux 5.14 Fedora Linux 42 (Container Image)
  CPU: (16) x64 INTEL(R) XEON(R) GOLD 6548N
Binaries:
  Node: 20.19.5 - /tmp/xfs-2c53a947/node
  Yarn: 4.10.3 - /tmp/xfs-2c53a947/yarn
  npm: 10.8.2 - /opt/tools/node/bin/npm

Additional context

No response

PayBas avatar Nov 07 '25 10:11 PayBas

Indeed, the yarn version implementation is a little weird. I'm a little wary of touching it outside of a major release, but rewriting it is definitely in my plans.

arcanis avatar Nov 07 '25 10:11 arcanis