diff --git a/cmd/skillshare/uninstall.go b/cmd/skillshare/uninstall.go index 808656358..21c957ae3 100644 --- a/cmd/skillshare/uninstall.go +++ b/cmd/skillshare/uninstall.go @@ -146,25 +146,21 @@ func resolveUninstallTarget(skillName, sourceDir, sourceLabel string, walk sourc return nil, fmt.Errorf("invalid skill name: %q", skillName) } - // Normalize _ prefix for tracked repos - if !strings.HasPrefix(skillName, "_") { - prefixedPath := filepath.Join(sourceDir, "_"+skillName) - if install.IsGitRepo(prefixedPath) { - skillName = "_" + skillName - } - } - skillPath := filepath.Join(sourceDir, skillName) info, err := os.Stat(skillPath) if err != nil { if os.IsNotExist(err) { - // Fallback: search by basename in nested directories - resolved, resolveErr := resolveNestedSkillDir(sourceDir, skillName, sourceLabel, walk) - if resolveErr != nil { - return nil, resolveErr + // Preserve an existing typed path before trying tracked-repo shorthand. + if repoName, repoPath := install.FindTrackedCheckoutUnlessSkill(sourceDir, skillName); repoPath != "" { + skillName, skillPath = repoName, repoPath + } else { + resolved, resolveErr := resolveNestedSkillDir(sourceDir, skillName, sourceLabel, walk) + if resolveErr != nil { + return nil, resolveErr + } + skillName = resolved + skillPath = filepath.Join(sourceDir, resolved) } - skillName = resolved - skillPath = filepath.Join(sourceDir, resolved) } else { return nil, fmt.Errorf("cannot access skill: %w", err) } @@ -175,7 +171,7 @@ func resolveUninstallTarget(skillName, sourceDir, sourceLabel string, walk sourc return &uninstallTarget{ name: skillName, path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }, nil } @@ -197,7 +193,7 @@ func resolveUninstallByGlob(pattern, sourceDir string, walk sourcewalk.Options) targets = append(targets, &uninstallTarget{ name: e.Name(), path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }) } } @@ -256,7 +252,7 @@ func resolveGroupSkills(group, sourceDir string, walks ...sourcewalk.Options) ([ if _, statErr := os.Stat(filepath.Join(path, "SKILL.md")); statErr == nil { hasSkillMD = true } - isRepo := install.IsGitRepo(path) + isRepo := install.IsTrackedCheckout(path) if hasSkillMD || isRepo { rel, relErr := filepath.Rel(resolvedSourceDir, logicalPath) @@ -344,7 +340,7 @@ func countGroupSkills(dir string) []string { names = append(names, fi.Name()) return filepath.SkipDir } - if install.IsGitRepo(path) { + if install.IsTrackedCheckout(path) { names = append(names, fi.Name()) return filepath.SkipDir } diff --git a/cmd/skillshare/uninstall_handlers.go b/cmd/skillshare/uninstall_handlers.go index 16dfdaa7c..a1448a707 100644 --- a/cmd/skillshare/uninstall_handlers.go +++ b/cmd/skillshare/uninstall_handlers.go @@ -206,7 +206,7 @@ func runUninstallSkills(opts *uninstallOptions, mode *uninstallMode, rawArgs []s targets = append(targets, &uninstallTarget{ name: dir, path: skillPath, - isTrackedRepo: install.IsGitRepo(skillPath), + isTrackedRepo: install.IsTrackedCheckout(skillPath), }) seen[skillPath] = true } diff --git a/cmd/skillshare/uninstall_test.go b/cmd/skillshare/uninstall_test.go index 7939319d8..467e11c7b 100644 --- a/cmd/skillshare/uninstall_test.go +++ b/cmd/skillshare/uninstall_test.go @@ -5,7 +5,6 @@ import ( "path/filepath" "testing" - "skillshare/internal/install" "skillshare/internal/sourcewalk" ) @@ -116,5 +115,54 @@ func TestResolveUninstallByGlob_SkipsFiles(t *testing.T) { } } -// Verify unused imports are referenced -var _ = install.IsGitRepo +func TestResolveUninstallTarget_TrackedNames(t *testing.T) { + for _, tc := range []struct { + name, input, existing, want string + repo bool + }{ + {"nested shorthand", "org/team", "", "org/_team", true}, + {"nested explicit", "org/_team", "", "org/_team", true}, + {"trailing slash", "org/team/", "", "org/_team", true}, + {"nested skill wins", "org/team", "org/team", "org/team", false}, + {"nested folder wins", "org/folder", "org/folder", "org/folder", false}, + {"top-level skill wins", "team", "team", "team", false}, + {"top-level shorthand", "team", "", "_team", true}, + {"top-level explicit", "_team", "", "_team", true}, + {"plain git checkout", "plain", "plain/.git", "plain", false}, + } { + t.Run(tc.name, func(t *testing.T) { + src := t.TempDir() + for _, name := range []string{"_team/.git", "org/_team/.git", "org/_folder/.git", tc.existing} { + if name != "" { + if err := os.MkdirAll(filepath.Join(src, name), 0755); err != nil { + t.Fatal(err) + } + } + } + if tc.existing == "org/team" || tc.existing == "team" { + if err := os.WriteFile(filepath.Join(src, tc.existing, "SKILL.md"), []byte("# Skill"), 0644); err != nil { + t.Fatal(err) + } + } + got, err := resolveUninstallTarget(tc.input, src, "source", sourcewalk.Options{}) + if err != nil { + t.Fatal(err) + } + if got.name != tc.want || got.path != filepath.Join(src, tc.want) || got.isTrackedRepo != tc.repo { + t.Fatalf("target = %+v, want name %q, tracked %v", got, tc.want, tc.repo) + } + }) + } +} + +func TestResolveUninstallTarget_AmbiguousNestedName(t *testing.T) { + src := t.TempDir() + for _, name := range []string{"a/_team/.git", "b/_team/.git"} { + if err := os.MkdirAll(filepath.Join(src, name), 0755); err != nil { + t.Fatal(err) + } + } + if _, err := resolveUninstallTarget("team", src, "source", sourcewalk.Options{}); err == nil { + t.Fatal("ambiguous shorthand must fail") + } +} diff --git a/skills/skillshare/references/install.md b/skills/skillshare/references/install.md index 61fd61784..2d5ff987e 100644 --- a/skills/skillshare/references/install.md +++ b/skills/skillshare/references/install.md @@ -198,6 +198,8 @@ skillshare uninstall --group frontend --dry-run skillshare uninstall my-skill --json ``` +**Tracked repo names:** `uninstall org/team` accepts the shorthand for `org/_team` installed with `--into org`. An existing skill or folder at the typed path wins; use `org/_team` to explicitly remove the repo. Ambiguous short names require the full path. + **Safety:** Tracked repos with uncommitted changes are skipped, and repos whose git status cannot be read fail. Use `--force` to override both. **Group auto-detection:** When uninstalling a directory that contains sub-skills, the confirmation prompt shows `Uninstalling group (N skills)` with a list of contained skills. diff --git a/website/docs/reference/commands/uninstall.md b/website/docs/reference/commands/uninstall.md index 7fd043e47..c61f72bde 100644 --- a/website/docs/reference/commands/uninstall.md +++ b/website/docs/reference/commands/uninstall.md @@ -175,6 +175,7 @@ For tracked repositories (folders starting with `_`): - Automatically removes the entry from `.gitignore` - The `_` prefix is optional when uninstalling - A repo installed with `--into` is named by its path, such as `devops/_team-skills` +- For `--into` repos, the final `_` is optional too: `devops/team-skills` resolves to `devops/_team-skills`. An existing skill or folder at the typed path takes precedence; use the explicit `_` path to remove the repo. Ambiguous short names fail and require the full path. - A skill or folder inside a tracked repo cannot be removed on its own, even with `--force`; the command fails with `inside a tracked repo; uninstall the repo instead`. Skills below a followed source link can still be removed one at a time ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## Examples diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index 51214c182..c1dc88468 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ tracked repositories(`_` で始まるフォルダ)の場合: - `.gitignore` からエントリを自動的に削除します - uninstall 時に `_` prefix は省略可能です - `--into` でインストールしたリポジトリは `devops/_team-skills` のようにパスで指定します +- `--into` のリポジトリも末尾の `_` を省略できます。`devops/team-skills` は `devops/_team-skills` を指定します。入力したパスに既存の Skill やフォルダがある場合はそちらを優先するため、リポジトリを削除するには `_` を含むパスを指定してください。短い名前が複数に一致する場合は失敗し、完全なパスが必要です。 - 追跡リポジトリ内の Skill やフォルダは、`--force` を付けても単独では削除できず、`inside a tracked repo; uninstall the repo instead` で失敗します。followed source link 配下の Skill は 1 つずつ削除できます ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # prefix 付き skillshare uninstall team-skills # prefix なし(自動検出) skillshare uninstall _team-skills --force # 未コミットの変更があっても強制削除 skillshare uninstall devops/_team-skills # --into devops でインストールしたリポジトリ +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 例 diff --git a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index 69dcf1e05..7bbbff08e 100644 --- a/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/ko/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ tracked repository(`_`로 시작하는 폴더)의 경우: - `.gitignore`에서 항목을 자동으로 제거합니다 - uninstall 시 `_` 접두사는 선택 사항입니다 - `--into`로 설치한 repo는 `devops/_team-skills`처럼 경로로 지정합니다 +- `--into` repo도 마지막 `_`를 생략할 수 있습니다. `devops/team-skills`는 `devops/_team-skills`로 해석됩니다. 입력한 경로에 skill이나 폴더가 있으면 그것을 우선하므로 repo를 제거하려면 `_`가 포함된 경로를 사용하세요. 짧은 이름이 여러 항목과 일치하면 실패하며 전체 경로가 필요합니다. - tracked repo 안의 skill이나 폴더는 `--force`를 붙여도 따로 제거할 수 없으며, `inside a tracked repo; uninstall the repo instead`로 실패합니다. followed source link 아래의 skill은 하나씩 제거할 수 있습니다 ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 예시 diff --git a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index be55bf789..ac030cb55 100644 --- a/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/zh-Hans/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -180,6 +180,7 @@ skillshare uninstall frontend/hooks -G frontend --force # hooks removed once - 自动从 `.gitignore` 中移除该条目 - Uninstall 时 `_` 前缀是可选的 - 用 `--into` 安装的 repo 以路径命名,例如 `devops/_team-skills` +- `--into` repo 最后一段的 `_` 也可以省略:`devops/team-skills` 会解析为 `devops/_team-skills`。输入路径上已有的 Skill 或文件夹优先;要移除 repo,请使用含 `_` 的完整路径。短名称匹配多个项目时会失败,必须指定完整路径。 - tracked repo 中的 Skill 或文件夹不能单独移除,加上 `--force` 也一样;命令会以 `inside a tracked repo; uninstall the repo instead` 失败。位于 followed source link 下的 Skill 仍可逐个移除 ```bash @@ -187,6 +188,7 @@ skillshare uninstall _team-skills # With prefix skillshare uninstall team-skills # Without prefix (auto-detected) skillshare uninstall _team-skills --force # Force remove with uncommitted changes skillshare uninstall devops/_team-skills # Repo installed with --into devops +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 示例 diff --git a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md index ba6ecd5d0..7ee245514 100644 --- a/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md +++ b/website/i18n/zh-Hant/docusaurus-plugin-content-docs/current/reference/commands/uninstall.md @@ -175,6 +175,7 @@ skillshare uninstall frontend/hooks -G frontend --force # hooks 只會被移除 - 自動從 `.gitignore` 移除該項目 - 解除安裝時 `_` 前綴為選填 - 用 `--into` 安裝的 repo 以路徑命名,例如 `devops/_team-skills` +- `--into` repo 最後一段的 `_` 也可以省略:`devops/team-skills` 會解析為 `devops/_team-skills`。輸入路徑上既有的 skill 或資料夾優先;要移除 repo,請使用含 `_` 的完整路徑。短名稱匹配多個項目時會失敗,必須指定完整路徑。 - tracked repo 裡的 skill 或資料夾不能單獨移除,加上 `--force` 也一樣;指令會以 `inside a tracked repo; uninstall the repo instead` 失敗。位於 followed source link 底下的 skill 仍可逐一移除 ```bash @@ -182,6 +183,7 @@ skillshare uninstall _team-skills # 含前綴 skillshare uninstall team-skills # 不含前綴(自動偵測) skillshare uninstall _team-skills --force # 強制移除,即使有未提交的變更 skillshare uninstall devops/_team-skills # 用 --into devops 安裝的 repo +skillshare uninstall devops/team-skills # Same repo, unless this path already exists ``` ## 範例