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
Get correct absolute path of changed files when .changeset/
is not in the root of the repository
#770
Get correct absolute path of changed files when .changeset/
is not in the root of the repository
#770
Conversation
🦋 Changeset detectedLatest commit: 08770b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 08770b0:
|
Ok, I think I understand what you are saying... but we would need a test case for this change, ideally one that would involve some changesets command, or at least a full user story that involves Changesets. |
…/changesets into fix-changed-since-absolute-path
Sure, I added a unit test that asserts the changed behavior. Not sure how adding a Changeset command test case would be beneficial here considering that the git functions are simply mocked in those test files. Would appreciate any pointers if you have something else in mind |
I was just wondering how exactly this has manifested in a bug in Changesets. Did |
Exactly,
When running |
cwd
.changeset/
is not in the root of the repository
packages/git/src/index.ts
Outdated
if (code !== 0) { | ||
return cwd; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a defensive check or perhaps this can sometimes happen for some legitimate reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt It'll fail, but if it does, fallback to the previous behavior
Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
packages/git/src/index.ts
Outdated
if (code !== 0) { | ||
return cwd; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the docs:
Show the (by default, absolute) path of the top-level directory of the working tree. If there is no working tree, report an error.
So I think that we should throw an error here:
if (code !== 0) { | |
return cwd; | |
} | |
if (code !== 0) { | |
throw new Error(gitCmd.stderr.toString()); | |
} |
Where for us this actually shouldn't ever throw, but this function is quite generic - so if we ever expose it then somebody could call it with cwd
outside of a git repo.
I think that it's better to throw here to raise potential issues early, rather than to swallow the error and lead to undetermined behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable
When creating absolute paths from changed files, we assume
cwd
is the repository root but that is not always the case like when .changesets is set in a subfolder. Instead we can ask git for the repository root and create correct absolute path of the files returned fromgit diff