From 49717721680d64c5acbefd5a8e0a24afcffba217 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 22 May 2020 12:57:41 -0400 Subject: [PATCH] API: return nil if HEAD reference does not exist --- api/go.mod | 4 ++-- api/go.sum | 4 ++++ api/graph/model/repository.go | 4 ++++ api/loaders/middleware.go | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/go.mod b/api/go.mod index 1e8bbc2..69db2bb 100644 --- a/api/go.mod +++ b/api/go.mod @@ -4,7 +4,7 @@ go 1.14 require ( git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3 - git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200519155752-5492494ccefa + git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200522165442-58de263ab370 github.com/99designs/gqlgen v0.11.4-0.20200512031635-40570d1b4d70 github.com/Masterminds/squirrel v1.4.0 github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect @@ -18,7 +18,7 @@ require ( github.com/lib/pq v1.5.2 github.com/martinlindhe/base36 v1.0.0 github.com/matryer/moq v0.0.0-20200310130814-7721994d1b54 // indirect - github.com/mitchellh/mapstructure v1.3.0 // indirect + github.com/mitchellh/mapstructure v1.3.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.6.0 // indirect github.com/prometheus/common v0.10.0 // indirect diff --git a/api/go.sum b/api/go.sum index 9146a70..2f72bed 100644 --- a/api/go.sum +++ b/api/go.sum @@ -10,6 +10,8 @@ git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200519153250-9929f08a73ba h1:Sar7LLCjGDyP git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200519153250-9929f08a73ba/go.mod h1:V38DHc2+k1GmbNT4pE6OH/2fOXYcZHn9o/PUAEXH1P0= git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200519155752-5492494ccefa h1:yh3hxZcollhjHZHEjkbh9PrBBFFNClYh0b5SAk+zJAY= git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200519155752-5492494ccefa/go.mod h1:V38DHc2+k1GmbNT4pE6OH/2fOXYcZHn9o/PUAEXH1P0= +git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200522165442-58de263ab370 h1:0X9bkwmK7jnqCKAItGF1PIn3SJ2BzJNF1jXN0nq1rcI= +git.sr.ht/~sircmpwn/gql.sr.ht v0.0.0-20200522165442-58de263ab370/go.mod h1:V38DHc2+k1GmbNT4pE6OH/2fOXYcZHn9o/PUAEXH1P0= git.sr.ht/~sircmpwn/gqlgen v0.0.0-20200412134447-57d7234737d4 h1:J/Sb88htNHzZaN6ZEF8BnRWj3LzYoTrOL4WRhZEEiQE= git.sr.ht/~sircmpwn/gqlgen v0.0.0-20200412134447-57d7234737d4/go.mod h1:W1cijL2EqAyL1eo1WAJ3ijNVkZM2okpYyCF5TRu1VfI= github.com/99designs/gqlgen v0.11.3 h1:oFSxl1DFS9X///uHV3y6CEfpcXWrDUxVblR4Xib2bs4= @@ -142,6 +144,8 @@ github.com/mitchellh/mapstructure v1.2.2 h1:dxe5oCinTXiTIcfgmZecdCzPmAJKd46KsCWc github.com/mitchellh/mapstructure v1.2.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.3.0 h1:iDwIio/3gk2QtLLEsqU5lInaMzos0hDTz8a6lazSFVw= github.com/mitchellh/mapstructure v1.3.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.3.1 h1:cCBH2gTD2K0OtLlv/Y5H01VQCqmlDxz30kS5Y5bqfLA= +github.com/mitchellh/mapstructure v1.3.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= diff --git a/api/graph/model/repository.go b/api/graph/model/repository.go index 0b030a8..b944da3 100644 --- a/api/graph/model/repository.go +++ b/api/graph/model/repository.go @@ -7,6 +7,7 @@ import ( "strconv" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" sq "github.com/Masterminds/squirrel" "git.sr.ht/~sircmpwn/gql.sr.ht/database" @@ -44,6 +45,9 @@ func (r *Repository) Repo() *git.Repository { func (r *Repository) Head() *Reference { ref, err := r.Repo().Head() if err != nil { + if err == plumbing.ErrReferenceNotFound { + return nil + } panic(err) } return &Reference{Ref: ref, Repo: r.repo} diff --git a/api/loaders/middleware.go b/api/loaders/middleware.go index ea8c157..9350921 100644 --- a/api/loaders/middleware.go +++ b/api/loaders/middleware.go @@ -21,7 +21,7 @@ import ( "git.sr.ht/~sircmpwn/git.sr.ht/api/graph/model" ) -var loadersCtxKey = &contextKey{"user"} +var loadersCtxKey = &contextKey{"loaders"} type contextKey struct { name string -- 2.38.4