|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import {ChildProcess} from 'child_process';
- import {spawn} from '../../utils/process';
- import {mkdirp, unlink} from '../../utils/fs';
-
- export interface GitService {
- create(repoBasePath: string): Promise<ChildProcess>
- delete(repoBasePath: string): Promise<void>
- advertiseReceivePackRefs(repoBasePath: string): Promise<ChildProcess>
- advertiseUploadPackRefs(repoBasePath: string): Promise<ChildProcess>
- receivePack(repoBasePath: string): Promise<ChildProcess>
- uploadPack(repoBasePath: string): Promise<ChildProcess>
- }
-
- export class GitServiceImpl implements GitService {
- private static isWindows() {
- return /^win/.test(process.platform);
- }
-
- async create(repoBasePath: string): Promise<ChildProcess> {
- await mkdirp(repoBasePath);
- return spawn(
- repoBasePath,
- 'git', ['init', '--bare'],
- );
- }
-
- async delete(repoBasePath: string): Promise<void> {
- await unlink(repoBasePath);
- }
-
- async advertiseReceivePackRefs(repoBasePath: string): Promise<ChildProcess> {
- const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack';
- const commonArgs = ['--stateless-rpc', '--advertise-refs', '.'];
- const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs;
- return spawn(repoBasePath, command, args);
- }
-
- async advertiseUploadPackRefs(repoBasePath: string): Promise<ChildProcess> {
- const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack';
- const commonArgs = ['--stateless-rpc', '--advertise-refs', '.'];
- const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs;
- return spawn(repoBasePath, command, args);
- }
-
- async receivePack(repoBasePath: string): Promise<ChildProcess> {
- const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack';
- const commonArgs = ['--stateless-rpc', '.'];
- const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs;
- return spawn(repoBasePath, command, args);
- }
-
- async uploadPack(repoBasePath: string): Promise<ChildProcess> {
- const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack';
- const commonArgs = ['--stateless-rpc', '.'];
- const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs;
- return spawn(repoBasePath, command, args);
- }
- }
|