Skip to content

Commit b9e6d94

Browse files
authored
zoekt-indexserver: Check stderr for git fetch (#603)
Instead of checking stdout, we check the combined output. By default, git fetch writes to stderr.
1 parent 7078a58 commit b9e6d94

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

cmd/zoekt-indexserver/main.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,15 @@ func periodicFetch(repoDir, indexDir string, opts *Options, pendingRepos chan<-
130130
// update.
131131
func fetchGitRepo(dir string) bool {
132132
cmd := exec.Command("git", "--git-dir", dir, "fetch", "origin")
133-
outBuf := &bytes.Buffer{}
134-
errBuf := &bytes.Buffer{}
135133

136-
// Prevent prompting
137-
cmd.Stdin = &bytes.Buffer{}
138-
cmd.Stderr = errBuf
139-
cmd.Stdout = outBuf
140-
if err := cmd.Run(); err != nil {
141-
log.Printf("command %s failed: %v\nOUT: %s\nERR: %s",
142-
cmd.Args, err, outBuf.String(), errBuf.String())
143-
} else {
144-
return len(outBuf.Bytes()) != 0
134+
output, err := cmd.CombinedOutput()
135+
if err != nil {
136+
log.Printf("command %s failed: %v\nCOMBINED_OUT: %s\n",
137+
cmd.Args, err, string(output))
138+
return false
145139
}
146-
return false
140+
// When fetch found no updates, it prints nothing out
141+
return len(output) != 0
147142
}
148143

149144
// indexPendingRepos consumes the directories on the repos channel and

0 commit comments

Comments
 (0)