mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
- Add GetRemoteRefHash/WithAuth/WithEnv to internal/git/info.go: uses git ls-remote with refs/heads/<branch> when branch is set, falls back to HEAD when branch is empty - Add Branch field to URLCheckInput and URLCheckOutput in check/parallel.go; ParallelCheckURLs dispatches to GetRemoteRefHashWithAuth when Branch is set - check.go: group skills by RepoURL@branch composite key so skills on different branches of the same repo are checked against the correct ref; urlHashMap keyed by same composite key for correct broadcast - install_config.go (InstallFromConfig): propagate SkillEntryDTO.Branch into Source.Branch for both plain and tracked skill phases so registry rebuild (install --from-config) respects the recorded branch
74 lines
2.0 KiB
Go
74 lines
2.0 KiB
Go
package git
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetRemoteRefHash(t *testing.T) {
|
|
// Create bare repo
|
|
bareRepo := filepath.Join(t.TempDir(), "test.git")
|
|
run(t, "", "git", "init", "--bare", bareRepo)
|
|
|
|
// Clone and set up
|
|
workDir := filepath.Join(t.TempDir(), "work")
|
|
run(t, "", "git", "clone", bareRepo, workDir)
|
|
run(t, workDir, "git", "config", "user.email", "test@test.com")
|
|
run(t, workDir, "git", "config", "user.name", "Test")
|
|
|
|
// Commit on main
|
|
os.WriteFile(filepath.Join(workDir, "main.txt"), []byte("main"), 0644)
|
|
run(t, workDir, "git", "add", ".")
|
|
run(t, workDir, "git", "commit", "-m", "main commit")
|
|
run(t, workDir, "git", "push", "origin", "HEAD")
|
|
|
|
// Create dev branch with different commit
|
|
run(t, workDir, "git", "checkout", "-b", "dev")
|
|
os.WriteFile(filepath.Join(workDir, "dev.txt"), []byte("dev"), 0644)
|
|
run(t, workDir, "git", "add", ".")
|
|
run(t, workDir, "git", "commit", "-m", "dev commit")
|
|
run(t, workDir, "git", "push", "origin", "dev")
|
|
|
|
t.Run("empty branch returns HEAD hash", func(t *testing.T) {
|
|
hash, err := GetRemoteRefHash(bareRepo, "")
|
|
if err != nil {
|
|
t.Fatalf("GetRemoteRefHash: %v", err)
|
|
}
|
|
if hash == "" {
|
|
t.Error("expected non-empty hash")
|
|
}
|
|
})
|
|
|
|
t.Run("specific branch returns that branch hash", func(t *testing.T) {
|
|
headHash, _ := GetRemoteRefHash(bareRepo, "")
|
|
devHash, err := GetRemoteRefHash(bareRepo, "dev")
|
|
if err != nil {
|
|
t.Fatalf("GetRemoteRefHash dev: %v", err)
|
|
}
|
|
if devHash == headHash {
|
|
t.Error("dev hash should differ from HEAD (main)")
|
|
}
|
|
})
|
|
|
|
t.Run("nonexistent branch returns error", func(t *testing.T) {
|
|
_, err := GetRemoteRefHash(bareRepo, "nonexistent")
|
|
if err == nil {
|
|
t.Error("expected error for nonexistent branch")
|
|
}
|
|
})
|
|
}
|
|
|
|
// run executes a command and fails the test on error.
|
|
func run(t *testing.T, dir string, name string, args ...string) {
|
|
t.Helper()
|
|
cmd := exec.Command(name, args...)
|
|
if dir != "" {
|
|
cmd.Dir = dir
|
|
}
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
t.Fatalf("%s %v failed: %s %v", name, args, out, err)
|
|
}
|
|
}
|