Files
gotea/modules/git/init_got_test.go
T
lotherk 4be6c78264 feat(got): initialize bare repositories with got
Add modules/got with a got runner, version check, repository detection, and idempotent bare init. Route bare repository creation from InitRepositoryLocal through got; non-bare temp worktrees keep git. Add [git] GOT_PATH and tests, including an explicit no-fallback test.

Assisted-by: OpenCode:DeepSeek-V4.1-Flash
2026-11-22 14:05:07 +00:00

47 lines
1.2 KiB
Go

// Copyright 2026 The Gotea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package git
import (
"os"
"path/filepath"
"strings"
"testing"
"gotea.dev/modules/got"
"gotea.dev/modules/setting"
)
func TestInitRepositoryLocalBareUsesGot(t *testing.T) {
if _, err := got.Version(t.Context()); err != nil {
t.Skipf("got not available: %v", err)
}
dir := filepath.Join(t.TempDir(), "repo.git")
if err := InitRepositoryLocal(t.Context(), dir, true, "sha1"); err != nil {
t.Fatal(err)
}
if !got.IsRepository(dir) {
t.Fatalf("%s was not initialized by got", dir)
}
head, err := os.ReadFile(filepath.Join(dir, "HEAD"))
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(string(head), "ref: refs/heads/") {
t.Fatalf("unexpected HEAD %q", head)
}
}
func TestInitRepositoryLocalBareDoesNotFallBackToGit(t *testing.T) {
old := setting.Git.GotPath
setting.Git.GotPath = "gotea-test-got-missing"
t.Cleanup(func() { setting.Git.GotPath = old })
dir := filepath.Join(t.TempDir(), "repo.git")
if err := InitRepositoryLocal(t.Context(), dir, true, "sha1"); err == nil {
t.Fatal("expected a got failure instead of a silent git fallback")
}
}