diff --git a/knotserver/git/post_receive.go b/knotserver/git/post_receive.go --- a/knotserver/git/post_receive.go +++ b/knotserver/git/post_receive.go @@ -3,6 +3,7 @@ import ( "bufio" "context" + "errors" "fmt" "io" "strings" @@ -57,29 +58,25 @@ type CommitCount struct { ByEmail map[string]int } -func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) RefUpdateMeta { +func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) (RefUpdateMeta, error) { + var errs error + commitCount, err := g.newCommitCount(line) - if err != nil { - // TODO: log this - } + errors.Join(errs, err) isDefaultRef, err := g.isDefaultBranch(line) - if err != nil { - // TODO: log this - } + errors.Join(errs, err) ctx, cancel := context.WithTimeout(context.Background(), time.Second*2) defer cancel() breakdown, err := g.AnalyzeLanguages(ctx) - if err != nil { - // TODO: log this - } + errors.Join(errs, err) return RefUpdateMeta{ CommitCount: commitCount, IsDefaultRef: isDefaultRef, LangBreakdown: breakdown, - } + }, errs } func (g *GitRepo) newCommitCount(line PostReceiveLine) (CommitCount, error) { @@ -95,8 +92,18 @@ args := []string{fmt.Sprintf("--max-count=%d", 100)} if line.OldSha.IsZero() { - // just git rev-list + // git rev-list ^other-branches --not ^this-branch args = append(args, line.NewSha.String()) + + branches, _ := g.Branches() + for _, b := range branches { + if !strings.Contains(line.Ref, b.Name) { + args = append(args, fmt.Sprintf("^%s", b.Name)) + } + } + + args = append(args, "--not") + args = append(args, fmt.Sprintf("^%s", line.Ref)) } else { // git rev-list .. args = append(args, fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String())) diff --git a/knotserver/internal.go b/knotserver/internal.go --- a/knotserver/internal.go +++ b/knotserver/internal.go @@ -3,6 +3,7 @@ import ( "context" "encoding/json" + "errors" "fmt" "log/slog" "net/http" @@ -145,7 +146,9 @@ if err != nil { return fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err) } - meta := gr.RefUpdateMeta(line) + var errs error + meta, err := gr.RefUpdateMeta(line) + errors.Join(errs, err) metaRecord := meta.AsRecord() @@ -169,7 +172,7 @@ Nsid: tangled.GitRefUpdateNSID, EventJson: string(eventJson), } - return h.db.InsertEvent(event, h.n) + return errors.Join(errs, h.db.InsertEvent(event, h.n)) } func (h *InternalHandle) triggerPipeline(clientMsgs *[]string, line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {