diff --git a/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/package.json b/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/package.json new file mode 100644 index 0000000000..15176de65f --- /dev/null +++ b/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/package.json @@ -0,0 +1,3 @@ +{ + "name": "files-with-non-ascii-char" +} diff --git "a/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/\346\252\224\346\241\210" "b/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/\346\252\224\346\241\210" new file mode 100644 index 0000000000..6b584e8ece --- /dev/null +++ "b/commands/import/__tests__/__fixtures__/files-with-non-ascii-char/\346\252\224\346\241\210" @@ -0,0 +1 @@ +content \ No newline at end of file diff --git a/commands/import/__tests__/import-command.test.js b/commands/import/__tests__/import-command.test.js index bf9e0f9f2d..5fe50c8080 100644 --- a/commands/import/__tests__/import-command.test.js +++ b/commands/import/__tests__/import-command.test.js @@ -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"); diff --git a/commands/import/index.js b/commands/import/index.js index 96c1024832..f3d8ff17f8 100644 --- a/commands/import/index.js +++ b/commands/import/index.js @@ -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) {