mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
GetTrackedRepos returned OS-native paths, so every caller that compared them with slash paths (RepoRelPath, dashboard repoPath, metadata keys) had to convert first. Two callers in install_queries already did, and this branch added four more. It now returns slash paths on every OS, matching GetMissingTrackedRepos; filepath.Join and filepath.Base accept them on Windows, and `update org/_repo` now also matches by full path there. The per-call-site conversions are gone. Smaller cleanups in the same code: - repoOf takes the slash relPath and looks up prefixes by substring, so the walk no longer splits and joins per directory; - repo .skillignore matchers are keyed by the same slash rel path, so isSkillIgnored no longer needs walkRoot; - batch uninstall uses utils.IsTrackedRepoDir instead of a literal "_"; - the dashboard uses repoOf where it spelled out isInRepo && folderOf; - the new tests reuse postBatchUninstall and share one --into sandbox.
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/sourcewalk"
|
|
)
|
|
|
|
type linkedRepoInfo struct {
|
|
Name string `json:"name"`
|
|
Target string `json:"target"`
|
|
}
|
|
|
|
// dashboardRepos separates user-owned checkouts before any Git checks or updates.
|
|
func dashboardRepos(source string, walk sourcewalk.Options) ([]string, []linkedRepoInfo) {
|
|
repos, _ := install.GetTrackedRepos(source, walk)
|
|
managed := make([]string, 0, len(repos))
|
|
linked := []linkedRepoInfo{}
|
|
seen := map[string]bool{}
|
|
for _, name := range repos {
|
|
path := filepath.Join(source, name)
|
|
if target, ok := walk.Follow.Resolve(path); ok {
|
|
linked = append(linked, linkedRepoInfo{Name: name, Target: target})
|
|
seen[name] = true
|
|
} else {
|
|
managed = append(managed, name)
|
|
}
|
|
}
|
|
// A followed checkout need not have the tracked-repo underscore prefix.
|
|
entries, _ := sourcewalk.ReadDir(source, walk)
|
|
for _, entry := range entries {
|
|
name := entry.Name()
|
|
path := filepath.Join(source, name)
|
|
if target, ok := walk.Follow.Resolve(path); ok && !seen[name] && install.IsGitRepo(path) {
|
|
linked = append(linked, linkedRepoInfo{Name: name, Target: target})
|
|
}
|
|
}
|
|
return managed, linked
|
|
}
|
|
|
|
// followedCheckout also protects skills inside a followed Git checkout.
|
|
func followedCheckout(path string, follow *sourcewalk.Follow) string {
|
|
for {
|
|
target, ok := follow.Resolve(path)
|
|
if !ok {
|
|
return ""
|
|
}
|
|
if install.IsGitRepo(path) {
|
|
return target
|
|
}
|
|
path = filepath.Dir(path)
|
|
}
|
|
}
|
|
|
|
func (s *Server) refuseFollowedCheckout(name, path string, follow []*sourcewalk.Follow) *updateResultItem {
|
|
var policy *sourcewalk.Follow
|
|
if len(follow) > 0 {
|
|
policy = follow[0]
|
|
} else {
|
|
policy = s.skillsWalk().Follow
|
|
}
|
|
if target := followedCheckout(path, policy); target != "" {
|
|
return &updateResultItem{Name: name, Action: "skipped", IsRepo: true,
|
|
Message: fmt.Sprintf("followed checkout %s is managed by you and is not updated by the dashboard", target)}
|
|
}
|
|
return nil
|
|
}
|