Skip to content
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(import): Support non-ASCII characters in file paths #2441

Merged
merged 1 commit into from May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,3 @@
{
"name": "files-with-non-ascii-char"
}
@@ -0,0 +1 @@
content
33 changes: 33 additions & 0 deletions commands/import/__tests__/import-command.test.js
Expand Up @@ -129,6 +129,39 @@ describe("ImportCommand", () => {
})
));

it("supports filepaths that have non-ascii char within the external repo", async () =>
Promise.all(
// running the same test with and without --flatten
[true, false].map(async shouldFlatten => {
const [testDir, externalDir] = await Promise.all([
initFixture("basic"),
initFixture("files-with-non-ascii-char", "Init external commit"),
]);
const newPackagePath = path.join(testDir, "packages", path.basename(externalDir));

await fs.copy(path.join(externalDir, "檔案"), path.join(externalDir, "檔案-copy"));
await gitAdd(externalDir, "檔案-copy");
await gitCommit(externalDir, "copy");

await fs.move(path.join(externalDir, "檔案"), path.join(externalDir, "檔案-rename"));
await gitAdd(externalDir, "檔案", "檔案-rename");
await gitCommit(externalDir, "rename");

const copyFilePath = path.join(newPackagePath, "檔案-copy");
const renameFilePath = path.join(newPackagePath, "檔案-rename");

if (shouldFlatten) {
await lernaImport(testDir)(externalDir, "--flatten");
} else {
await lernaImport(testDir)(externalDir);
}

expect(await lastCommitInDir(testDir)).toBe("rename");
expect(await pathExists(copyFilePath)).toBe(true);
expect(await pathExists(renameFilePath)).toBe(true);
})
));

it("skips empty patches with --flatten", async () => {
const [testDir, externalDir] = await initBasicFixtures();
const filePath = path.join(externalDir, "file.txt");
Expand Down
10 changes: 5 additions & 5 deletions commands/import/index.js
Expand Up @@ -189,11 +189,11 @@ class ImportCommand extends Command {
// to all affected files. This moves the git history for the entire
// external repository into the package subdirectory, commit by commit.
return patch
.replace(/^([-+]{3} COMPARE_[AB])/gm, replacement)
.replace(/^(diff --git COMPARE_A)/gm, replacement)
.replace(/^(diff --git (?! COMPARE_B\/).+ COMPARE_B)/gm, replacement)
.replace(/^(copy (from|to)) /gm, `$1 ${formattedTarget}/`)
.replace(/^(rename (from|to)) /gm, `$1 ${formattedTarget}/`);
.replace(/^([-+]{3} "?COMPARE_[AB])/gm, replacement)
.replace(/^(diff --git "?COMPARE_A)/gm, replacement)
.replace(/^(diff --git (?! "?COMPARE_B\/).+ "?COMPARE_B)/gm, replacement)
.replace(/^(copy (from|to)) ("?)/gm, `$1 $3${formattedTarget}/`)
.replace(/^(rename (from|to)) ("?)/gm, `$1 $3${formattedTarget}/`);
}

getGitUserFromSha(sha) {
Expand Down