Fix verifyCommits error when push a new branch (#26664)

> ### Description
> If a new branch is pushed, and the repository has a rule that would
require signed commits for the new branch, the commit is rejected with a
500 error regardless of whether it's signed.
> 
> When pushing a new branch, the "old" commit is the empty ID
(0000000000000000000000000000000000000000). verifyCommits has no
provision for this and passes an invalid commit range to git rev-list.
Prior to 1.19 this wasn't an issue because only pre-existing individual
branches could be protected.
> 
> I was able to reproduce with
[try.gitea.io/CraigTest/test](https://try.gitea.io/CraigTest/test),
which is set up with a blanket rule to require commits on all branches.


Fix #25565
Very thanks to @Craig-Holmquist-NTI for reporting the bug and suggesting
an valid solution!

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
CaiCandong
2023-08-30 02:27:53 +00:00
committed by GitHub
co-authored by wxiaoguang Lunny Xiao
parent 508de3a58d
commit 815d267c80
43 changed files with 270 additions and 20 deletions
@@ -0,0 +1,2 @@
x•ŽK
1Ù ÒéüAÄS¸ï$Í"32 ooð®ŠWð òÞ{!žæ`–˜JC%¡.˜ $Ár]sѱe$ïmòâMƒ·)£÷±(O`ªbtlÐE[:;4–àHÐ1_û”rayýáþl“é’÷~“ÊE­L@cå€Xv…Mþã":µMÛƒG«_}À?Ý
@@ -0,0 +1,2 @@
x1
!ES{ŠéAwGGa 9EúQg W·Èí#¹AªÞû©ÕZ§/£‹€³Œ–p±ì(¤(ó®óBhÈÛ¼&áŸãÝ:pLY`ûÍãU†ð-µzŸÁ°ô†\µ×ZM:†ü¡¨Êå€óxJ/ûG}:µ3
@@ -0,0 +1,3 @@
x•ŽA
Â0E]ç³$™L“ ˆx•L2µ]´•
ÞÞê␍\}ø¼ÿøe[–¹:{êM’°õZ5bŠ8$¡–Äv ž°fÉRÍ37];Ôˆìbt¡Ò úå3‡$‰,tXœ¨G“÷>m␍²”ªpýÅý1wÍ—²-7p½£Ä„p¶ÉZs´Ç±®L̾¾´Íã¤åµLæëe@ó
@@ -0,0 +1,3 @@
x•’Ë®«FE3æ+zn%44æ!%QxƒÛ€s˜AÓ` 8Øæëã{£Ì2IM¶j•ª´¥Údèûf²Ìý2”‚"‡$§e‰¶
-(â ­Ä!´ÝJ"åaŲ@•BaîùHo3 ŸVØòå<$/)å$JøJDB¡•H¤§˜ü{¾ RRðûOù«nfšÿF†þOÀ‰
âq[°2„̇~ŒÍô¬Ô÷zjjðëÒLÛÅÀ·}prm¬Fqhþä `@Ø«¦ªš®ª¥Õ˜fî?3Ç[7г…ê¨Ð) ^™þuÿÖ¿,µÆl7©zÝÿr|&«Ou4Ø9Ó:µÎQjôû·êÕ1x±õå6ÍQ‡÷ƒÀ%Áåtû‰sò¸íV‰| ( V¿,aL,ù«G~²Ç¹‹‹r¥ùûî@·`·Àþ$[! XËŠep©Œæ[8 oýä(›« k£Z´Î³yóeÐ¹ÙÆÄ«Y²¿kÖd€¯6•3¾;3ÜÔ RÔi Þ‹dYÓDk91V]/Cê#º¾&ÿêpo´Fáb¯‹¶}§¹ô¦òuW&]+m xaqdÜIõX¯þ3␍ŽƒׯK’ÚÓI#Æi_ärgðñÁôôõÄ©7=ú`@[õŠ&AóṲ̂ÞLÖo–‹3~MÆóõü8MGtö²ï>ÄôŒx›¼vQ²(…aÅÄWŸo"¡Ës±r‰z”°eÓÅ­}å†QDñóÖ¨fK)ó˜mÆr>>•ª†¿‚†ÝÌšF8³x™␍Ä×^J k{mczþI*²^ÆMb‡þ m¸6Š”M~h¹pÕÍ␍{¡¡±0€ö• ]€?nUwgþÉ ‰ÿJ ³Ð±©Þ<ó7Û2
@@ -0,0 +1,3 @@
x•ŽA
Â0E]ç³$™L“ ˆx•L2µ]´•
ÞÞê␍\}ø¼ÿøe[–¹:{êM’°õZ5bŠ8$¡–Äv ž°fÉRÍ37];Ôˆìbt¡Ò úå3‡$‰,tXœ¨G“÷>m␍²”ªpýÅý1wÍ—²-7p½£Ä„p¶ÉZs´Ç±®L̾¾´Íã¤åµLæëe@ó