mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 14:14:22 +01:00
@@ -13,8 +13,7 @@
|
||||
"bin": {
|
||||
"git-peard": "./src/gitpeard.js",
|
||||
"git-remote-pear": "./src/git-remote-pear.js",
|
||||
"git-pear": "./src/cli.js",
|
||||
"rpc": "./src/rpc.js"
|
||||
"git-pear": "./src/cli.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -82,9 +82,6 @@ swarm.on('connection', async (socket) => {
|
||||
})
|
||||
|
||||
async function talkToGit (refs, drive, repoName, rpc) {
|
||||
for (const ref in refs) {
|
||||
console.warn(refs[ref] + '\t' + ref)
|
||||
}
|
||||
process.stdin.setEncoding('utf8')
|
||||
const didFetch = false
|
||||
process.stdin.on('readable', async function () {
|
||||
@@ -103,17 +100,20 @@ async function talkToGit (refs, drive, repoName, rpc) {
|
||||
if (!home.isShared(repoName)) {
|
||||
home.shareAppFolder(name)
|
||||
}
|
||||
|
||||
|
||||
dst = dst.replace('refs/heads/', '').replace('\n\n', '')
|
||||
await git.push(dst)
|
||||
|
||||
let command
|
||||
if (isDelete) {
|
||||
command = 'delete-branch-from-repo'
|
||||
command = 'd-branch'
|
||||
} else if (isForce) {
|
||||
command = 'force-push-to-repo'
|
||||
await git.push(src, isForce)
|
||||
src = src.replace('+', '')
|
||||
command = 'f-push'
|
||||
} else {
|
||||
command = 'push-to-repo'
|
||||
console.warn('pushing', src, dst)
|
||||
await git.push(src)
|
||||
command = 'push'
|
||||
}
|
||||
|
||||
const publicKey = home.readPk()
|
||||
@@ -122,15 +122,20 @@ async function talkToGit (refs, drive, repoName, rpc) {
|
||||
// process.kill(daemonPid || home.getDaemonPid())
|
||||
// home.removeDaemonPid()
|
||||
|
||||
// process.stdout.write(res.toString())
|
||||
process.stdout.write('\n\n')
|
||||
process.exit(0)
|
||||
} else if (chunk && chunk.search(/^list/) !== -1) { // list && list for-push
|
||||
for (const ref in refs) {
|
||||
console.warn(refs[ref] + '\t' + ref)
|
||||
}
|
||||
Object.keys(refs).forEach(function (branch, i) {
|
||||
process.stdout.write(refs[branch] + ' ' + branch + '\n')
|
||||
})
|
||||
process.stdout.write('\n')
|
||||
} else if (chunk && chunk.search(/^fetch/) !== -1) {
|
||||
for (const ref in refs) {
|
||||
console.warn(refs[ref] + '\t' + ref)
|
||||
}
|
||||
const lines = chunk.split(/\n/).filter(l => l !== '')
|
||||
|
||||
const targets = []
|
||||
|
||||
@@ -31,8 +31,10 @@ async function addRemote (name) {
|
||||
return await doGit(init)
|
||||
}
|
||||
|
||||
async function push (branch = 'master') {
|
||||
const push = spawn('git', ['push', 'pear', branch])
|
||||
async function push (branch = 'master', force = false) {
|
||||
const args = ['push', 'pear', branch]
|
||||
if (force) args.push('-f')
|
||||
const push = spawn('git', args)
|
||||
return await doGit(push)
|
||||
}
|
||||
|
||||
|
||||
48
src/rpc.js
48
src/rpc.js
@@ -23,9 +23,9 @@ module.exports = class RPC {
|
||||
rpc.respond('get-refs', async req => await this.getRefsHandler(req))
|
||||
|
||||
/* -- PUSH HANDLERS -- */
|
||||
rpc.respond('push-to-repo', async req => await this.pushHandler(req))
|
||||
rpc.respond('force-push-to-repo', req => this.forcePushHandler(req))
|
||||
rpc.respond('delete-branch-from-repo', req => this.deleteBranchHandler(req))
|
||||
rpc.respond('push', async req => await this.pushHandler(req))
|
||||
rpc.respond('f-push', async req => await this.forcePushHandler(req))
|
||||
rpc.respond('d-branch', async req => await this.deleteBranchHandler(req))
|
||||
|
||||
this.connections[peerInfo.publicKey] = rpc
|
||||
}
|
||||
@@ -47,7 +47,6 @@ module.exports = class RPC {
|
||||
async pushHandler (req) {
|
||||
const { url, repo, key, branch } = this.parsePushCommand(req)
|
||||
// TODO: check ACL
|
||||
// collect stdout to buffer and return it
|
||||
return await new Promise((resolve, reject) => {
|
||||
const process = spawn('git', ['fetch', url, `${branch}:${branch}`], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||
let errBuffer = Buffer.from('')
|
||||
@@ -55,31 +54,42 @@ module.exports = class RPC {
|
||||
errBuffer = Buffer.concat([errBuffer, data])
|
||||
})
|
||||
|
||||
// TODO: write buffer to standard output with ACL
|
||||
process.on('close', code => {
|
||||
return code === 0 ? resolve(errBuffer) : reject(errBuffer)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
forcePushHandler (req) {
|
||||
async forcePushHandler (req) {
|
||||
const { url, repo, key, branch } = this.parsePushCommand(req)
|
||||
// TODO:
|
||||
// check ACL
|
||||
// collect stdout to buffer and return it
|
||||
// const process = spawn('git', ['reset', '--hard', url, branch], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||
console.error('req', req.toString())
|
||||
console.error('forcePushHandler not implemented')
|
||||
// TODO: check ACL
|
||||
return await new Promise((resolve, reject) => {
|
||||
const process = spawn('git', ['fetch', url, `${branch}:${branch}`, '--force'], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||
let errBuffer = Buffer.from('')
|
||||
process.stderr.on('data', data => {
|
||||
errBuffer = Buffer.concat([errBuffer, data])
|
||||
})
|
||||
|
||||
process.on('close', code => {
|
||||
return code === 0 ? resolve(errBuffer) : reject(errBuffer)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
deleteBranchHandler (req) {
|
||||
async deleteBranchHandler (req) {
|
||||
const { url, repo, key, branch } = this.parsePushCommand(req)
|
||||
// TODO:
|
||||
// check ACL
|
||||
// collect stdout to buffer and return it
|
||||
// const process = spawn('git', ['branch', '-d', branch], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||
console.error('req', req.toString())
|
||||
console.error('deleteBranchHandler not implemented')
|
||||
// TODO: check ACL
|
||||
return await new Promise((resolve, reject) => {
|
||||
const process = spawn('git', ['branch', '-D', branch], { env: { GIT_DIR: home.getCodePath(repo) } })
|
||||
let errBuffer = Buffer.from('')
|
||||
process.stderr.on('data', data => {
|
||||
errBuffer = Buffer.concat([errBuffer, data])
|
||||
})
|
||||
|
||||
process.on('close', code => {
|
||||
return code === 0 ? resolve(errBuffer) : reject(errBuffer)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
parsePushCommand(req) {
|
||||
|
||||
Reference in New Issue
Block a user