~edwargix/git.sr.ht

424b962d845f813a187235371a291f34f8c46e13 — наб 4 years ago ca92f1c
Ensure all pushed refs are UTF-8, lest the webapp 500 on reading the repo

New push output:
-- >8 --
nabijaczleweli@tarta:~/code/git.sr.ht/gitsrht-update-hook$ git push 'git@git.shi.rt:~nabijaczleweli/empty' HEAD:▒ HEAD:owo
Enumerating objects: 34, done.
Counting objects: 100% (34/34), done.
Delta compression using up to 24 threads
Compressing objects: 100% (23/23), done.
Writing objects: 100% (23/23), 5.86 KiB | 1.95 MiB/s, done.
Total 23 (delta 17), reused 0 (delta 0)
remote: refs/heads/▒ not valid UTF-8, see https://github.com/libgit2/pygit2/issues/1028 for more information
remote: error: hook declined to update refs/heads/▒
remote: Builds started:
remote: http://127.0.0.1:5002/~nabijaczleweli/job/133 [alpine.yml]
remote: http://127.0.0.1:5002/~nabijaczleweli/job/134 [archlinux.yml]
remote: http://127.0.0.1:5002/~nabijaczleweli/job/135 [debian.yml]
To git.shi.rt:~nabijaczleweli/empty
 * [new branch]      HEAD -> owo
 ! [remote rejected] HEAD -> ▒ (hook declined)
error: failed to push some refs to 'git@git.shi.rt:~nabijaczleweli/empty'
-- >8 --

New log output:
-- >8 --
hooks/pre-receive 2020/08/10 18:44:24 [hooks/pre-receive]
hooks/pre-receive 2020/08/10 18:44:24 Running pre-receive for push 7c774348-3d6e-46fe-a613-ca344e079249
hooks/update 2020/08/10 18:44:24 [hooks/update refs/heads/▒ 0000000000000000000000000000000000000000 98d9b505ba528ccfccaba0605930bf1140648dbb]
hooks/update 2020/08/10 18:44:24 Running update for push 7c774348-3d6e-46fe-a613-ca344e079249
hooks/update 2020/08/10 18:44:24 Refusing ref 'refs/heads/▒': not UTF-8
hooks/update 2020/08/10 18:44:24 [hooks/update refs/heads/owo 0000000000000000000000000000000000000000 98d9b505ba528ccfccaba0605930bf1140648dbb]
hooks/update 2020/08/10 18:44:24 Running update for push 7c774348-3d6e-46fe-a613-ca344e079249
hooks/post-update 2020/08/10 18:44:24 [hooks/post-update refs/heads/owo]
hooks/post-update 2020/08/10 18:44:24 Running post-update for push 7c774348-3d6e-46fe-a613-ca344e079249
hooks/post-update 2020/08/10 18:44:24 Submitted 3 builds for refs/heads/owo
hooks/post-update 2020/08/10 18:44:24 Skipping stage 3, no work
-- >8 --
1 files changed, 8 insertions(+), 0 deletions(-)

M gitsrht-update-hook/update.go
M gitsrht-update-hook/update.go => gitsrht-update-hook/update.go +8 -0
@@ 2,8 2,10 @@ package main

import (
	"fmt"
	"log"
	"os"
	"time"
	"unicode/utf8"

	goredis "github.com/go-redis/redis"
)


@@ 22,6 24,12 @@ func update() {
	}
	logger.Printf("Running update for push %s", pushUuid)

	if !utf8.ValidString(refname) {
		logger.Printf("Refusing ref '%s': not UTF-8", refname)
		log.Printf("%s not valid UTF-8, see https://github.com/libgit2/pygit2/issues/1028 for more information", refname);
		os.Exit(1)
	}

	redisHost, ok := config.Get("sr.ht", "redis-host")
	if !ok {
		redisHost = "redis://localhost:6379"