From decbce262df3b5564de19930baa95882aa938026 Mon Sep 17 00:00:00 2001 From: Eduardo Tongson Date: Sat, 24 Aug 2024 14:33:48 +0800 Subject: [PATCH] There is a bug with paths longer than 80 characters. When running `git pull --stat` for changes with these long paths. You get a truncated path: (#79) ``` .../deeply/nested/directory/hierarchy/this.service | 6 +++--- ``` This will not match the set `dir` in the gitopper configuration. Unfortunately you cannot set the maximum width in `git pull --stat` but possible with `git diff --stat`. We have to separate the steps when checking for changes. That is, `git fetch`, `git diff`, then `git merge`. The default kernel-imposed limit in Linux is 4096 so just use that too. It does `git diff` now so we can also set `--name-only` to get a clean output for string matching. We can skip matching the path inside the `git pull --stat` output format. --- gitcmd/diffstat.go | 8 +++----- gitcmd/git.go | 8 +++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gitcmd/diffstat.go b/gitcmd/diffstat.go index 68438aa..3461ea7 100644 --- a/gitcmd/diffstat.go +++ b/gitcmd/diffstat.go @@ -28,11 +28,9 @@ func (g *Git) OfInterest(data []byte) bool { // bunch of lines usually < 1000. So it's not too bad. for scanner.Scan() { text := scanner.Text() - if strings.HasPrefix(text, " ") && strings.Contains(text, " | ") { - for _, d := range g.dirs { - if strings.Contains(text, d) { - return true - } + for _, d := range g.dirs { + if strings.Contains(text, d) { + return true } } } diff --git a/gitcmd/git.go b/gitcmd/git.go index 746bc96..4ff0384 100644 --- a/gitcmd/git.go +++ b/gitcmd/git.go @@ -120,10 +120,16 @@ func (g *Git) Pull() (bool, error) { g.cwd = g.mount defer func() { g.cwd = "" }() - out, err := g.run("pull", "--stat", "origin", g.branch) + if _, err := g.run("fetch"); err != nil { + return false, err + } + out, err := g.run("diff", "--stat=4096", "--name-only", g.branch, fmt.Sprintf("origin/%s", g.branch)) if err != nil { return false, err } + if _, err := g.run("merge"); err != nil { + return false, err + } return g.OfInterest(out), nil }