Skip to content

Commit

Permalink
fix(import): Support non-ASCII characters in file paths (#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiAnAn committed May 23, 2020
1 parent 611c38e commit c74ffa4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
@@ -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

0 comments on commit c74ffa4

Please sign in to comment.