mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-18 06:34:28 +01:00
git push upon share; helper for git child process
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
26
src/git.js
26
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 }
|
||||
|
||||
Reference in New Issue
Block a user