-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix(utils): Use safe relative path when calling git diff #1323
Conversation
When location is the same as the cwd, return '.' instead of empty string otherwise git diff will fail refs lerna#1322
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.
Thanks for reporting this and identifying the fix!
@@ -134,7 +134,9 @@ function describeTag(ref, opts) { | |||
} | |||
|
|||
function diffSinceIn(committish, location, opts) { | |||
const formattedLocation = slash(path.relative(opts.cwd, location)); |
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 think I'd rather just leave off the -- <formattedLocation>
args if formattedLocation
is empty. The git command works the same way in that case.
diff --git a/core/git-utils/index.js b/core/git-utils/index.js
index bb11df0f..720ae11a 100644
--- a/core/git-utils/index.js
+++ b/core/git-utils/index.js
@@ -134,15 +134,17 @@ function describeTag(ref, opts) {
}
function diffSinceIn(committish, location, opts) {
+ const args = ["diff", "--name-only", committish];
const formattedLocation = slash(path.relative(opts.cwd, location));
+ if (formattedLocation) {
+ // avoid same-directory path.relative() === ""
+ args.push("--", formattedLocation);
+ }
+
log.silly("diffSinceIn", committish, formattedLocation);
- const diff = ChildProcessUtilities.execSync(
- "git",
- ["diff", "--name-only", committish, "--", formattedLocation],
- opts
- );
+ const diff = ChildProcessUtilities.execSync("git", args, opts);
log.silly("diff", diff);
return diff;
@@ -259,6 +259,21 @@ describe("GitUtilities", () => { | |||
opts | |||
); | |||
}); | |||
|
|||
it("returns list of files changed since commit at location when location equals 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.
I appreciate the test!
@Vunovati Thanks for the fix! |
@evocateur do you know when we can expect a new beta release containing the fix? I cannot reference it as a git or github dev dependency ("lerna": lerna/lerna#master") in my package.json due to this repo's project structure which prevents it from being installed that way. I can't think of any other options. Also, Thank you for merging this. |
@Vunovati Sorry, meant to release it yesterday. Just published |
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When location is the same as the cwd, return '.' instead of empty string
otherwise git diff will fail
refs #1322
Description
Using path.relative is not enough for git params as when comparing two identical paths (
path.relative
) it will return an empty stringMotivation and Context
Fixes #1322
How Has This Been Tested?
I added a test case and was not able to reproduce it as in #1322 anymore
Types of changes
Checklist: