delete corrupt lfs objects so they re-download on the next checkout
This commit is contained in:
parent
0fb75eddfb
commit
e209ddf683
@ -63,6 +63,7 @@ func doFsck(localGitDir string) (bool, error) {
|
||||
if recalculatedOid != p.Pointer.Oid {
|
||||
ok = false
|
||||
Print("Object %s (%s) is corrupt", p.Name, p.Oid)
|
||||
os.RemoveAll(path)
|
||||
}
|
||||
}
|
||||
return ok, nil
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
@ -18,8 +20,14 @@ func TestFsck(t *testing.T) {
|
||||
testFileContent := "test data"
|
||||
h := sha256.New()
|
||||
io.WriteString(h, testFileContent)
|
||||
wantOid := hex.EncodeToString(h.Sum(nil))
|
||||
lfsObjectPath := filepath.Join(repo.Path, ".git", "lfs", "objects", wantOid[0:2], wantOid[2:4], wantOid)
|
||||
oid1 := hex.EncodeToString(h.Sum(nil))
|
||||
lfsObjectPath := filepath.Join(repo.Path, ".git", "lfs", "objects", oid1[0:2], oid1[2:4], oid1)
|
||||
|
||||
testFile2Content := "test data 2"
|
||||
h.Reset()
|
||||
io.WriteString(h, testFile2Content)
|
||||
oid2 := hex.EncodeToString(h.Sum(nil))
|
||||
lfsObject2Path := filepath.Join(repo.Path, ".git", "lfs", "objects", oid2[0:2], oid2[2:4], oid2)
|
||||
|
||||
cmd.Before(func() {
|
||||
path := filepath.Join(repo.Path, ".git", "info", "attributes")
|
||||
@ -27,8 +35,28 @@ func TestFsck(t *testing.T) {
|
||||
|
||||
// Add a Git LFS object
|
||||
repo.WriteFile(filepath.Join(repo.Path, "a.dat"), testFileContent)
|
||||
repo.GitCmd("add", "a.dat")
|
||||
repo.WriteFile(filepath.Join(repo.Path, "b.dat"), testFile2Content)
|
||||
repo.GitCmd("add", "*.dat")
|
||||
repo.GitCmd("commit", "-m", "a")
|
||||
repo.WriteFile(lfsObjectPath, testFileContent+"CORRUPTION")
|
||||
})
|
||||
|
||||
cmd.After(func() {
|
||||
by, err := ioutil.ReadFile(lfsObject2Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
h.Reset()
|
||||
h.Write(by)
|
||||
oid := hex.EncodeToString(h.Sum(nil))
|
||||
if oid != oid2 {
|
||||
t.Errorf("oid for b.dat does not match")
|
||||
}
|
||||
|
||||
_, err = os.Stat(lfsObjectPath)
|
||||
if err == nil {
|
||||
t.Errorf("Expected a.dat to be cleared for being corrupt", lfsObjectPath)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user