Select Git revision
gitMission.ts
-
pierrick_cbl authored
set git username/email with a 'system' scope NB: 'global' scope would not be enough since the user running deadlock-recorder is 'root' and the terminal in vscode uses theia user
pierrick_cbl authoredset git username/email with a 'system' scope NB: 'global' scope would not be enough since the user running deadlock-recorder is 'root' and the terminal in vscode uses theia user
gitMission.ts 3.03 KiB
import simpleGit, { SimpleGit, SimpleGitOptions } from 'simple-git';
import { PROJECT_SRC_PATH } from './config';
import UserConfig from './userConfig';
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const DEFAULT_REMOTE = 'origin';
const DEFAULT_BRANCH = 'master';
export default class GitMission {
private git: SimpleGit;
constructor(private userConfig: UserConfig) {
const options: Partial<SimpleGitOptions> = {
baseDir: PROJECT_SRC_PATH,
binary: 'git',
maxConcurrentProcesses: 2,
};
this.git = simpleGit(options);
}
async setupSshAgent() {
const { err, stderr, stdout } = await exec(`eval "$(ssh-agent -s)" && ssh-keyscan -p ${this.userConfig.getGiteaSshPort()} -H ${this.userConfig.getGiteaHost()} >> ~/.ssh/known_hosts`);
console.log(stdout);
if (err) {
console.error(stderr);
throw new Error(err);
}
}
get author() {
return this.userConfig.getUsername();
}
async init() {
try {
console.log('Setup ssh agent');
await this.setupSshAgent();
console.log('Init Git mission..');
const remote = await this.readRemote();
if (remote === DEFAULT_REMOTE) {
return Promise.resolve(this);
}
const remotePath = this.getRemotePath();
await this.git.init();
await this.git.addRemote(DEFAULT_REMOTE, remotePath);
await this.git.addConfig('user.email', this.userConfig.getCurrentUserDetails().email, false, "system");
await this.git.addConfig('user.name', `${this.userConfig.getCurrentUserDetails().lastName} ${this.userConfig.getCurrentUserDetails().firstName}`, false, "system");
return Promise.resolve(this);
} catch (e) {
console.error(e);
return Promise.reject(e);
}
}
private getRemotePath() {
return `ssh://git@${this.userConfig.getGiteaHost()}:${this.userConfig.getGiteaSshPort()}/${this.userConfig.getRemoteGitUsername()}/${this.userConfig.getMissionId()}`;