fix: git diff no-relative#1620
fix: git diff no-relative#1620Andarist merged 1 commit intochangesets:mainfrom Netail:fix/git-relative
Conversation
🦋 Changeset detectedLatest commit: fd740d1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1620 +/- ##
=======================================
Coverage 80.66% 80.66%
=======================================
Files 54 54
Lines 2255 2255
Branches 681 680 -1
=======================================
Hits 1819 1819
Misses 431 431
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
bluwy
left a comment
There was a problem hiding this comment.
Seems fine to me. Should we also add --no-relative here too?
changesets/packages/git/src/index.ts
Line 198 in 5c2bac5
There was a problem hiding this comment.
Not sure we need this changeset. When @changesets/git is released, the version range from the CLI should pick it up with an npm update.
There was a problem hiding this comment.
To have some more specific entries in the CHANGELOG, idk something I had to do in a previous PR
There was a problem hiding this comment.
I'll leave @Andarist to decide perhaps. Usually I won't add another changeset but I'm fine either ways.
As long as the cwd is always in the root, it should be fine. (I can add it just in case) But with getChangedChangesetFilesSinceRef it first CDs into the .changesets directory, meaning the cwd is not in the root |
Ah I didn't realize that the I wonder if we should not do that and let |
Oh that's true, as the cwd is in the .changeset directory already, we could technically get rid of the filter for the files in the directory. But the cwd is already set outside of the function, so in case the function gets called without the cwd, it might still be nice to have in place |
|
Shouldn't this be --relative={relative root path from repo root}, rather than --no-relative? With --no-relative, I still get repo relative roots: This still kills |
|
Hi @Aubron Let's continue the conversation on here, as it allows us more characters & code blocks :) First of all, is this an issue you were experiencing before as well or only since 2.29.1? |
|
This is something I've seen in various old versions of the status cli, today was my opportunity to try and understand why it happens: This happens when your repo includes your .changesets directory not in the root of the repo:
export default async function getChangesets(
cwd: string,
sinceRef?: string
): Promise<Array<NewChangeset>> {
console.log("DEBUG: Getting changesets for directory: " + cwd);
let changesetBase = path.join(cwd, ".changeset");
let contents: string[];
try {
contents = await fs.readdir(changesetBase);
} catch (err) {
if ((err as any).code === "ENOENT") {
throw new Error("There is no .changeset directory in this project");
}
throw err;
}
console.log("DEBUG: Found changeset files: " + JSON.stringify(contents, null, 2));
const newChangesets = await git.getChangedChangesetFilesSinceRef({
cwd: changesetBase,
ref: sinceRef,
});
console.log("DEBUG: New changeset hashes: " + JSON.stringify(newChangesets, null, 2));this is then reduced to its first slice via const newHashes = newChangesets.map((c) => c.split("/")[1]);
console.log("DEBUG: New hashes: " + JSON.stringify(newHashes, null, 2));This causes the changeset resolution to fail, since it can't find the changesets in the set of hashes And to confirm, I think our circumstances must be similar-but-not-the-same, and touching the same files. |
|
changesets/packages/read/src/index.ts Line 17 in 5d01857 Ah yes, I might see what's wrong. The filter basically splits on "/" and takes item at position 1 (in your case "javascript"). Let me create a fix for you :) |
|
For example, I have fixed this locally to the project by patching that c.split("/")[1] to instead be the last element in the split, but I assume that solution will break in some other configuration EDIT: Thanks! Would be nice for someone who has just been touching this code to fix, I'm very worried about breaking others' configs |
|
#1636 Should do it, I think :) |
|
Note that --no-relative was introduced in git 2.28.0 so this fails in earlier versions of git such as 2.25.1 with the slightly misleading error 'Error: Failed to diff against {divergedAt}. Is {divergedAt} a valid ref?' |
If diff.relative in the git config has (accidentally) been set to true (In our case by GitHub actions/workflows), the new changesets are not correctly resolved. (as it won't include
.changeset/in the path, thus not passing the filter) This should fix it.RE: #700 (comment)
Friendly pings; @Andarist @bluwy :)