9
9
"fmt"
10
10
"io"
11
11
"net/http"
12
- "path"
13
12
"strings"
14
13
"time"
15
14
@@ -26,8 +25,6 @@ import (
26
25
"code.gitea.io/gitea/modules/setting"
27
26
"code.gitea.io/gitea/modules/timeutil"
28
27
"code.gitea.io/gitea/modules/util"
29
-
30
- "gopkg.in/ini.v1" //nolint:depguard
31
28
)
32
29
33
30
/*
@@ -240,14 +237,14 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
240
237
241
238
// cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
242
239
// This also removes possible user credentials.
243
- func cleanUpMigrateGitConfig (configPath string ) error {
244
- cfg , err := ini . Load ( configPath ) // FIXME: the ini package doesn't really work with git config files
245
- if err != nil {
246
- return fmt . Errorf ( "open config file: %w" , err )
247
- }
248
- cfg . DeleteSection ( "remote \" origin \" " )
249
- if err = cfg . SaveToIndent ( configPath , "\t " ); err != nil {
250
- return fmt . Errorf ( "save config file: %w" , err )
240
+ func cleanUpMigrateGitConfig (ctx context. Context , repoPath string ) error {
241
+ cmd := git . NewCommand ( ctx , "remote" , "rm" , "origin" )
242
+ // if the origin does not exist
243
+ _ , stderr , err := cmd . RunStdString ( & git. RunOpts {
244
+ Dir : repoPath ,
245
+ } )
246
+ if err != nil && ! strings . HasPrefix ( stderr , "fatal: No such remote" ) {
247
+ return err
251
248
}
252
249
return nil
253
250
}
@@ -270,7 +267,7 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
270
267
}
271
268
272
269
if repo .HasWiki () {
273
- if err := cleanUpMigrateGitConfig (path . Join ( repo .WikiPath (), "config" )); err != nil {
270
+ if err := cleanUpMigrateGitConfig (ctx , repo .WikiPath ()); err != nil {
274
271
return repo , fmt .Errorf ("cleanUpMigrateGitConfig (wiki): %w" , err )
275
272
}
276
273
}
0 commit comments