diff --git a/action/dist/index.js b/action/dist/index.js index 5e2c6d4..ac3d754 100644 --- a/action/dist/index.js +++ b/action/dist/index.js @@ -8394,7 +8394,7 @@ exports.main = function (_a) { folder = path.resolve(process.cwd(), config.folder); log.log("##[info] Copying all files from " + folder); // TODO: replace this copy with a node implementation - return [4 /*yield*/, exports.exec("cp -rT " + folder + "/ ./", { log: log, env: childEnv, cwd: REPO_TEMP })]; + return [4 /*yield*/, exports.exec("cp -rT \"" + folder + "\"/ ./", { log: log, env: childEnv, cwd: REPO_TEMP })]; case 26: // TODO: replace this copy with a node implementation _j.sent(); diff --git a/action/src/index.ts b/action/src/index.ts index 4749f55..e73a3b5 100644 --- a/action/src/index.ts +++ b/action/src/index.ts @@ -521,7 +521,7 @@ export const main = async ({ const folder = path.resolve(process.cwd(), config.folder); log.log(`##[info] Copying all files from ${folder}`); // TODO: replace this copy with a node implementation - await exec(`cp -rT ${folder}/ ./`, { log, env: childEnv, cwd: REPO_TEMP }); + await exec(`cp -rT "${folder}"/ ./`, { log, env: childEnv, cwd: REPO_TEMP }); await exec(`git add -A .`, { log, env: childEnv, cwd: REPO_TEMP }); const message = config.message .replace(/\{target\-branch\}/g, config.branch) diff --git a/action/test/specs/__snapshots__/ssh-existing-branch-folder-space.spec.ts.snap b/action/test/specs/__snapshots__/ssh-existing-branch-folder-space.spec.ts.snap new file mode 100644 index 0000000..dff6607 --- /dev/null +++ b/action/test/specs/__snapshots__/ssh-existing-branch-folder-space.spec.ts.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Spaces in folder names are correctly handled 1`] = ` +"msg:Update master to output generated at +tree:3f97adec519b4ce0c5950da8eb91bd2939d20689 +author:s0 +msg:initial +tree:c1cde76c408d7c8cb6956f35f1e4853366340aec +author:Test User " +`; diff --git a/action/test/specs/ssh-existing-branch-folder-space.spec.ts b/action/test/specs/ssh-existing-branch-folder-space.spec.ts new file mode 100644 index 0000000..262a106 --- /dev/null +++ b/action/test/specs/ssh-existing-branch-folder-space.spec.ts @@ -0,0 +1,66 @@ +import * as path from 'path'; + +import * as util from '../util'; + +const REPO_DIR = path.join( + util.REPOS_DIR, + 'ssh-existing-branch-folder-space.git' +); +const WORK_DIR = path.join(util.DATA_DIR, 'ssh-existing-branch-folder-space'); +const REPO_CLONE_DIR = path.join(WORK_DIR, 'clone'); +const DATA_DIR = path.join(WORK_DIR, 'data with space'); + +it('Spaces in folder names are correctly handled', async () => { + // Create empty repo + await util.mkdir(REPO_DIR); + await util.wrappedExec('git init --bare', { cwd: REPO_DIR }); + + // Clone repo, and create an initial commit + await util.mkdir(WORK_DIR); + await util.wrappedExec(`git clone "${REPO_DIR}" clone`, { cwd: WORK_DIR }); + await util.writeFile(path.join(REPO_CLONE_DIR, 'initial'), 'foobar'); + await util.wrappedExec(`git add -A .`, { cwd: REPO_CLONE_DIR }); + await util.wrappedExec(`git config user.name "Test User"`, { + cwd: REPO_CLONE_DIR, + }); + await util.wrappedExec(`git config user.email "test@example.com"`, { + cwd: REPO_CLONE_DIR, + }); + await util.wrappedExec(`git commit -m initial`, { cwd: REPO_CLONE_DIR }); + await util.wrappedExec(`git push origin master`, { cwd: REPO_CLONE_DIR }); + + // Create dummy data + await util.mkdir(DATA_DIR); + await util.mkdir(path.join(DATA_DIR, 'dummy foo')); + await util.writeFile(path.join(DATA_DIR, 'dummy foo', 'baz'), 'foobar'); + await util.writeFile(path.join(DATA_DIR, 'dummy foo', '.bat'), 'foobar'); + + // Run Action + await util.runWithGithubEnv( + path.basename(__filename), + { + REPO: 'ssh://git@git-ssh/git-server/repos/ssh-existing-branch-folder-space.git', + BRANCH: 'master', + FOLDER: DATA_DIR, + SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(), + KNOWN_HOSTS_FILE: util.KNOWN_HOSTS, + }, + 's0/test', + {}, + 's0' + ); + + // Check that the log of the repo is as expected + // (check tree-hash, commit message, and author) + const log = ( + await util.exec( + 'git log --pretty="format:msg:%s%ntree:%T%nauthor:%an <%ae>" master', + { + cwd: REPO_DIR, + } + ) + ).stdout; + const sha = await util.getRepoSha(); + const cleanedLog = log.replace(sha, ''); + expect(cleanedLog).toMatchSnapshot(); +});