1
0
Fork 0
forked from forgejo/forgejo

Add unit tests for update git hook

- Add unit tests.
- Handle the 'impossible' case of not enough arguments.
- Ref: https://codeberg.org/forgejo/forgejo/pulls/2834
This commit is contained in:
Gusted 2024-04-06 15:43:45 +02:00
parent 0a51ae26bc
commit dad799fa46
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 58 additions and 22 deletions

View file

@ -302,8 +302,12 @@ func runHookUpdate(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
// The last three arguments given to the hook are in order: reference name, old commit ID and new commit ID.
args := os.Args[len(os.Args)-3:]
if c.NArg() != 3 {
return nil
}
args := c.Args().Slice()
// The arguments given to the hook are in order: reference name, old commit ID and new commit ID.
refFullName := git.RefName(args[0])
newCommitID := args[2]