Skip to content
Merged
3 changes: 2 additions & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Clone and verify:
git clone https://github.com/git-fire/git-testkit.git

# or SSH
# git clone git@github.com:git-fire/git-testkit.git
git clone git@github.com:git-fire/git-testkit.git

cd git-testkit
go test ./...
Expand All @@ -34,6 +34,7 @@ go test ./...
- `scenarios.go`: fluent scenario builder and predefined multi-repo scenarios.
- `snapshots.go`: snapshot/restore utilities for expensive test setup reuse.
- `fixtures_test.go`: external package tests (`testutil_test`) that validate public API usage.
- `usb_fixtures.go` / `usb_fixtures_test.go`: USB volume root and `.git-fire` config helpers for backup-mode style tests.
- `scenarios_test.go`: package-internal tests for scenario/snapshot behavior.

## Design principles
Expand Down
9 changes: 7 additions & 2 deletions fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,13 @@ func GetRemotes(t *testing.T, repoPath string) map[string]string {
remainder = strings.TrimSpace(remainder)
}

remainder = strings.TrimSuffix(remainder, " (fetch)")
remainder = strings.TrimSuffix(remainder, " (push)")
// Strip only the trailing git remote role suffix once so paths that end
// with text like " (push)" are not damaged by sequential TrimSuffix calls.
if strings.HasSuffix(remainder, " (fetch)") {
remainder = strings.TrimSuffix(remainder, " (fetch)")
} else if strings.HasSuffix(remainder, " (push)") {
remainder = strings.TrimSuffix(remainder, " (push)")
}

if name != "" && remainder != "" {
remotes[name] = remainder
Expand Down
25 changes: 25 additions & 0 deletions fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,31 @@ func TestCreateTestRepo_WithRemotePathContainingSpaces(t *testing.T) {
}
}

func TestCreateTestRepo_WithRemotePathContainingPushSuffix(t *testing.T) {
tmpDir := t.TempDir()
remotePath := filepath.Join(tmpDir, "origin (push)")
if err := os.MkdirAll(remotePath, 0755); err != nil {
t.Fatalf("Failed to create bare repo directory: %v", err)
}
testutil.RunGitCmd(t, tmpDir, "init", "--bare", remotePath)

repoPath := testutil.CreateTestRepo(t, testutil.RepoOptions{
Name: "remote-push-suffix-repo",
Remotes: map[string]string{
"origin": remotePath,
},
})

remotes := testutil.GetRemotes(t, repoPath)
originURL, exists := remotes["origin"]
if !exists {
t.Fatal("Expected 'origin' remote to be configured")
}
if originURL != remotePath {
t.Fatalf("Expected origin URL %q, got %q", remotePath, originURL)
}
}

func TestCreateBareRemote(t *testing.T) {
remotePath := testutil.CreateBareRemote(t, "test-remote")

Expand Down
14 changes: 12 additions & 2 deletions usb_fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,24 @@ func ReadUSBVolumeConfig(t *testing.T, root string) USBVolumeConfig {
func AssertGitDirAt(t *testing.T, path string, wantBare bool) {
t.Helper()
if wantBare {
if _, err := os.Stat(filepath.Join(path, "HEAD")); err != nil {
headPath := filepath.Join(path, "HEAD")
info, err := os.Stat(headPath)
if err != nil {
t.Fatalf("expected bare repo at %s: %v", path, err)
}
if info.IsDir() {
t.Fatalf("expected bare repo HEAD file at %s", path)
}
return
}
if _, err := os.Stat(filepath.Join(path, ".git")); err != nil {
gitPath := filepath.Join(path, ".git")
info, err := os.Stat(gitPath)
if err != nil {
t.Fatalf("expected non-bare repo at %s: %v", path, err)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
if !info.IsDir() {
t.Fatalf("expected non-bare repo .git directory at %s", path)
}
}
Comment thread
cursor[bot] marked this conversation as resolved.

func FileURLForPath(t *testing.T, path string) string {
Expand Down
Loading