From b021544065cda522deb51d2abe546dfa8bd0f644 Mon Sep 17 00:00:00 2001 From: Willie Date: Fri, 9 Oct 2026 23:57:57 +0800 Subject: [PATCH] fix(install): accept a local bare repository path for --track A bare repository has HEAD and objects at its root but no .git entry, so the local-path check rejected it while file:///same/path cloned fine. Add IsLocalGitRepo (working tree or bare) and use it for both the --track normalization and the --branch guard. --- cmd/skillshare/install.go | 2 +- internal/install/install_git.go | 11 +++++++++++ internal/install/install_tracked.go | 2 +- internal/install/install_tracked_test.go | 12 ++++++++++++ .../install_track_root_skill_test.go | 18 ++++++++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cmd/skillshare/install.go b/cmd/skillshare/install.go index 8b8cf866f..ad165c707 100644 --- a/cmd/skillshare/install.go +++ b/cmd/skillshare/install.go @@ -202,7 +202,7 @@ func parseInstallArgs(args []string) (*installArgs, bool, error) { if result.opts.Branch != "" && result.sourceArg != "" { source, parseErr := install.ParseSource(result.sourceArg) trackableLocal := result.opts.Track && source != nil && - source.Type == install.SourceTypeLocalPath && install.IsGitRepo(source.Path) + source.Type == install.SourceTypeLocalPath && install.IsLocalGitRepo(source.Path) if parseErr == nil && !source.IsGit() && !trackableLocal { return nil, false, fmt.Errorf("--branch can only be used with git repository sources") } diff --git a/internal/install/install_git.go b/internal/install/install_git.go index 333fde9ee..1bf7dd6c5 100644 --- a/internal/install/install_git.go +++ b/internal/install/install_git.go @@ -35,6 +35,17 @@ func IsGitRepo(path string) bool { return err == nil && (info.IsDir() || info.Mode().IsRegular()) } +// IsLocalGitRepo reports whether path is the root of a git repository, either a +// working tree (.git) or a bare repository (HEAD and objects at the root). +func IsLocalGitRepo(path string) bool { + if IsGitRepo(path) { + return true + } + head, headErr := os.Stat(filepath.Join(path, "HEAD")) + objects, objErr := os.Stat(filepath.Join(path, "objects")) + return headErr == nil && head.Mode().IsRegular() && objErr == nil && objects.IsDir() +} + // IsTrackedCheckout reports whether path is a tracked repo checkout: a // _-prefixed directory that is a git repo. func IsTrackedCheckout(path string) bool { diff --git a/internal/install/install_tracked.go b/internal/install/install_tracked.go index 96ab34c2d..f1ed7c1a5 100644 --- a/internal/install/install_tracked.go +++ b/internal/install/install_tracked.go @@ -24,7 +24,7 @@ func localFileURL(path string) string { // normalizeTrackSource turns a local path that is a git repository into the // file:// form that parseFileURL builds, and rejects other non-git sources. func normalizeTrackSource(source *Source) error { - if source.Type == SourceTypeLocalPath && IsGitRepo(source.Path) { + if source.Type == SourceTypeLocalPath && IsLocalGitRepo(source.Path) { source.Type = SourceTypeGitHTTPS source.CloneURL = localFileURL(source.Path) return validateCloneURL(source.CloneURL) diff --git a/internal/install/install_tracked_test.go b/internal/install/install_tracked_test.go index 6b2a1b270..395eaa70c 100644 --- a/internal/install/install_tracked_test.go +++ b/internal/install/install_tracked_test.go @@ -298,3 +298,15 @@ func TestParseSource_ExplicitUNCFileURLKeepsAuthority(t *testing.T) { t.Errorf("CloneURL = %q, want file://server/share/repo", source.CloneURL) } } + +func TestInferTrackedKind_LocalBareRepoPath(t *testing.T) { + bare := strings.TrimPrefix(makeRemote(t, ""), "file://") + + source, err := ParseSource(bare) + if err != nil { + t.Fatal(err) + } + if _, err := InferTrackedKind(source, "skill"); err != nil { + t.Fatalf("local bare repo should be trackable: %v", err) + } +} diff --git a/tests/integration/install_track_root_skill_test.go b/tests/integration/install_track_root_skill_test.go index 8bebcd4ae..99c9605d4 100644 --- a/tests/integration/install_track_root_skill_test.go +++ b/tests/integration/install_track_root_skill_test.go @@ -6,6 +6,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" "testing" "skillshare/internal/install" @@ -370,3 +371,20 @@ func TestInstall_Track_LocalGitPath(t *testing.T) { t.Fatalf("tracked repo should be cloned to _local-repo") } } + +// TestInstall_Track_LocalBareRepoPath verifies --track also takes a local bare +// repository path, as file:// does. +func TestInstall_Track_LocalBareRepoPath(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + setupGlobalConfig(sb) + + bare := strings.TrimPrefix(setupBareRepoWithRootSkill(t, sb, "bare-local"), "file://") + + result := sb.RunCLI("install", bare, "--track", "--name", "bare-local", "--skip-audit") + result.AssertSuccess(t) + + if !sb.FileExists(filepath.Join(sb.SourcePath, "_bare-local", "SKILL.md")) { + t.Fatalf("tracked repo should be cloned to _bare-local") + } +}