mirror of
https://github.com/aljazceru/gitpear.git
synced 2025-12-17 22:24:22 +01:00
more elaborate todos on push capabilities
Signed-off-by: dzdidi <deniszalessky@gmail.com>
This commit is contained in:
@@ -11,6 +11,8 @@ const crypto = require('hypercore-crypto')
|
||||
const git = require('./git.js')
|
||||
const home = require('./home')
|
||||
|
||||
const fs = require('fs')
|
||||
|
||||
const url = process.argv[3]
|
||||
const matches = url.match(/pear:\/\/([a-f0-9]{64})\/(.*)/)
|
||||
|
||||
@@ -59,10 +61,10 @@ swarm.on('connection', async (socket) => {
|
||||
|
||||
const refsRes = await rpc.request('get-refs', Buffer.from(repoName))
|
||||
|
||||
await talkToGit(JSON.parse(refsRes.toString()), drive)
|
||||
await talkToGit(JSON.parse(refsRes.toString()), drive, repoName)
|
||||
})
|
||||
|
||||
async function talkToGit (refs, drive) {
|
||||
async function talkToGit (refs, drive, repoName) {
|
||||
for (const ref in refs) {
|
||||
console.warn(refs[ref] + '\t' + ref)
|
||||
}
|
||||
@@ -74,34 +76,44 @@ async function talkToGit (refs, drive) {
|
||||
process.stdout.write('list\n')
|
||||
process.stdout.write('push\n')
|
||||
process.stdout.write('fetch\n\n')
|
||||
} else if (chunk && chunk.search(/^push/) !== -1) {j
|
||||
} else if (chunk && chunk.search(/^push/) !== -1) {
|
||||
const [_command, path] = chunk.split(' ')
|
||||
const [src, dst] = path.split(':')
|
||||
|
||||
const isDelete = !src
|
||||
const isForce = src.startsWith('+')
|
||||
|
||||
if (!home.getDaemonPid()) {
|
||||
const daemon = spawn('git-peard', opts)
|
||||
home.storeDaemonPid(daemon.pid)
|
||||
// TODO: remove in case of error or exit but allow unref
|
||||
// daemon.on('error', home.removeDaemonPid)
|
||||
// daemon.on('exit', home.removeDaemonPid)
|
||||
daemon.unref()
|
||||
}
|
||||
// TODO: options:
|
||||
// ---- push by pull ----
|
||||
// - init for share (daemon, etc)
|
||||
// - push branch to local remote
|
||||
// - send rpc command to origin
|
||||
// XXX: it looks like git is trying to establish network connection first, so if it can not
|
||||
// reach push destination it hangs everything on capabilities exchange
|
||||
// TODO: add timeout
|
||||
|
||||
// FOR TESTING RUN SECOND INSTANCE OF GIT-PEARD
|
||||
// if (!home.isDaemonRunning()) {
|
||||
// const opts = {
|
||||
// detached: true,
|
||||
// stdio: [ 'ignore', home.getOutStream(), home.getErrStream() ]
|
||||
// }
|
||||
// const daemon = spawn('git-peard', opts)
|
||||
// home.storeDaemonPid(daemon.pid)
|
||||
// // TODO: remove in case of error or exit but allow unref
|
||||
// // daemon.on('error', home.removeDaemonPid)
|
||||
// // daemon.on('exit', home.removeDaemonPid)
|
||||
// daemon.unref()
|
||||
// }
|
||||
|
||||
console.error('TODO')
|
||||
// TODO: get repo name (current dir name instead or name from url)
|
||||
// if (home.isShared(repoName)) {
|
||||
// git push branch
|
||||
// } else {
|
||||
// share repo with current branch
|
||||
// }
|
||||
|
||||
// - send rpc command to remote (url)
|
||||
// Mapping of RPC commands to git commands on origin:
|
||||
// - normal push - git pull
|
||||
// - force push - git reset --hard <remote>/<branch>
|
||||
// - delete branch - git branch -D <remote>/<branch>
|
||||
//
|
||||
// ---- push by push ----
|
||||
//
|
||||
//
|
||||
|
||||
process.stdout.write('\n\n')
|
||||
process.exit(0)
|
||||
|
||||
@@ -90,6 +90,10 @@ function getDaemonPid () {
|
||||
}
|
||||
}
|
||||
|
||||
function isDaemonRunning () {
|
||||
return fs.existsSync(`${APP_HOME}/.daemon.pid`)
|
||||
}
|
||||
|
||||
function removeDaemonPid () {
|
||||
try {
|
||||
fs.unlinkSync(`${APP_HOME}/.daemon.pid`)
|
||||
@@ -114,5 +118,6 @@ module.exports = {
|
||||
getErrStream,
|
||||
storeDaemonPid,
|
||||
getDaemonPid,
|
||||
isDaemonRunning,
|
||||
removeDaemonPid
|
||||
}
|
||||
|
||||
@@ -16,9 +16,16 @@ module.exports = class RPC {
|
||||
// for example check of peerInfo.publicKey is in a list of allowed keys
|
||||
// which can in turn be stored in a .git-daemon-export-ok file
|
||||
|
||||
/* -- PULL HANDLERS -- */
|
||||
rpc.respond('get-repos', req => this.getReposHandler(req))
|
||||
rpc.respond('get-refs', async req => await this.getRefsHandler(req))
|
||||
|
||||
/* -- PUSH HANDLERS -- */
|
||||
// TODO: reponders to pull requests
|
||||
// normal push: git pull <url>
|
||||
// force push: git reset --hard url/<branch>
|
||||
// delete branch: git branch -D url/<branch>
|
||||
|
||||
this.connections[peerInfo.publicKey] = rpc
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user