From 353d462bbe6c89b7cb9d7d64f73f2c20518e3607 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sun, 6 Aug 2023 01:50:15 +0500 Subject: [PATCH] Fix recent changes crashing on empty wikis This is a dirty fix. How come git-handling is so messed? --- history/revision.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/history/revision.go b/history/revision.go index c5a6041..e3aa853 100644 --- a/history/revision.go +++ b/history/revision.go @@ -27,7 +27,12 @@ func gitLog(args ...string) ([]Revision, error) { "log", "--abbrev-commit", "--no-merges", "--pretty=format:%h\t%ae\t%at\t%s", }, args...) + args = append(args, "--") out, err := silentGitsh(args...) + if strings.Contains(out.String(), "bad revision 'HEAD'") { + // Then we have no recent changes! It's a hack. + return nil, nil + } if err != nil { return nil, err } @@ -63,6 +68,7 @@ func (stream *recentChangesStream) next(n int) []Revision { // currHash is the last revision from the last call, so skip it args = append(args, "--skip=1", stream.currHash) } + res, err := gitLog(args...) if err != nil { log.Fatal(err) @@ -70,6 +76,7 @@ func (stream *recentChangesStream) next(n int) []Revision { if len(res) != 0 { stream.currHash = res[len(res)-1].Hash } + return res }