Resolve LFS objects from git common dir

This commit is contained in:
2026-04-18 16:03:49 +02:00
parent dfde20f679
commit 8e7ffd8f4f
2 changed files with 75 additions and 3 deletions
+53
View File
@@ -1874,6 +1874,59 @@ func TestPlanHAKChunksPutsNewestAssetsInLastChunk(t *testing.T) {
}
}
func TestCollectLFSAssetInfoUsesGitCommonDirForWorktree(t *testing.T) {
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git not available")
}
parent := t.TempDir()
repoRoot := filepath.Join(parent, "repo")
worktreeRoot := filepath.Join(parent, "worktree")
mustMkdir(t, repoRoot)
runGitTest(t, repoRoot, "init")
mustWriteFile(t, filepath.Join(repoRoot, "README.md"), "test\n")
runGitTest(t, repoRoot, "add", ".")
runGitTest(t, repoRoot, "config", "user.name", "Test User")
runGitTest(t, repoRoot, "config", "user.email", "test@example.com")
runGitTest(t, repoRoot, "commit", "-m", "initial")
runGitTest(t, repoRoot, "worktree", "add", worktreeRoot, "HEAD")
oid := strings.Repeat("a", 64)
assetRel := filepath.Join("core", "foo.mdl")
assetPath := filepath.Join(worktreeRoot, "assets", assetRel)
mustMkdir(t, filepath.Dir(assetPath))
mustWriteFile(t, assetPath, "version https://git-lfs.github.com/spec/v1\n"+"oid sha256:"+oid+"\n"+"size 5\n")
lfsObjectPath := filepath.Join(repoRoot, ".git", "lfs", "objects", oid[:2], oid[2:4], oid)
mustMkdir(t, filepath.Dir(lfsObjectPath))
mustWriteFile(t, lfsObjectPath, "model")
proj := &project.Project{
Root: worktreeRoot,
Config: project.Config{
Paths: project.PathConfig{Source: "src", Assets: "assets", Build: "build"},
},
Inventory: project.Inventory{
AssetFiles: []string{filepath.ToSlash(assetRel)},
},
}
infos, err := collectLFSAssetInfo(proj)
if err != nil {
t.Fatalf("collect lfs asset info: %v", err)
}
info, ok := infos[filepath.ToSlash(assetRel)]
if !ok {
t.Fatal("expected LFS asset info")
}
if got, want := info.ObjectPath, lfsObjectPath; got != want {
t.Fatalf("unexpected LFS object path:\ngot %s\nwant %s", got, want)
}
if _, err := lfsPathResource(assetPath, info, true); err != nil {
t.Fatalf("expected worktree LFS object to resolve: %v", err)
}
}
func runGitCommitTest(t *testing.T, dir, timestamp, message string) {
t.Helper()
runGitTest(t, dir, "add", ".")