|
@@ -1,14 +1,13 @@ |
|
|
import {ChildProcess} from 'child_process'; |
|
|
|
|
|
import {spawn} from '../../utils/process'; |
|
|
|
|
|
import {mkdirp, unlink} from '../../utils/fs'; |
|
|
|
|
|
|
|
|
import {ChildProcess, spawn} from 'child_process'; |
|
|
|
|
|
import * as fs from 'fs/promises'; |
|
|
|
|
|
|
|
|
export interface GitService { |
|
|
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> |
|
|
|
|
|
|
|
|
create(cwd: string): Promise<ChildProcess> |
|
|
|
|
|
delete(cwd: string): Promise<void> |
|
|
|
|
|
advertiseReceivePackRefs(cwd: string): Promise<ChildProcess> |
|
|
|
|
|
advertiseUploadPackRefs(cwd: string): Promise<ChildProcess> |
|
|
|
|
|
receivePack(cwd: string): Promise<ChildProcess> |
|
|
|
|
|
uploadPack(cwd: string): Promise<ChildProcess> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export class GitServiceImpl implements GitService { |
|
|
export class GitServiceImpl implements GitService { |
|
@@ -16,43 +15,40 @@ export class GitServiceImpl implements GitService { |
|
|
return /^win/.test(process.platform); |
|
|
return /^win/.test(process.platform); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async create(repoBasePath: string): Promise<ChildProcess> { |
|
|
|
|
|
await mkdirp(repoBasePath); |
|
|
|
|
|
return spawn( |
|
|
|
|
|
repoBasePath, |
|
|
|
|
|
'git', ['init', '--bare'], |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
async create(cwd: string): Promise<ChildProcess> { |
|
|
|
|
|
await fs.mkdir(cwd, { recursive: true }); |
|
|
|
|
|
return spawn('git', ['init', '--bare'], { cwd }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async delete(repoBasePath: string): Promise<void> { |
|
|
|
|
|
await unlink(repoBasePath); |
|
|
|
|
|
|
|
|
async delete(cwd: string): Promise<void> { |
|
|
|
|
|
await fs.rm(cwd, { recursive: true, force: true, }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async advertiseReceivePackRefs(repoBasePath: string): Promise<ChildProcess> { |
|
|
|
|
|
|
|
|
async advertiseReceivePackRefs(cwd: string): Promise<ChildProcess> { |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack'; |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack'; |
|
|
const commonArgs = ['--stateless-rpc', '--advertise-refs', '.']; |
|
|
const commonArgs = ['--stateless-rpc', '--advertise-refs', '.']; |
|
|
const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs; |
|
|
const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs; |
|
|
return spawn(repoBasePath, command, args); |
|
|
|
|
|
|
|
|
return spawn(command, args, { cwd }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async advertiseUploadPackRefs(repoBasePath: string): Promise<ChildProcess> { |
|
|
|
|
|
|
|
|
async advertiseUploadPackRefs(cwd: string): Promise<ChildProcess> { |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack'; |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack'; |
|
|
const commonArgs = ['--stateless-rpc', '--advertise-refs', '.']; |
|
|
const commonArgs = ['--stateless-rpc', '--advertise-refs', '.']; |
|
|
const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs; |
|
|
const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs; |
|
|
return spawn(repoBasePath, command, args); |
|
|
|
|
|
|
|
|
return spawn(command, args, { cwd }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async receivePack(repoBasePath: string): Promise<ChildProcess> { |
|
|
|
|
|
|
|
|
async receivePack(cwd: string): Promise<ChildProcess> { |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack'; |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-receive-pack'; |
|
|
const commonArgs = ['--stateless-rpc', '.']; |
|
|
const commonArgs = ['--stateless-rpc', '.']; |
|
|
const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs; |
|
|
const args = GitServiceImpl.isWindows() ? ['receive-pack', ...commonArgs] : commonArgs; |
|
|
return spawn(repoBasePath, command, args); |
|
|
|
|
|
|
|
|
return spawn(command, args, { cwd }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async uploadPack(repoBasePath: string): Promise<ChildProcess> { |
|
|
|
|
|
|
|
|
async uploadPack(cwd: string): Promise<ChildProcess> { |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack'; |
|
|
const command = GitServiceImpl.isWindows() ? 'git' : 'git-upload-pack'; |
|
|
const commonArgs = ['--stateless-rpc', '.']; |
|
|
const commonArgs = ['--stateless-rpc', '.']; |
|
|
const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs; |
|
|
const args = GitServiceImpl.isWindows() ? ['upload-pack', ...commonArgs] : commonArgs; |
|
|
return spawn(repoBasePath, command, args); |
|
|
|
|
|
|
|
|
return spawn(command, args, { cwd }); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |