Skip to content

Commit

Permalink
There is a bug with paths longer than 80 characters. When running `gi…
Browse files Browse the repository at this point in the history
…t 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.
  • Loading branch information
tongson authored Aug 24, 2024
1 parent b0c65ec commit decbce2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 3 additions & 5 deletions gitcmd/diffstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion gitcmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit decbce2

Please sign in to comment.