diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 1b885b0..e1ff7ca 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -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 ./... @@ -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 diff --git a/fixtures.go b/fixtures.go index a06526b..7251431 100644 --- a/fixtures.go +++ b/fixtures.go @@ -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 diff --git a/fixtures_test.go b/fixtures_test.go index 77f5af1..7157e58 100644 --- a/fixtures_test.go +++ b/fixtures_test.go @@ -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") diff --git a/usb_fixtures.go b/usb_fixtures.go index f453a83..36183b0 100644 --- a/usb_fixtures.go +++ b/usb_fixtures.go @@ -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) } + if !info.IsDir() { + t.Fatalf("expected non-bare repo .git directory at %s", path) + } } func FileURLForPath(t *testing.T, path string) string {