Commit 6f92a907 authored by ZJ van de Weg's avatar ZJ van de Weg Committed by Z.J. van de Weg

Incorporate feedback

parent e520eb91
...@@ -28,24 +28,26 @@ func (d *diff) Inject(w http.ResponseWriter, r *http.Request, sendData string) { ...@@ -28,24 +28,26 @@ func (d *diff) Inject(w http.ResponseWriter, r *http.Request, sendData string) {
log.Printf("SendDiff: sending diff between %q and %q for %q", params.ShaFrom, params.ShaTo, r.URL.Path) log.Printf("SendDiff: sending diff between %q and %q for %q", params.ShaFrom, params.ShaTo, r.URL.Path)
gitShowCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo) gitDiffCmd := gitCommand("", "git", "--git-dir="+params.RepoPath, "diff", params.ShaFrom, params.ShaTo)
stdout, err := gitShowCmd.StdoutPipe() stdout, err := gitDiffCmd.StdoutPipe()
if err != nil { if err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: git diff %q %q stdout: %v", params.ShaFrom, params.ShaTo, err)) helper.Fail500(w, fmt.Errorf("SendDiff: create stdout pipe: %v", err))
return return
} }
if err := gitShowCmd.Start(); err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: git diff %q %q stdout: %v", params.ShaFrom, params.ShaTo, err)) if err := gitDiffCmd.Start(); err != nil {
helper.Fail500(w, fmt.Errorf("SendDiff: start %v: %v", gitDiffCmd, err))
return return
} }
defer helper.CleanUpProcessGroup(gitShowCmd) defer helper.CleanUpProcessGroup(gitDiffCmd)
w.Header().Del("Content-Length")
if _, err := io.Copy(w, stdout); err != nil { if _, err := io.Copy(w, stdout); err != nil {
helper.LogError(fmt.Errorf("SendDiff: git diff %q %q stdout: %v", err)) helper.LogError(fmt.Errorf("SendDiff: copy %v stdout: %v", gitDiffCmd, err))
return return
} }
if err := gitShowCmd.Wait(); err != nil { if err := gitDiffCmd.Wait(); err != nil {
helper.LogError(fmt.Errorf("SendDiff: git diff %q %q stdout: %v", err)) helper.LogError(fmt.Errorf("SendDiff: wait for %v: %v", gitDiffCmd, err))
return return
} }
} }
...@@ -610,10 +610,10 @@ func TestGetGitDiff(t *testing.T) { ...@@ -610,10 +610,10 @@ func TestGetGitDiff(t *testing.T) {
w.Header().Set(headerKey, "git-diff:"+encodedJSON) w.Header().Set(headerKey, "git-diff:"+encodedJSON)
return return
}) })
defer ts.Close() defer ts.Close()
ws := startWorkhorseServer(ts.URL) ws := startWorkhorseServer(ts.URL)
defer ts.Close() defer ws.Close()
resourcePath := "/something" resourcePath := "/something"
resp, err := http.Get(ws.URL + resourcePath) resp, err := http.Get(ws.URL + resourcePath)
...@@ -636,6 +636,11 @@ func TestGetGitDiff(t *testing.T) { ...@@ -636,6 +636,11 @@ func TestGetGitDiff(t *testing.T) {
if !strings.HasPrefix(string(body), "diff --git a/README b/README") { if !strings.HasPrefix(string(body), "diff --git a/README b/README") {
t.Fatalf("diff --git a/README b/README, got %q", body) t.Fatalf("diff --git a/README b/README, got %q", body)
} }
bodyLengthBytes := len(body)
if bodyLengthBytes != 155 {
t.Fatal("Expected the body to consist of 155 bytes, got %v", bodyLengthBytes)
}
} }
func setupStaticFile(fpath, content string) error { func setupStaticFile(fpath, content string) error {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment