From 67386b3cdfd75e0b92034cd70baef4ccbedd1f40 Mon Sep 17 00:00:00 2001 From: dzdidi Date: Tue, 15 Aug 2023 17:47:24 +0200 Subject: [PATCH] git push upon share; helper for git child process Signed-off-by: dzdidi --- src/cli.js | 3 ++- src/git.js | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/cli.js b/src/cli.js index bba5323..aee1fe4 100755 --- a/src/cli.js +++ b/src/cli.js @@ -44,8 +44,8 @@ program if (options.share) { home.shareAppFolder(name) + await git.push() console.log(`Shared "${name}" project`) - // push? } }) @@ -57,6 +57,7 @@ program const name = path.resolve(p).split(path.sep).pop() if ((home.isInitialized(name))) { home.shareAppFolder(name) + await git.push() console.log(`Shared "${name}" project`) return } diff --git a/src/git.js b/src/git.js index 813fef4..f733555 100644 --- a/src/git.js +++ b/src/git.js @@ -23,23 +23,25 @@ async function lsPromise (url) { async function createBareRepo (name) { const init = spawn('git', ['init', '--bare'], { env: { GIT_DIR: getCodePath(name) } }) - init.stderr.pipe(process.stderr) - return new Promise((resolve, reject) => { - init.on('close', (code) => { - if (code) return reject(new Error(`git init exited with code ${code}`)) - - resolve() - }) - }) + return await doGit(init) } async function addRemote (name) { const init = spawn('git', ['remote', 'add', 'pear', getCodePath(name)]) - init.stderr.pipe(process.stderr) + return await doGit(init) +} + +async function push (branch = 'master') { + const push = spawn('git', ['push', 'pear', branch]) + return await doGit(push) +} + +async function doGit (child) { + child.stderr.pipe(process.stderr) return new Promise((resolve, reject) => { - init.on('close', (code) => { + child.on('close', (code) => { if (code) { - return reject(new Error(`git remote add exited with code ${code}`)) + return reject(new Error(`git exited with code ${code}`)) } return resolve() @@ -178,4 +180,4 @@ async function unpackStream (packStream) { }) } -module.exports = { lsPromise, uploadPack, unpackFile, unpackStream, createBareRepo, addRemote } +module.exports = { lsPromise, uploadPack, unpackFile, unpackStream, createBareRepo, addRemote, push }