If a meta file heater was present but no sha, a panic would occur. Return an error instead.

This commit is contained in:
rubyist 2014-06-04 12:01:45 -04:00
parent f1276a1d04
commit d1f05fb202
2 changed files with 11 additions and 0 deletions

@ -32,6 +32,10 @@ func Decode(reader io.Reader) (string, error) {
return "", err
}
if len(lines) < 2 {
return "", errors.New("No sha in meta file")
}
if matched {
return string(lines[1]), nil
}

@ -51,3 +51,10 @@ func TestDecodeInvalid(t *testing.T) {
t.Errorf("Decoded invalid sha")
}
}
func TestDecodeWithValidHeaderNoSha(t *testing.T) {
buf := bytes.NewBufferString("# git-media")
if _, err := Decode(buf); err == nil {
t.Errorf("Decoded with header but no sha")
}
}