Skip to content

fix(git): wrong changeset file commit - #2277

Merged
bluwy merged 7 commits into
changesets:mainfrom
trueberryless:fix/wrong-changeset-file
Sep 3, 2026
Merged

bluwy merged 7 commits into
changesets:mainfrom
trueberryless:fix/wrong-changeset-file

Conversation

@trueberryless

@trueberryless trueberryless commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes a regression added here, where similar changeset files can lead to wrong commit SHA lookups if the file content is very similar.

The fix adds the C (copy) git type to the --diff-filter option, which means that two changeset files will not be mixed up by git just because they have similar content.

@changeset-bot

changeset-bot Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ead294f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@changesets/git Patch
@changesets/apply-release-plan Patch
@changesets/cli Patch
@changesets/read Patch
@changesets/release-utils Patch
@changesets/get-release-plan Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for changesets ready!

Name Link
🔨 Latest commit ead294f
🔍 Latest deploy log https://app.netlify.com/projects/changesets/deploys/6a96b382fa8a4500080b9d6a
😎 Deploy Preview https://deploy-preview-2277--changesets.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@trueberryless trueberryless changed the title test(git): reproduce bug in tests fix(git): wrong changeset file commit Aug 30, 2026
@trueberryless
trueberryless marked this pull request as ready for review August 30, 2026 10:11
@codecov

codecov Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.57%. Comparing base (a0a4dc6) to head (ead294f).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2277   +/-   ##
=======================================
  Coverage   84.57%   84.57%           
=======================================
  Files          80       80           
  Lines        3177     3177           
  Branches      894      894           
=======================================
  Hits         2687     2687           
  Misses        433      433           
  Partials       57       57           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/git/src/index.ts
@bluwy

bluwy commented Aug 31, 2026

Copy link
Copy Markdown
Member

This PR also fixes another issue by adding the -- separator to the git log command to tell git to look for the history of a deleted file (because before this command runs, the version command has already deleted the changeset files in the checkout project).

Can you elaborate on this? We should be capturing the commits first before deleting the files. With the -- flag it looks like it can match files not in the current branch, which we only want to match on the current branch.

@trueberryless

Copy link
Copy Markdown
Contributor Author

Can you elaborate on this? We should be capturing the commits first before deleting the files.

Ah true, I confused the method order. Nonetheless, I strongly recommend using the -- separator to prevent confusion with other parameters, as the docs mention.

With the -- flag it looks like it can match files not in the current branch, which we only want to match on the current branch.

Where exactly does it mention this?

@bluwy

bluwy commented Sep 1, 2026

Copy link
Copy Markdown
Member

Where exactly does it mention this?

I tested it manually. If you delete README.md for example, if you do git log README.md, it fails. But if git log -- README.md it passes.

When it fails, it also logs this which kinda explains it ("path not in the working tree"):

fatal: ambiguous argument 'README.md': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

@trueberryless

Copy link
Copy Markdown
Contributor Author

I tested it manually. If you delete README.md for example, if you do git log README.md, it fails. But if git log -- README.md it passes.

When it fails, it also logs this which kinda explains it ("path not in the working tree"):

fatal: ambiguous argument 'README.md': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Gotcha. I think the error happens because git doesn't fully understand that we want to pass the path argument (as the file doesn't exist). It interpretes our path as a revision, but this is no revision. So adding -- makes sure that git always knows it's a path.

I initially included it because I also thought that the command would fail with the error you showed. However, since we get the commits before deleting, I think it isn't strictly necessarily to include the -- separator currently. It is just more fragile if we don't include it.

So IMHO we should keep the -- separator, but im also open to removing it 👍

@bluwy

bluwy commented Sep 1, 2026

Copy link
Copy Markdown
Member

I'd prefer removing -- so the command only works on paths in the current working tree. If you prefer to use --, we need a flag or something that makes sure to only return if the path exists in the current working tree. If there's no way to do that, we should remove --.

@trueberryless

Copy link
Copy Markdown
Contributor Author

I removed it for now because if you use --, git searches the commits even when the file was deleted (outside of current working tree). However, one potential problem without the separator is: If a branch exists with the exact name of the path we pass, git would show the history of the branch instead of the path. This is very unlikely I think because I never saw some branch name that includes .md. Nonetheless, it's worth considering. But removing it is fine for me, so this PR focuses on the actual bug only 👍

@bluwy
bluwy added this pull request to the merge queue Sep 3, 2026
Merged via the queue into changesets:main with commit 059f70a Sep 3, 2026
18 checks passed
expect(commits).toEqual([originalCommit]);
});

it("reads the SHA of a file-add when tweaked then moved to pre", async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love those tests ❤️

@trueberryless
trueberryless deleted the fix/wrong-changeset-file branch September 4, 2026 07:06
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

Successfully merging this pull request may close these issues.

User misattributed in CHANGELOG using @changesets/changelog-github

4 participants