forked from gitea/gitea
Use git command instead of the ini package to remove the `origin` remote (#25066)
This commit is contained in:
parent
d851bd9a6b
commit
3d1fda737b
|
@ -9,7 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -26,8 +25,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/timeutil"
|
"code.gitea.io/gitea/modules/timeutil"
|
||||||
"code.gitea.io/gitea/modules/util"
|
"code.gitea.io/gitea/modules/util"
|
||||||
|
|
||||||
"gopkg.in/ini.v1" //nolint:depguard
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -240,14 +237,14 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
|
||||||
|
|
||||||
// cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
|
// cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
|
||||||
// This also removes possible user credentials.
|
// This also removes possible user credentials.
|
||||||
func cleanUpMigrateGitConfig(configPath string) error {
|
func cleanUpMigrateGitConfig(ctx context.Context, repoPath string) error {
|
||||||
cfg, err := ini.Load(configPath) // FIXME: the ini package doesn't really work with git config files
|
cmd := git.NewCommand(ctx, "remote", "rm", "origin")
|
||||||
if err != nil {
|
// if the origin does not exist
|
||||||
return fmt.Errorf("open config file: %w", err)
|
_, stderr, err := cmd.RunStdString(&git.RunOpts{
|
||||||
}
|
Dir: repoPath,
|
||||||
cfg.DeleteSection("remote \"origin\"")
|
})
|
||||||
if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
|
if err != nil && !strings.HasPrefix(stderr, "fatal: No such remote") {
|
||||||
return fmt.Errorf("save config file: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -270,7 +267,7 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.HasWiki() {
|
if repo.HasWiki() {
|
||||||
if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
|
if err := cleanUpMigrateGitConfig(ctx, repo.WikiPath()); err != nil {
|
||||||
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
|
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue