fixes if git cat-file has error
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@@ -554,7 +553,6 @@ func parseGitTree(data <-chan byte) (GitTree, error) {
|
|||||||
parsedLen := 0
|
parsedLen := 0
|
||||||
for parsedLen < hdr.size {
|
for parsedLen < hdr.size {
|
||||||
entry, err := parseTreeEntry(data, len(hdr.hash)/2)
|
entry, err := parseTreeEntry(data, len(hdr.hash)/2)
|
||||||
log.Println(entry, parsedLen, hdr.size)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GitTree{}, nil
|
return GitTree{}, nil
|
||||||
}
|
}
|
||||||
@@ -650,14 +648,18 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
|||||||
|
|
||||||
data_out.Write([]byte(commitId))
|
data_out.Write([]byte(commitId))
|
||||||
data_out.ch <- '\x00'
|
data_out.ch <- '\x00'
|
||||||
c, err := parseGitCommit(data_in.ch)
|
|
||||||
|
var c GitCommit
|
||||||
|
c, err = parseGitCommit(data_in.ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("Error parsing git commit:", err)
|
LogError("Error parsing git commit:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data_out.Write([]byte(c.Tree))
|
data_out.Write([]byte(c.Tree))
|
||||||
data_out.ch <- '\x00'
|
data_out.ch <- '\x00'
|
||||||
tree, err := parseGitTree(data_in.ch)
|
|
||||||
|
var tree GitTree
|
||||||
|
tree, err = parseGitTree(data_in.ch)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogError("Error parsing git tree:", err)
|
LogError("Error parsing git tree:", err)
|
||||||
@@ -691,8 +693,11 @@ func (e *GitHandlerImpl) GitCatFile(cwd, commitId, filename string) (data []byte
|
|||||||
return len(data), nil
|
return len(data), nil
|
||||||
})
|
})
|
||||||
LogDebug("command run:", cmd.Args)
|
LogDebug("command run:", cmd.Args)
|
||||||
err = cmd.Run()
|
if e := cmd.Run(); e != nil {
|
||||||
|
close(data_in.ch)
|
||||||
|
close(data_out.ch)
|
||||||
|
return nil, e
|
||||||
|
}
|
||||||
done.Lock()
|
done.Lock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func TestGitClone(t *testing.T) {
|
|||||||
}
|
}
|
||||||
d := t.TempDir()
|
d := t.TempDir()
|
||||||
os.Chdir(d)
|
os.Chdir(d)
|
||||||
|
defer os.Chdir(execPath)
|
||||||
cmd := exec.Command("/usr/bin/bash", path.Join(execPath, "test_clone_setup.sh"))
|
cmd := exec.Command("/usr/bin/bash", path.Join(execPath, "test_clone_setup.sh"))
|
||||||
if _, err := cmd.Output(); err != nil {
|
if _, err := cmd.Output(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@@ -333,7 +334,7 @@ Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>` + "\x00"
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommitTreeParsingOfHead(t *testing.T) {
|
func TestCommitTreeParsing(t *testing.T) {
|
||||||
gitDir := t.TempDir()
|
gitDir := t.TempDir()
|
||||||
testDir, _ := os.Getwd()
|
testDir, _ := os.Getwd()
|
||||||
var commitId string
|
var commitId string
|
||||||
@@ -348,11 +349,58 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
|||||||
t.Fatal(err.Error())
|
t.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gh, err := AllocateGitWorkTree(gitDir, "", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("GitCatFile commit", func(t *testing.T) {
|
||||||
|
h, _ := gh.ReadExistingPath(".")
|
||||||
|
defer h.Close()
|
||||||
|
|
||||||
|
file, err := h.GitCatFile("", commitId, "help")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(file) != "help\n" {
|
||||||
|
t.Error("expected 'help\\n' but got", string(file))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GitCatFile commit", func(t *testing.T) {
|
||||||
|
h, _ := gh.ReadExistingPath(".")
|
||||||
|
defer h.Close()
|
||||||
|
|
||||||
|
file, err := h.GitCatFile("", "HEAD", "help")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(file) != "help\n" {
|
||||||
|
t.Error("expected 'help\\n' but got", string(file))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GitCatFile bad commit", func(t *testing.T) {
|
||||||
|
h, _ := gh.ReadExistingPath(".")
|
||||||
|
defer h.Close()
|
||||||
|
|
||||||
|
file, err := h.GitCatFile("", "518b468f391bf01d5d76d497d7cbecfa8b46d185714cf8745800ae18afb21afd", "help")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected error, but not nothing")
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(file) != "" {
|
||||||
|
t.Error("expected 'help\\n' but got", file)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("reads HEAD and parses the tree", func(t *testing.T) {
|
t.Run("reads HEAD and parses the tree", func(t *testing.T) {
|
||||||
const nodejs21 = "c678c57007d496a98bec668ae38f2c26a695f94af78012f15d044ccf066ccb41"
|
const nodejs21 = "c678c57007d496a98bec668ae38f2c26a695f94af78012f15d044ccf066ccb41"
|
||||||
h := GitHandlerImpl{
|
h, _ := gh.ReadExistingPath(".")
|
||||||
GitPath: gitDir,
|
defer h.Close()
|
||||||
}
|
|
||||||
id, ok := h.GitSubmoduleCommitId("", "nodejs21", commitId)
|
id, ok := h.GitSubmoduleCommitId("", "nodejs21", commitId)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("failed parse")
|
t.Error("failed parse")
|
||||||
@@ -363,9 +411,9 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("reads README.md", func(t *testing.T) {
|
t.Run("reads README.md", func(t *testing.T) {
|
||||||
h := GitHandlerImpl{
|
h, _ := gh.ReadExistingPath(".")
|
||||||
GitPath: gitDir,
|
defer h.Close()
|
||||||
}
|
|
||||||
data, err := h.GitCatFile("", commitId, "README.md")
|
data, err := h.GitCatFile("", commitId, "README.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed parse: %v", err)
|
t.Errorf("failed parse: %v", err)
|
||||||
@@ -376,9 +424,8 @@ func TestCommitTreeParsingOfHead(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("read HEAD", func(t *testing.T) {
|
t.Run("read HEAD", func(t *testing.T) {
|
||||||
h := GitHandlerImpl{
|
h, _ := gh.ReadExistingPath(".")
|
||||||
GitPath: gitDir,
|
defer h.Close()
|
||||||
}
|
|
||||||
|
|
||||||
data, err := h.GitSubmoduleList("", "HEAD")
|
data, err := h.GitSubmoduleList("", "HEAD")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user