Skip to content

Commit 254bf68

Browse files
authored
Merge pull request #41 from s0/folder-spaces
Handle folders with spaces
2 parents 0257a5f + 52f657f commit 254bf68

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

Diff for: action/dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8394,7 +8394,7 @@ exports.main = function (_a) {
83948394
folder = path.resolve(process.cwd(), config.folder);
83958395
log.log("##[info] Copying all files from " + folder);
83968396
// TODO: replace this copy with a node implementation
8397-
return [4 /*yield*/, exports.exec("cp -rT " + folder + "/ ./", { log: log, env: childEnv, cwd: REPO_TEMP })];
8397+
return [4 /*yield*/, exports.exec("cp -rT \"" + folder + "\"/ ./", { log: log, env: childEnv, cwd: REPO_TEMP })];
83988398
case 26:
83998399
// TODO: replace this copy with a node implementation
84008400
_j.sent();

Diff for: action/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export const main = async ({
521521
const folder = path.resolve(process.cwd(), config.folder);
522522
log.log(`##[info] Copying all files from ${folder}`);
523523
// TODO: replace this copy with a node implementation
524-
await exec(`cp -rT ${folder}/ ./`, { log, env: childEnv, cwd: REPO_TEMP });
524+
await exec(`cp -rT "${folder}"/ ./`, { log, env: childEnv, cwd: REPO_TEMP });
525525
await exec(`git add -A .`, { log, env: childEnv, cwd: REPO_TEMP });
526526
const message = config.message
527527
.replace(/\{target\-branch\}/g, config.branch)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Spaces in folder names are correctly handled 1`] = `
4+
"msg:Update master to output generated at <sha>
5+
tree:3f97adec519b4ce0c5950da8eb91bd2939d20689
6+
author:s0 <s0@users.noreply.github.com>
7+
msg:initial
8+
tree:c1cde76c408d7c8cb6956f35f1e4853366340aec
9+
author:Test User <test@example.com>"
10+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import * as path from 'path';
2+
3+
import * as util from '../util';
4+
5+
const REPO_DIR = path.join(
6+
util.REPOS_DIR,
7+
'ssh-existing-branch-folder-space.git'
8+
);
9+
const WORK_DIR = path.join(util.DATA_DIR, 'ssh-existing-branch-folder-space');
10+
const REPO_CLONE_DIR = path.join(WORK_DIR, 'clone');
11+
const DATA_DIR = path.join(WORK_DIR, 'data with space');
12+
13+
it('Spaces in folder names are correctly handled', async () => {
14+
// Create empty repo
15+
await util.mkdir(REPO_DIR);
16+
await util.wrappedExec('git init --bare', { cwd: REPO_DIR });
17+
18+
// Clone repo, and create an initial commit
19+
await util.mkdir(WORK_DIR);
20+
await util.wrappedExec(`git clone "${REPO_DIR}" clone`, { cwd: WORK_DIR });
21+
await util.writeFile(path.join(REPO_CLONE_DIR, 'initial'), 'foobar');
22+
await util.wrappedExec(`git add -A .`, { cwd: REPO_CLONE_DIR });
23+
await util.wrappedExec(`git config user.name "Test User"`, {
24+
cwd: REPO_CLONE_DIR,
25+
});
26+
await util.wrappedExec(`git config user.email "test@example.com"`, {
27+
cwd: REPO_CLONE_DIR,
28+
});
29+
await util.wrappedExec(`git commit -m initial`, { cwd: REPO_CLONE_DIR });
30+
await util.wrappedExec(`git push origin master`, { cwd: REPO_CLONE_DIR });
31+
32+
// Create dummy data
33+
await util.mkdir(DATA_DIR);
34+
await util.mkdir(path.join(DATA_DIR, 'dummy foo'));
35+
await util.writeFile(path.join(DATA_DIR, 'dummy foo', 'baz'), 'foobar');
36+
await util.writeFile(path.join(DATA_DIR, 'dummy foo', '.bat'), 'foobar');
37+
38+
// Run Action
39+
await util.runWithGithubEnv(
40+
path.basename(__filename),
41+
{
42+
REPO: 'ssh://git@git-ssh/git-server/repos/ssh-existing-branch-folder-space.git',
43+
BRANCH: 'master',
44+
FOLDER: DATA_DIR,
45+
SSH_PRIVATE_KEY: (await util.readFile(util.SSH_PRIVATE_KEY)).toString(),
46+
KNOWN_HOSTS_FILE: util.KNOWN_HOSTS,
47+
},
48+
's0/test',
49+
{},
50+
's0'
51+
);
52+
53+
// Check that the log of the repo is as expected
54+
// (check tree-hash, commit message, and author)
55+
const log = (
56+
await util.exec(
57+
'git log --pretty="format:msg:%s%ntree:%T%nauthor:%an <%ae>" master',
58+
{
59+
cwd: REPO_DIR,
60+
}
61+
)
62+
).stdout;
63+
const sha = await util.getRepoSha();
64+
const cleanedLog = log.replace(sha, '<sha>');
65+
expect(cleanedLog).toMatchSnapshot();
66+
});

0 commit comments

Comments
 (0)