Skip to content

Commit 3d1fda7

Browse files
authored
Use git command instead of the ini package to remove the origin remote (#25066)
1 parent d851bd9 commit 3d1fda7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

modules/repository/repo.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"io"
1111
"net/http"
12-
"path"
1312
"strings"
1413
"time"
1514

@@ -26,8 +25,6 @@ import (
2625
"code.gitea.io/gitea/modules/setting"
2726
"code.gitea.io/gitea/modules/timeutil"
2827
"code.gitea.io/gitea/modules/util"
29-
30-
"gopkg.in/ini.v1" //nolint:depguard
3128
)
3229

3330
/*
@@ -240,14 +237,14 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
240237

241238
// cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
242239
// 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
251248
}
252249
return nil
253250
}
@@ -270,7 +267,7 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
270267
}
271268

272269
if repo.HasWiki() {
273-
if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
270+
if err := cleanUpMigrateGitConfig(ctx, repo.WikiPath()); err != nil {
274271
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
275272
}
276273
}

0 commit comments

Comments
 (0)