Skip to content

Commit

Permalink
Merge pull request #41 from s0/folder-spaces
Browse files Browse the repository at this point in the history
Handle folders with spaces
  • Loading branch information
s0 authored May 13, 2021
2 parents 0257a5f + 52f657f commit 254bf68
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion action/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <sha>
tree:3f97adec519b4ce0c5950da8eb91bd2939d20689
author:s0 <[email protected]>
msg:initial
tree:c1cde76c408d7c8cb6956f35f1e4853366340aec
author:Test User <[email protected]>"
`;
66 changes: 66 additions & 0 deletions action/test/specs/ssh-existing-branch-folder-space.spec.ts
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"`, {
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, '<sha>');
expect(cleanedLog).toMatchSnapshot();
});

0 comments on commit 254bf68

Please sign in to comment.