Skip to content

Commit 1579e9d

Browse files
committed
capture patches by their branching hash
1 parent e78cf38 commit 1579e9d

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/components/publish.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'socket:fs'
22
import path from 'socket:path'
3-
import { exec } from 'socket:child_process'
3+
import { exec, execSync } from 'socket:child_process'
44

55
import Tonic from '@socketsupply/tonic'
66
import { TonicDialog } from '@socketsupply/components/dialog'
@@ -131,7 +131,7 @@ export class DialogPublish extends TonicDialog {
131131
}
132132

133133
try {
134-
output = await exec(`git commit -m '${JSON.stringify(msg)}'`, { cwd })
134+
output = await exec(`git commit -m "${currentHash}" -m "${commitMessage}"`, { cwd })
135135
} catch (err) {
136136
output.stderr = err.message
137137
}
@@ -165,20 +165,15 @@ export class DialogPublish extends TonicDialog {
165165
//
166166
// Just publish the diff
167167
//
168+
let output
168169
try {
169-
output = await exec('git format-patch -1 HEAD --stdout', { cwd })
170+
output = await execSync('git format-patch -1 HEAD --stdout', { cwd })
170171
} catch (err) {
171-
output.stderr = err.message
172-
}
173-
174-
if (output.stderr) {
175-
coTerminal.error(output.stderr)
176-
await this.hide()
177-
return this.html``
172+
console.log(err)
178173
}
179174

180-
coTerminal.info('Publishing patch')
181-
this.publish('patch', Buffer.from(output.stdout)) // into the background
175+
coTerminal.info(output.toString())
176+
this.publish('patch', Buffer.from(output)) // into the background
182177
}
183178

184179
const coProjectSummary = document.querySelector('view-project-summary')

src/index.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ class AppView extends Tonic {
269269
await sub.join()
270270
}
271271
})
272+
273+
socket.on('#data', (...args) => console.log)
272274
} else {
273275
// If the user has changed the clusterId and or subclusterId, we need to tell the peer about it
274276
// TODO(@heapwolf): we need a nice way to send config updates to the peer worker.
@@ -277,12 +279,13 @@ class AppView extends Tonic {
277279
const { data: dataProjects } = await this.db.projects.readAll()
278280

279281
for (const [projectId, project] of dataProjects.entries()) {
280-
if (socket.subclusters.get(project.subclusterId)) continue
282+
if (socket.subclusters.get(project.subclusterId)) {
283+
continue
284+
}
281285

282286
const subcluster = await socket.subcluster({ sharedKey: project.sharedKey })
283287

284288
subcluster.on('patch', async (value, packet) => {
285-
console.log('GOT PATCH!', value, packet)
286289
if (!packet.verified) return // gtfoa
287290
if (packet.index !== -1) return // not interested
288291

@@ -293,6 +296,14 @@ class AppView extends Tonic {
293296
const { data: hasPacket } = await this.db.patches.has(key)
294297
if (hasPacket) return
295298

299+
const patch = Buffer.from(value.data).toString()
300+
const headers = patch.split('---')[0]
301+
const subjectHeader = headers.find(s => s.includes('Subject:'))
302+
const branchingHash = subjectHeader.split(/\[PATCH]\s*/)[0]
303+
304+
if (branchingHash) {
305+
await this.db.patches.put(branchingHash.trim(), patch)
306+
}
296307
})
297308

298309
subcluster.on('clone', async (value, packet) => {

0 commit comments

Comments
 (0)