mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
On Windows, filepath.Join produces backslash separators that were written directly into .gitignore and JSON metadata files. Git does not match backslash patterns, and metadata subdirs with backslashes corrupt source URLs during updates. Use strings.ReplaceAll(s, "\\", "/") at write boundaries — matching the existing pattern in sync.go — to ensure config/metadata files always contain forward slashes regardless of OS.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package install
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestUpdateGitIgnore_NormalizesBackslashes(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// Simulate Windows: filepath.Join("skills", "my-skill") → "skills\my-skill"
|
|
entry := "skills\\my-skill"
|
|
if err := UpdateGitIgnore(dir, entry); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
content, err := os.ReadFile(filepath.Join(dir, ".gitignore"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got := string(content)
|
|
if strings.Contains(got, `\`) {
|
|
t.Errorf("gitignore contains backslash:\n%s", got)
|
|
}
|
|
if !strings.Contains(got, "skills/my-skill/") {
|
|
t.Errorf("gitignore should contain skills/my-skill/, got:\n%s", got)
|
|
}
|
|
}
|
|
|
|
func TestRemoveFromGitIgnore_NormalizesBackslashes(t *testing.T) {
|
|
dir := t.TempDir()
|
|
|
|
// First add with forward slashes
|
|
if err := UpdateGitIgnore(dir, "skills/my-skill"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Remove with backslashes (simulating Windows)
|
|
removed, err := RemoveFromGitIgnore(dir, "skills\\my-skill")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !removed {
|
|
t.Error("expected entry to be removed")
|
|
}
|
|
|
|
content, err := os.ReadFile(filepath.Join(dir, ".gitignore"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(content), "skills/my-skill") {
|
|
t.Errorf("entry should have been removed, got:\n%s", string(content))
|
|
}
|
|
}
|