-
Notifications
You must be signed in to change notification settings - Fork 494
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
Changes from 6 commits
96095b8
6b7f290
2c36da3
a7ed53d
adc0087
a5ac08a
08770b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@changesets/cli": patch | ||
--- | ||
|
||
`changeset add` and `changeset status` should now properly handle the situation where Changesets are managed from a directory different than the root of the repository. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@changesets/git": patch | ||
--- | ||
|
||
`getChangedFilesSince` and `getChangedPackagesSinceRef` will now return the correct absolute paths of the changed files when the passed `cwd` is different from the repository's root. |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -182,6 +182,22 @@ export async function isRepoShallow({ cwd }: { cwd: string }) { | |||||||||||||
export async function deepenCloneBy({ by, cwd }: { by: number; cwd: string }) { | ||||||||||||||
await spawn("git", ["fetch", `--deepen=${by}`], { cwd }); | ||||||||||||||
} | ||||||||||||||
async function getRepoRoot({ cwd }: { cwd: string }) { | ||||||||||||||
const { stdout, code } = await spawn( | ||||||||||||||
"git", | ||||||||||||||
["rev-parse", "--show-toplevel"], | ||||||||||||||
{ cwd } | ||||||||||||||
); | ||||||||||||||
|
||||||||||||||
if (code !== 0) { | ||||||||||||||
return cwd; | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. according to the docs:
So I think that we should throw an error here:
Suggested change
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 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 commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable |
||||||||||||||
|
||||||||||||||
return stdout | ||||||||||||||
.toString() | ||||||||||||||
.trim() | ||||||||||||||
.replace(/\n|\r/g, ""); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
export async function getChangedFilesSince({ | ||||||||||||||
cwd, | ||||||||||||||
|
@@ -207,7 +223,9 @@ export async function getChangedFilesSince({ | |||||||||||||
.split("\n") | ||||||||||||||
.filter(a => a); | ||||||||||||||
if (!fullPath) return files; | ||||||||||||||
return files.map(file => path.resolve(cwd, file)); | ||||||||||||||
|
||||||||||||||
const repoRoot = await getRepoRoot({ cwd }); | ||||||||||||||
return files.map(file => path.resolve(repoRoot, file)); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// below are less generic functions that we use in combination with other things we are doing | ||||||||||||||
|
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