Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Examples:
IsRepo: true,
}
} else {
info, err := deployer.GetGitInfo(logger, dir)
info, err := deployer.GetGitInfoRecursive(logger, dir)
if err != nil {
logger.Debug("Failed to get git info: %v", err)
}
Expand Down
40 changes: 40 additions & 0 deletions internal/deployer/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,43 @@ func GetGitInfo(logger logger.Logger, dir string) (*GitInfo, error) {

return info, nil
}

// GetGitInfoRecursive walks up directories until it finds a git repo and returns its info
func GetGitInfoRecursive(logger logger.Logger, startDir string) (*GitInfo, error) {
depth := 0
dir := startDir
for {
if depth >= 100 {
logger.Warn("Max depth reached while trying to find git dir")
return &GitInfo{}, nil
}
info, err := GetGitInfo(logger, dir)
if err != nil {
return nil, err
}
if info != nil && info.IsRepo {
return info, nil
}

parent := parentDir(dir)
if parent == dir {
break
}
dir = parent
depth++
}
return &GitInfo{}, nil
}

// parentDir returns the parent directory of the given path
func parentDir(path string) string {
if path == "/" {
return path
}
cleaned := strings.TrimRight(path, "/")
idx := strings.LastIndex(cleaned, "/")
if idx <= 0 {
return "/"
}
return cleaned[:idx]
}
Loading