| 1 | import { FLUSH_PACKET } from './pkt-line.js'; |
| 2 | import { pktLine } |
| 3 | |
| 4 | const SIDE_BAND_DATA = 1 |
| 5 | // The packet limits git sets for each side-band capability, less the length and the band byte. |
| 6 | const SIDE_BAND_64K_CHUNK = 65520 |
| 7 | const SIDE_BAND_CHUNK = 1000 |
| 8 | |
| 9 | /** A receive-pack reply that refuses every ref in a push, which git prints as `! [remote rejected] <ref> (<reason>)`. Null when the client asked for no report, so the caller has nothing better than an error status. */ |
| 10 | export function rejectedPushReport({ |
| 11 | refs, |
| 12 | capabilities, |
| 13 | reason, |
| 14 | }: { |
| 15 | refs: string |
| 16 | capabilities: string |
| 17 | reason: string |
| 18 | }): Buffer | |
| 19 | if ( |
| 20 | !capabilities.includes(' |
| 21 | !capabilities.includes(' |
| 22 | ) |
| 23 | return null; |
| 24 | |
| 25 | // A reason runs to the end of its line, so it must not break one. |
| 26 | const line = |
| 27 | const report = |
| 28 | pktLine('unpack ok\n') |
| 29 | ...refs.map( |
| 30 | Buffer.from(FLUSH_PACKET |
| 31 | ]); |
| 32 | |
| 33 | const chunk = |
| 34 | ? SIDE_BAND_64K_CHUNK |
| 35 | : capabilities.includes( |
| 36 | ? SIDE_BAND_CHUNK |
| 37 | : null; |
| 38 | if (chunk === |
| 39 | |
| 40 | const packets: |
| 41 | for (let start |
| 42 | packets.push( |
| 43 | pktLine( |
| 44 | Buffer.concat([ |
| 45 | Buffer.from([SIDE_BAND_DATA |
| 46 | report.subarray(start |
| 47 | ]), |
| 48 | ), |
| 49 | ); |
| 50 | } |
| 51 | return Buffer.concat |
| 52 | } |