mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
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.
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user