|
| 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