-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.js
More file actions
30 lines (26 loc) · 778 Bytes
/
git.js
File metadata and controls
30 lines (26 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const logger = require('./log.js');
let git = {};
/**
* 克隆仓库
* @param {string} url 仓库地址
* @param {string} branch 分支
* @param {string} localRepo 本地仓库的克隆目录
*/
git.clone = async function(url, branch, localRepo) {
logger.info(`cloning repo: ${url}`);
let command = `git clone ${url} ${ branch != '' ? `-b ${branch}` : ''}`;
await exec(command, { cwd: localRepo });
};
/**
* 拉取最新代码
* @param {string} 仓库在本地的物理路径
*/
git.pull = async function(repoPath) {
logger.info(`pulling repo: ${repoPath}`);
let command = `git pull`;
await exec(command, { cwd: repoPath });
};
module.exports = git;