UNPKG

930 BJavaScriptView Raw
1module.exports = function (data) {
2 return new Promise((resolve,reject)=>{
3 msgs.neu("pushing to the remote git repository");
4
5 if(data.repo_user !== "none" && data.repo_password !== "none") {
6 data.gitUrlWithAuth = data.repo_url
7 .toLowerCase()
8 .split("https://")
9 .join("https://"+encodeURIComponent(data.repo_user)+":"+encodeURIComponent(data.repo_password)+"@");
10 }
11 else data.gitUrlWithAuth = data.repo_url;
12
13 var Git = git(process.cwd())
14 .silent(true)
15 .add("./*")
16 .commit(data.message)
17 .listRemote([],function (err) {
18 if(err) Git.addRemote("origin",data.gitUrlWithAuth,function () {
19 push();
20 });
21 else {
22 push();
23 }
24 });
25
26 function push() {
27 Git.push("origin","HEAD:"+data.repo_branch,function (err) {
28 if(err) reject(err);
29 else {
30 msgs.ok("Successfully push to the remote git repository");
31 resolve(data);
32 }
33 });
34 }
35 });
36};
\No newline at end of file