diff --git a/go.mod b/go.mod index 64b387b8134..86ece166842 100644 --- a/go.mod +++ b/go.mod @@ -106,7 +106,7 @@ require ( github.com/grafana/grafana-openapi-client-go v0.0.0-20231213163343-bd475d63fb79 // @grafana/grafana-backend-group github.com/grafana/grafana-plugin-sdk-go v0.278.0 // @grafana/plugins-platform-backend github.com/grafana/loki/v3 v3.2.1 // @grafana/observability-logs - github.com/grafana/nanogit v0.0.0-20250625082556-a4828b879bbb // @grafana-app-platform-squad + github.com/grafana/nanogit v0.0.0-20250709085038-55508a6a9f40 // @grafana-app-platform-squad github.com/grafana/otel-profiling-go v0.5.1 // @grafana/grafana-backend-group github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // @grafana/observability-traces-and-profiling github.com/grafana/pyroscope/api v1.2.1-0.20250415190842-3ff7247547ae // @grafana/observability-traces-and-profiling diff --git a/go.sum b/go.sum index c208845b1c1..53054254a04 100644 --- a/go.sum +++ b/go.sum @@ -1654,8 +1654,8 @@ github.com/grafana/loki/pkg/push v0.0.0-20231124142027-e52380921608 h1:ZYk42718k github.com/grafana/loki/pkg/push v0.0.0-20231124142027-e52380921608/go.mod h1:f3JSoxBTPXX5ec4FxxeC19nTBSxoTz+cBgS3cYLMcr0= github.com/grafana/loki/v3 v3.2.1 h1:VB7u+KHfvL5aHAxgoVBvz5wVhsdGuqKC7uuOFOOe7jw= github.com/grafana/loki/v3 v3.2.1/go.mod h1:WvdLl6wOS+yahaeQY+xhD2m2XzkHDfKr5FZaX7D/X2Y= -github.com/grafana/nanogit v0.0.0-20250625082556-a4828b879bbb h1:JR672zBiCkfiKuRRsU76TRC2q12q0VfZl2SP8jBIAJQ= -github.com/grafana/nanogit v0.0.0-20250625082556-a4828b879bbb/go.mod h1:tN93IZUaAmnSWgL0IgnKdLv6DNeIhTJGvl1wvQMrWco= +github.com/grafana/nanogit v0.0.0-20250709085038-55508a6a9f40 h1:wsIgOI4Ou1o/UtxtJlemLufpVBpMdcXVJxedk0wLoCM= +github.com/grafana/nanogit v0.0.0-20250709085038-55508a6a9f40/go.mod h1:ToqLjIdvV3AZQa3K6e5m9hy/nsGaUByc2dWQlctB9iA= github.com/grafana/otel-profiling-go v0.5.1 h1:stVPKAFZSa7eGiqbYuG25VcqYksR6iWvF3YH66t4qL8= github.com/grafana/otel-profiling-go v0.5.1/go.mod h1:ftN/t5A/4gQI19/8MoWurBEtC6gFw8Dns1sJZ9W4Tls= github.com/grafana/prometheus-alertmanager v0.25.1-0.20250620093340-be61a673dee6 h1:oJnbhG6ZNy10AjsgNeAtAKeGHogIGOMfAsBH6fYYa5M= diff --git a/pkg/registry/apis/provisioning/repository/nanogit/git.go b/pkg/registry/apis/provisioning/repository/nanogit/git.go index ce1773e787a..c533d1fb85a 100644 --- a/pkg/registry/apis/provisioning/repository/nanogit/git.go +++ b/pkg/registry/apis/provisioning/repository/nanogit/git.go @@ -595,7 +595,7 @@ func (r *gitRepository) resolveRefToHash(ctx context.Context, ref string) (hash. // Try to parse ref as a hash first refHash, err := hash.FromHex(ref) - if err == nil && refHash != nil { + if err == nil && refHash != hash.Zero { // Valid hash, return it return refHash, nil } @@ -604,9 +604,9 @@ func (r *gitRepository) resolveRefToHash(ctx context.Context, ref string) (hash. branchRef, err := r.client.GetRef(ctx, ref) if err != nil { if errors.Is(err, nanogit.ErrObjectNotFound) { - return nil, fmt.Errorf("ref not found: %s: %w", ref, repository.ErrRefNotFound) + return hash.Zero, fmt.Errorf("ref not found: %s: %w", ref, repository.ErrRefNotFound) } - return nil, fmt.Errorf("get ref %s: %w", ref, err) + return hash.Zero, fmt.Errorf("get ref %s: %w", ref, err) } return branchRef.Hash, nil diff --git a/pkg/registry/apis/provisioning/repository/nanogit/git_test.go b/pkg/registry/apis/provisioning/repository/nanogit/git_test.go index 20df321fc74..d9413c429f0 100644 --- a/pkg/registry/apis/provisioning/repository/nanogit/git_test.go +++ b/pkg/registry/apis/provisioning/repository/nanogit/git_test.go @@ -695,7 +695,7 @@ func TestGitRepository_Read(t *testing.T) { Hash: hash.Hash{}, }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash([]byte("tree-hash")), + Tree: hash.MustFromHex("abcdef1234567890abcdef1234567890abcdef12"), }, nil) mockClient.GetTreeByPathReturns(&nanogit.Tree{ Hash: hash.Hash{}, @@ -1191,7 +1191,7 @@ func TestGitRepository_LatestRef(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, // Non-empty hash + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, // Non-empty hash }, nil) }, gitConfig: RepositoryConfig{ @@ -1412,11 +1412,11 @@ func TestGitRepository_CompareFiles(t *testing.T) { // Return refs for base and ref mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) // Return comparison results @@ -1449,11 +1449,11 @@ func TestGitRepository_CompareFiles(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{}, nil) @@ -1547,7 +1547,7 @@ func TestGitRepository_ensureBranchExists(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) }, gitConfig: RepositoryConfig{ @@ -1565,7 +1565,7 @@ func TestGitRepository_ensureBranchExists(t *testing.T) { // Second call - get source branch mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) // CreateRef succeeds mockClient.CreateRefReturns(nil) @@ -1862,7 +1862,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) }, gitConfig: RepositoryConfig{ @@ -1887,7 +1887,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) }, gitConfig: RepositoryConfig{ @@ -1939,7 +1939,7 @@ func TestGitRepository_resolveRefToHash(t *testing.T) { if tt.wantError { require.Error(t, err) - require.Nil(t, refHash) + require.Equal(t, hash.Zero, refHash) } else { require.NoError(t, err) require.NotNil(t, refHash) @@ -2212,7 +2212,7 @@ func TestGitRepository_EdgeCases(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockWriter := &mocks.FakeStagedWriter{} @@ -2251,7 +2251,7 @@ func TestGitRepository_EdgeCases(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetCommitReturns(&nanogit.Commit{Tree: hash.Hash{}}, nil) mockClient.GetBlobByPathReturns(&nanogit.Blob{}, errors.New("some read error")) @@ -2401,7 +2401,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/invalid-hex", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) }, ref: "invalid-hex-zzz", @@ -2412,7 +2412,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) }, ref: "refs/heads/feature", @@ -2423,7 +2423,7 @@ func TestGitRepository_ResolveRefToHash_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/tags/v1.0.0", - Hash: hash.Hash{7, 8, 9}, + Hash: hash.Hash{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}, }, nil) }, ref: "refs/tags/v1.0.0", @@ -2540,11 +2540,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) mockClient.CompareCommitsReturns(nil, errors.New("compare error")) }, @@ -2558,11 +2558,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{ { @@ -2580,11 +2580,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{ { @@ -2606,11 +2606,11 @@ func TestGitRepository_CompareFiles_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{ { @@ -2683,7 +2683,7 @@ func TestGitRepository_ReadTree_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetFlatTreeReturns(nil, errors.New("flat tree error")) }, @@ -2694,23 +2694,23 @@ func TestGitRepository_ReadTree_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.GetFlatTreeReturns(&nanogit.FlatTree{ Entries: []nanogit.FlatTreeEntry{ { Path: "other/file.yaml", // Outside configs/ - Hash: hash.Hash{4, 5, 6}, + Hash: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, Type: protocol.ObjectTypeBlob, }, { Path: "configs/included.yaml", // Inside configs/ - Hash: hash.Hash{7, 8, 9}, + Hash: hash.Hash{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}, Type: protocol.ObjectTypeBlob, }, { Path: "configs/dir", // Directory without trailing slash - Hash: hash.Hash{10, 11, 12}, + Hash: hash.Hash{10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29}, Type: protocol.ObjectTypeTree, }, }, @@ -2828,7 +2828,7 @@ func TestGitRepository_ensureBranchExists_ErrorConditions(t *testing.T) { // Second call - get source branch mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) // CreateRef fails mockClient.CreateRefReturns(errors.New("create ref failed")) @@ -2880,10 +2880,10 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121315"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash([]byte("tree-hash")), + Tree: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetTreeByPathReturns(nil, errors.New("tree error")) }, @@ -2895,7 +2895,7 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(nil, errors.New("commit error")) }, @@ -2907,10 +2907,10 @@ func TestGitRepository_Read_EdgeCases(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708092a0b0c0d0e0f1011121314"), }, nil) mockClient.GetBlobByPathReturns(nil, errors.New("blob error")) }, @@ -2965,7 +2965,7 @@ func TestGitRepository_Create_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error")) }, @@ -2977,7 +2977,7 @@ func TestGitRepository_Create_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.CreateBlobReturns(hash.Hash{}, errors.New("create blob error")) @@ -3030,7 +3030,7 @@ func TestGitRepository_Update_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.Hash{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, }, nil) mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error")) }, @@ -3042,7 +3042,7 @@ func TestGitRepository_Update_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.UpdateBlobReturns(hash.Hash{}, errors.New("update blob error")) @@ -3096,7 +3096,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.NewStagedWriterReturns(nil, errors.New("staged writer error")) }, @@ -3109,7 +3109,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.DeleteBlobReturns(hash.Hash{}, errors.New("delete blob error")) @@ -3124,7 +3124,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.DeleteTreeReturns(hash.Hash{}, errors.New("delete tree error")) @@ -3139,7 +3139,7 @@ func TestGitRepository_Delete_ErrorConditions(t *testing.T) { setupMock: func(mockClient *mocks.FakeClient) { mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.DeleteTreeReturns(hash.Hash{}, nanogit.ErrObjectNotFound) @@ -3186,7 +3186,7 @@ func TestGitRepository_CompareFiles_EmptyBase(t *testing.T) { // Only setup for ref resolution mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{ { @@ -3218,8 +3218,8 @@ func TestGitRepository_CompareFiles_EmptyBase(t *testing.T) { // Verify CompareCommits was called with empty base hash and feature hash require.Equal(t, 1, mockClient.CompareCommitsCallCount()) _, baseHash, refHash := mockClient.CompareCommitsArgsForCall(0) - require.Nil(t, baseHash) // Empty hash for empty base - require.Equal(t, hash.Hash{4, 5, 6}, refHash) + require.Equal(t, hash.Zero, baseHash) // Empty hash for empty base + require.Equal(t, hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), refHash) } func TestGitRepository_EmptyRefHandling(t *testing.T) { @@ -3237,7 +3237,7 @@ func TestGitRepository_EmptyRefHandling(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} @@ -3299,7 +3299,7 @@ func TestGitRepository_CompareFiles_ResolveErrors(t *testing.T) { // First call succeeds for base mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) // Second call fails for ref mockClient.GetRefReturnsOnCall(1, nanogit.Ref{}, errors.New("ref error")) @@ -3341,14 +3341,14 @@ func TestGitRepository_Read_EmptyRef(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash{4, 5, 6}, + Tree: hash.Hash{4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, }, nil) mockClient.GetBlobByPathReturns(&nanogit.Blob{ Content: []byte("file content"), - Hash: hash.Hash{7, 8, 9}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) gitRepo := &gitRepository{ @@ -3376,13 +3376,13 @@ func TestGitRepository_ReadTree_EmptyRef(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetFlatTreeReturns(&nanogit.FlatTree{ Entries: []nanogit.FlatTreeEntry{ { Path: "configs/test.yaml", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), Type: protocol.ObjectTypeBlob, }, }, @@ -3504,17 +3504,17 @@ func TestGitRepository_Write_DefaultRef(t *testing.T) { // First call for Read check - file not found mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetBlobByPathReturns(&nanogit.Blob{}, nanogit.ErrObjectNotFound) // Second call for Create mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockWriter := &mocks.FakeStagedWriter{} mockWriter.CreateBlobReturns(hash.Hash{}, nil) @@ -3545,14 +3545,14 @@ func TestGitRepository_Read_RefInFileInfo(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetBlobByPathReturns(&nanogit.Blob{ Content: []byte("file content"), - Hash: hash.Hash{7, 8, 9}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) gitRepo := &gitRepository{ @@ -3582,10 +3582,10 @@ func TestGitRepository_Read_GetTreeByPath_NotFound(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetCommitReturns(&nanogit.Commit{ - Tree: hash.Hash([]byte("tree-hash")), + Tree: hash.Hash{30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49}, }, nil) mockClient.GetTreeByPathReturns(nil, nanogit.ErrObjectNotFound) @@ -3614,7 +3614,7 @@ func TestGitRepository_ReadTree_GetFlatTree_NotFound(t *testing.T) { mockClient := &mocks.FakeClient{} mockClient.GetRefReturns(nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetFlatTreeReturns(nil, nanogit.ErrObjectNotFound) @@ -3655,11 +3655,11 @@ func TestGitRepository_CompareFiles_FilesOutsideConfiguredPath_AllStatuses(t *te mockClient := &mocks.FakeClient{} mockClient.GetRefReturnsOnCall(0, nanogit.Ref{ Name: "refs/heads/main", - Hash: hash.Hash{1, 2, 3}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121314"), }, nil) mockClient.GetRefReturnsOnCall(1, nanogit.Ref{ Name: "refs/heads/feature", - Hash: hash.Hash{4, 5, 6}, + Hash: hash.MustFromHex("0102030405060708090a0b0c0d0e0f1011121315"), }, nil) mockClient.CompareCommitsReturns([]nanogit.CommitFile{ {