@@ -10,7 +10,7 @@ const {
10
10
unpack
11
11
} = require ( '../src/proxy/processors/push-action/parsePush' ) ;
12
12
13
- import { FLUSH_PACKET , PACK_SIGNATURE } from '../src/proxy/processors/constants' ;
13
+ import { EMPTY_COMMIT_HASH , FLUSH_PACKET , PACK_SIGNATURE } from '../src/proxy/processors/constants' ;
14
14
15
15
/**
16
16
* Creates a simplified sample PACK buffer for testing.
@@ -64,6 +64,20 @@ function createPacketLineBuffer(lines) {
64
64
return buffer ;
65
65
}
66
66
67
+ /**
68
+ * Creates an empty PACK buffer for testing.
69
+ * @return {Buffer } - The generated buffer containing the PACK header and checksum.
70
+ */
71
+ function createEmptyPackBuffer ( ) {
72
+ const header = Buffer . alloc ( 12 ) ;
73
+ header . write ( PACK_SIGNATURE , 0 , 4 , 'utf-8' ) ; // signature
74
+ header . writeUInt32BE ( 2 , 4 ) ; // version
75
+ header . writeUInt32BE ( 0 , 8 ) ; // number of entries
76
+
77
+ const checksum = Buffer . alloc ( 20 ) ; // fake checksum (all zeros)
78
+ return Buffer . concat ( [ header , checksum ] ) ;
79
+ }
80
+
67
81
describe ( 'parsePackFile' , ( ) => {
68
82
let action ;
69
83
let req ;
@@ -442,6 +456,28 @@ describe('parsePackFile', () => {
442
456
expect ( step . error ) . to . be . true ;
443
457
expect ( step . errorMessage ) . to . include ( 'Invalid PACK data structure' ) ;
444
458
} ) ;
459
+
460
+ it ( 'should return empty commitData on empty branch push' , async ( ) => {
461
+ const emptyPackBuffer = createEmptyPackBuffer ( ) ;
462
+
463
+ const newCommit = 'b' . repeat ( 40 ) ;
464
+ const ref = 'refs/heads/feature/emptybranch' ;
465
+ const packetLine = `${ EMPTY_COMMIT_HASH } ${ newCommit } ${ ref } \0capabilities\n` ;
466
+
467
+ req . body = Buffer . concat ( [ createPacketLineBuffer ( [ packetLine ] ) , emptyPackBuffer ] ) ;
468
+
469
+ const result = await exec ( req , action ) ;
470
+
471
+ expect ( result ) . to . equal ( action ) ;
472
+
473
+ const step = action . steps . find ( s => s . stepName === 'parsePackFile' ) ;
474
+ expect ( step ) . to . exist ;
475
+ expect ( step . error ) . to . be . false ;
476
+ expect ( action . branch ) . to . equal ( ref ) ;
477
+ expect ( action . setCommit . calledOnceWith ( EMPTY_COMMIT_HASH , newCommit ) ) . to . be . true ;
478
+
479
+ expect ( action . commitData ) . to . be . an ( 'array' ) . with . lengthOf ( 0 ) ;
480
+ } ) ;
445
481
} ) ;
446
482
447
483
describe ( 'getPackMeta' , ( ) => {
0 commit comments