@@ -6,6 +6,7 @@ package gogit
66
77import (
88 "context"
9+ "errors"
910 "fmt"
1011 "strings"
1112
@@ -51,6 +52,10 @@ func CreateOrganizationRepository(ctx context.Context, gc gitprovider.Client, do
5152 }
5253
5354 if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
55+ if cerr := repo .Delete (ctx ); cerr != nil {
56+ err = errors .Join (err , cerr )
57+ }
58+
5459 return fmt .Errorf ("failed to add CODEOWNERS file: %w" , err )
5560 }
5661
@@ -65,6 +70,10 @@ func CreateOrganizationRepository(ctx context.Context, gc gitprovider.Client, do
6570 logger .Info ("using existing repository" , "domain" , domain , "repository" , spec .RepositoryName )
6671 } else {
6772 if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
73+ if cerr := repo .Delete (ctx ); cerr != nil {
74+ err = errors .Join (err , cerr )
75+ }
76+
6877 return fmt .Errorf ("failed to add CODEOWNERS file: %w" , err )
6978 }
7079
@@ -112,6 +121,10 @@ func CreateUserRepository(ctx context.Context, gc gitprovider.Client, domain str
112121 }
113122
114123 if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
124+ if cerr := repo .Delete (ctx ); cerr != nil {
125+ err = errors .Join (err , cerr )
126+ }
127+
115128 return fmt .Errorf ("failed to add CODEOWNERS file: %w" , err )
116129 }
117130
@@ -126,6 +139,10 @@ func CreateUserRepository(ctx context.Context, gc gitprovider.Client, domain str
126139 logger .Info ("using existing repository" , "domain" , domain , "repository" , spec .RepositoryName )
127140 } else {
128141 if err := createCodeownersFile (ctx , repo , spec .Maintainers ); err != nil {
142+ if cerr := repo .Delete (ctx ); cerr != nil {
143+ err = errors .Join (err , cerr )
144+ }
145+
129146 return fmt .Errorf ("failed to add CODEOWNERS file: %w" , err )
130147 }
131148
0 commit comments