gshr
git static host repo -- generates static html for repos
git clone https://git.vogt.world/gshr.git
Log | Files | README.md | LICENSE
← Commit log
commit
message
Some commit patches were wrong with go-git...
author
Ben Vogt <[email protected]>
date
2023-04-10 17:52:48
stats
1 file(s) changed, 15 insertions(+), 3 deletions(-)
files
commit.go
 1diff --git a/commit.go b/commit.go
 2index 101aafe..0c203a9 100644
 3--- a/commit.go
 4+++ b/commit.go
 5@@ -4,7 +4,9 @@ import (
 6 	"errors"
 7 	"html/template"
 8 	"os"
 9+	"os/exec"
10 	"path"
11+	"strings"
12 
13 	"github.com/go-git/go-git/v5"
14 	"github.com/go-git/go-git/v5/plumbing/object"
15@@ -53,11 +55,20 @@ func RenderAllCommitPages(data RepoData, r *git.Repository) {
16 		filesChanged := []string{}
17 		if parent != nil {
18 			patch, err := parent.Patch(c)
19-			checkErr(err)
20-			patchString := patch.String()
21+			// NOTE: Seems to be a bug in go-git that gives us diff patches that are wrong. Could be my
22+			//       usage, but something tells me no. Fixing it by shelling out for now, since we
23+			//       require git to be installed for `git update-server-info` anyway.
24+			cmd := exec.Command("git", "diff", parent.Hash.String(), c.Hash.String())
25+			cmd.Dir = path.Join(args.OutputDir, data.Name)
26+			var out strings.Builder
27+			cmd.Stdout = &out
28+			checkErr(cmd.Run())
29+			patchString := out.String()
30 			highlighted := highlight("x.diff", &patchString)
31-			checkErr(err)
32 			diffContent = template.HTML(highlighted)
33+			checkErr(err)
34+			patch, err = parent.Patch(c)
35+			checkErr(err)
36 			for _, fp := range patch.FilePatches() {
37 				from, to := fp.Files()
38 				if from != nil {