Skip to content

Commit 51f0b57

Browse files
committed
chore: windows compat
1 parent f757c8b commit 51f0b57

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

integration/patches_git_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,9 @@ func TestGitArchitecture_ImplicitFetchFromRemote(t *testing.T) {
821821
originalID := extractGeneratedIDFromContent(content)
822822
require.NotEmpty(t, originalID, "pet.go should have @generated-id")
823823

824-
// Add a custom method at the end of the file (after the struct closing brace)
825-
// This is less likely to conflict with generator changes
826-
modifiedContent := strings.Replace(string(content),
827-
"}\n",
828-
"}\n\n// ENVB_USER_EDIT: Developer B's customization\nfunc (p *Pet) CustomMethod() string {\n\treturn \"custom\"\n}\n", 1)
824+
// Add a custom method at the end of the file
825+
// We append to the very end of the file to avoid conflict with generated getters
826+
modifiedContent := string(content) + "\n// ENVB_USER_EDIT: Developer B's customization\nfunc (p *Pet) CustomMethod() string {\n\treturn \"custom\"\n}\n"
829827
err = os.WriteFile(petFile, []byte(modifiedContent), 0644)
830828
require.NoError(t, err)
831829
gitCommitAllInDir(t, envBDir, "developer B user edit")
@@ -837,10 +835,12 @@ func TestGitArchitecture_ImplicitFetchFromRemote(t *testing.T) {
837835
gitCommitAllInDir(t, envBDir, "generation 2 in envB")
838836

839837
// Step 7: Verify user edit was preserved (proving 3-way merge worked)
840-
finalContent, err := os.ReadFile(sdkFile)
838+
finalContent, err := os.ReadFile(petFile)
841839
require.NoError(t, err)
842840
require.Contains(t, string(finalContent), "ENVB_USER_EDIT: Developer B's customization",
843841
"User modification should be preserved after generation (3-way merge worked)")
842+
require.Contains(t, string(finalContent), "func (p *Pet) CustomMethod()",
843+
"Custom method should be preserved after generation")
844844

845845
// Verify ID is preserved
846846
finalID := extractGeneratedIDFromContent(finalContent)

internal/git/plumbing.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,27 @@ func (r *Repository) writeBlobGoGit(content []byte) (string, error) {
6969
}
7070

7171
// GetBlob retrieves the content of a blob by its SHA-1 hash.
72+
// Uses native git commands to ensure we can read objects fetched by native git fetch.
7273
func (r *Repository) GetBlob(hash string) ([]byte, error) {
7374
// Strip "sha1:" prefix if present (common in some systems)
7475
hash = strings.TrimPrefix(hash, "sha1:")
7576

76-
h := plumbing.NewHash(hash)
77-
blob, err := r.repo.BlobObject(h)
78-
if err != nil {
79-
return nil, fmt.Errorf("failed to find blob %s: %w", hash, err)
77+
repoRoot := r.Root()
78+
if repoRoot == "" {
79+
return nil, fmt.Errorf("repository root not found")
8080
}
8181

82-
reader, err := blob.Reader()
82+
// Use native git to read blob content.
83+
// This is necessary because go-git's storer may not see objects
84+
// that were fetched via native git fetch commands.
85+
cmd := exec.Command("git", "cat-file", "blob", hash)
86+
cmd.Dir = repoRoot
87+
output, err := cmd.Output()
8388
if err != nil {
84-
return nil, fmt.Errorf("failed to open blob reader: %w", err)
85-
}
86-
defer reader.Close()
87-
88-
buf := new(bytes.Buffer)
89-
if _, err := buf.ReadFrom(reader); err != nil {
90-
return nil, fmt.Errorf("failed to read blob content: %w", err)
89+
return nil, fmt.Errorf("failed to read blob %s: %w", hash, err)
9190
}
9291

93-
return buf.Bytes(), nil
92+
return output, nil
9493
}
9594

9695
// TreeEntry represents a file or directory in a git tree.

internal/git/repository.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,26 @@ func (r *Repository) Root() string {
7474
}
7575

7676
// HasObject checks if a blob or commit exists in the local object database.
77+
// Uses native git commands to ensure we see objects fetched by native git fetch.
7778
func (r *Repository) HasObject(hash string) bool {
7879
if r.repo == nil {
7980
return false
8081
}
8182

8283
// Strip "sha1:" prefix if present
8384
hash = strings.TrimPrefix(hash, "sha1:")
84-
h := plumbing.NewHash(hash)
8585

86-
// Try to get the object - if it exists, return true
87-
_, err := r.repo.Storer.EncodedObject(plumbing.AnyObject, h)
88-
return err == nil
86+
// Use native git to check object existence.
87+
// This is necessary because go-git's storer may not see objects
88+
// that were fetched via native git fetch commands.
89+
repoRoot := r.Root()
90+
if repoRoot == "" {
91+
return false
92+
}
93+
94+
cmd := exec.Command("git", "cat-file", "-e", hash)
95+
cmd.Dir = repoRoot
96+
return cmd.Run() == nil
8997
}
9098

9199
// FetchRef fetches a specific ref from origin.

0 commit comments

Comments
 (0)