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
+22 -3
View File
@@ -733,10 +733,14 @@ func chunksFromManifest(assets []assetResource, entries []BuildManifestHAK) ([]h
func collectLFSAssetInfo(p *project.Project) (map[string]lfsAssetInfo, error) {
result := make(map[string]lfsAssetInfo)
lfsObjectRoot, err := resolveLFSObjectRoot(p.Root)
if err != nil {
return nil, err
}
for _, rel := range p.Inventory.AssetFiles {
rel = filepath.ToSlash(rel)
abs := filepath.Join(p.AssetsDir(), filepath.FromSlash(rel))
info, ok, err := parseLFSPointerFile(abs, p.Root)
info, ok, err := parseLFSPointerFile(abs, lfsObjectRoot)
if err != nil {
return nil, err
}
@@ -748,7 +752,22 @@ func collectLFSAssetInfo(p *project.Project) (map[string]lfsAssetInfo, error) {
return result, nil
}
func parseLFSPointerFile(path, repoRoot string) (lfsAssetInfo, bool, error) {
func resolveLFSObjectRoot(repoRoot string) (string, error) {
output, err := gitOutput(repoRoot, "rev-parse", "--git-common-dir")
if err != nil {
return filepath.Join(repoRoot, ".git", "lfs", "objects"), nil
}
commonDir := strings.TrimSpace(output)
if commonDir == "" {
return filepath.Join(repoRoot, ".git", "lfs", "objects"), nil
}
if !filepath.IsAbs(commonDir) {
commonDir = filepath.Join(repoRoot, commonDir)
}
return filepath.Join(filepath.Clean(commonDir), "lfs", "objects"), nil
}
func parseLFSPointerFile(path, lfsObjectRoot string) (lfsAssetInfo, bool, error) {
entry, err := os.Lstat(path)
if err != nil {
return lfsAssetInfo{}, false, fmt.Errorf("stat %s: %w", path, err)
@@ -784,7 +803,7 @@ func parseLFSPointerFile(path, repoRoot string) (lfsAssetInfo, bool, error) {
return lfsAssetInfo{}, false, nil
}
if len(info.OID) >= 4 {
info.ObjectPath = filepath.Join(repoRoot, ".git", "lfs", "objects", info.OID[:2], info.OID[2:4], info.OID)
info.ObjectPath = filepath.Join(lfsObjectRoot, info.OID[:2], info.OID[2:4], info.OID)
}
return info, true, nil
}