mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-29 07:19:26 +00:00
fix
This commit is contained in:
parent
183cde56e0
commit
70ef12612d
@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/globallock"
|
||||
)
|
||||
|
||||
func GetGitConfig(ctx context.Context, repo Repository, key string) (string, error) {
|
||||
func GitConfigGet(ctx context.Context, repo Repository, key string) (string, error) {
|
||||
result, _, err := git.NewCommand("config", "--get").
|
||||
AddDynamicArguments(key).
|
||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
||||
@ -26,13 +26,13 @@ func GetGitConfig(ctx context.Context, repo Repository, key string) (string, err
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getRepoConfigLockKey(repoStoragePath string) string {
|
||||
func repoGitConfigLockKey(repoStoragePath string) string {
|
||||
return "repo-config:" + repoStoragePath
|
||||
}
|
||||
|
||||
// AddGitConfig add a git configuration key to a specific value for the given repository.
|
||||
func AddGitConfig(ctx context.Context, repo Repository, key, value string) error {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
// GitConfigAdd add a git configuration key to a specific value for the given repository.
|
||||
func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -44,24 +44,24 @@ func AddGitConfig(ctx context.Context, repo Repository, key, value string) error
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateGitConfig updates a git configuration key to a specific value for the given repository.
|
||||
// GitConfigSet updates a git configuration key to a specific value for the given repository.
|
||||
// If the key does not exist, it will be created.
|
||||
// If the key exists, it will be updated to the new value.
|
||||
func UpdateGitConfig(ctx context.Context, repo Repository, key, value string) (string, error) {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
func GitConfigSet(ctx context.Context, repo Repository, key, value string) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
defer releaser()
|
||||
|
||||
value, _, err1 := git.NewCommand("config").
|
||||
_, _, err = git.NewCommand("config").
|
||||
AddDynamicArguments(key, value).
|
||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
||||
return value, err1
|
||||
return err
|
||||
}
|
||||
|
||||
func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...string) error {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...string) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -77,8 +77,8 @@ func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL st
|
||||
return err
|
||||
}
|
||||
|
||||
func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) error {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
func GitRemoteRemove(ctx context.Context, repo Repository, remoteName string) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -89,8 +89,8 @@ func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) er
|
||||
return err
|
||||
}
|
||||
|
||||
// GetRemoteURL returns the url of a specific remote of the repository.
|
||||
func GetRemoteURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
|
||||
// GitRemoteGetURL returns the url of a specific remote of the repository.
|
||||
func GitRemoteGetURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
|
||||
addr, err := git.GetRemoteAddress(ctx, repoPath(repo), remoteName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -98,9 +98,9 @@ func GetRemoteURL(ctx context.Context, repo Repository, remoteName string) (*git
|
||||
return giturl.ParseGitURL(addr)
|
||||
}
|
||||
|
||||
// PruneRemote prunes the remote branches that no longer exist in the remote repository.
|
||||
func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
// FIXME: config related? long-time running?
|
||||
func GitRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -115,8 +115,9 @@ func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeou
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||
// FIXME: config related? long-time running?
|
||||
func GitRemoteUpdatePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||
releaser, err := globallock.Lock(ctx, repoGitConfigLockKey(repo.RelativePath()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ func handleSettingsPostMirror(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := gitrepo.GetRemoteURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
|
||||
u, err := gitrepo.GitRemoteGetURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
|
||||
if err != nil {
|
||||
ctx.Data["Err_MirrorAddress"] = true
|
||||
handleSettingRemoteAddrError(ctx, err, form)
|
||||
|
@ -93,11 +93,11 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
|
||||
numRepos++
|
||||
|
||||
if autofix {
|
||||
_, err := gitrepo.UpdateGitConfig(ctx, repo, "receive.advertisePushOptions", "true")
|
||||
err := gitrepo.GitConfigSet(ctx, repo, "receive.advertisePushOptions", "true")
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := gitrepo.GetGitConfig(ctx, repo, "receive.advertisePushOptions")
|
||||
value, err := gitrepo.GitConfigGet(ctx, repo, "receive.advertisePushOptions")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ import (
|
||||
func getMergeBase(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pr *issues_model.PullRequest, baseBranch, headBranch string) (string, error) {
|
||||
// Add a temporary remote
|
||||
tmpRemote := fmt.Sprintf("mergebase-%d-%d", pr.ID, time.Now().UnixNano())
|
||||
if err := gitrepo.AddGitRemote(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
|
||||
return "", fmt.Errorf("AddGitRemote: %w", err)
|
||||
if err := gitrepo.GitRemoteAdd(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
|
||||
return "", fmt.Errorf("GitRemoteAdd: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := gitrepo.RemoveGitRemote(ctx, repo, tmpRemote); err != nil {
|
||||
log.Error("getMergeBase: RemoveGitRemote: %v", err)
|
||||
if err := gitrepo.GitRemoteRemove(ctx, repo, tmpRemote); err != nil {
|
||||
log.Error("getMergeBase: GitRemoteRemove: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -41,12 +41,12 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
|
||||
remoteName := m.GetRemoteName()
|
||||
repo := m.GetRepository(ctx)
|
||||
// Remove old remote
|
||||
err = gitrepo.RemoveGitRemote(ctx, repo, remoteName)
|
||||
err = gitrepo.GitRemoteRemove(ctx, repo, remoteName)
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = gitrepo.AddGitRemote(ctx, repo, remoteName, addr, "--mirror=fetch")
|
||||
err = gitrepo.GitRemoteAdd(ctx, repo, remoteName, addr, "--mirror=fetch")
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return err
|
||||
}
|
||||
@ -54,12 +54,12 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
|
||||
if m.Repo.HasWiki() {
|
||||
wikiRemotePath := repo_module.WikiRemoteURL(ctx, addr)
|
||||
// Remove old remote of wiki
|
||||
err = gitrepo.RemoveGitRemote(ctx, repo.WikiStorageRepo(), remoteName)
|
||||
err = gitrepo.GitRemoteRemove(ctx, repo.WikiStorageRepo(), remoteName)
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = gitrepo.AddGitRemote(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
|
||||
err = gitrepo.GitRemoteAdd(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return err
|
||||
}
|
||||
@ -208,7 +208,7 @@ func pruneBrokenReferences(ctx context.Context,
|
||||
stderrBuilder.Reset()
|
||||
stdoutBuilder.Reset()
|
||||
|
||||
pruneErr := gitrepo.PruneRemote(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
|
||||
pruneErr := gitrepo.GitRemotePrune(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
|
||||
if pruneErr != nil {
|
||||
stdout := stdoutBuilder.String()
|
||||
stderr := stderrBuilder.String()
|
||||
@ -261,7 +261,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
||||
}
|
||||
cmd.AddArguments("--tags").AddDynamicArguments(m.GetRemoteName())
|
||||
|
||||
remoteURL, remoteErr := gitrepo.GetRemoteURL(ctx, m.Repo, m.GetRemoteName())
|
||||
remoteURL, remoteErr := gitrepo.GitRemoteGetURL(ctx, m.Repo, m.GetRemoteName())
|
||||
if remoteErr != nil {
|
||||
log.Error("SyncMirrors [repo: %-v]: GetRemoteAddress Error %v", m.Repo, remoteErr)
|
||||
return nil, false
|
||||
@ -365,7 +365,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
||||
stderrBuilder.Reset()
|
||||
stdoutBuilder.Reset()
|
||||
|
||||
if err := gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||
if err := gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
||||
stdout := stdoutBuilder.String()
|
||||
stderr := stderrBuilder.String()
|
||||
@ -386,7 +386,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
||||
stderrBuilder.Reset()
|
||||
stdoutBuilder.Reset()
|
||||
|
||||
if err = gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||
if err = gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
||||
stdout := stdoutBuilder.String()
|
||||
stderr := stderrBuilder.String()
|
||||
|
@ -30,13 +30,13 @@ var stripExitStatus = regexp.MustCompile(`exit status \d+ - `)
|
||||
// AddPushMirrorRemote registers the push mirror remote.
|
||||
func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error {
|
||||
addRemoteAndConfig := func(storageRepo gitrepo.Repository, addr string) error {
|
||||
if err := gitrepo.AddGitRemote(ctx, storageRepo, m.RemoteName, addr, "--mirror=push"); err != nil {
|
||||
if err := gitrepo.GitRemoteAdd(ctx, storageRepo, m.RemoteName, addr, "--mirror=push"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := gitrepo.AddGitConfig(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*"); err != nil {
|
||||
if err := gitrepo.GitConfigAdd(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*"); err != nil {
|
||||
return err
|
||||
}
|
||||
return gitrepo.AddGitConfig(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/tags/*:refs/tags/*")
|
||||
return gitrepo.GitConfigAdd(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/tags/*:refs/tags/*")
|
||||
}
|
||||
|
||||
if err := addRemoteAndConfig(m.Repo, addr); err != nil {
|
||||
@ -58,12 +58,12 @@ func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr str
|
||||
// RemovePushMirrorRemote removes the push mirror remote.
|
||||
func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error {
|
||||
_ = m.GetRepository(ctx)
|
||||
if err := gitrepo.RemoveGitRemote(ctx, m.Repo, m.RemoteName); err != nil {
|
||||
if err := gitrepo.GitRemoteRemove(ctx, m.Repo, m.RemoteName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if m.Repo.HasWiki() {
|
||||
if err := gitrepo.RemoveGitRemote(ctx, m.Repo.WikiStorageRepo(), m.RemoteName); err != nil {
|
||||
if err := gitrepo.GitRemoteRemove(ctx, m.Repo.WikiStorageRepo(), m.RemoteName); err != nil {
|
||||
// The wiki remote may not exist
|
||||
log.Warn("Wiki Remote[%d] could not be removed: %v", m.ID, err)
|
||||
}
|
||||
@ -128,7 +128,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
||||
storageRepo = repo.WikiStorageRepo()
|
||||
path = repo.WikiPath()
|
||||
}
|
||||
remoteURL, err := gitrepo.GetRemoteURL(ctx, storageRepo, m.RemoteName)
|
||||
remoteURL, err := gitrepo.GitRemoteGetURL(ctx, storageRepo, m.RemoteName)
|
||||
if err != nil {
|
||||
log.Error("GetRemoteAddress(%s) Error %v", path, err)
|
||||
return errors.New("Unexpected error")
|
||||
|
@ -35,12 +35,12 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
if headGitRepo.Path != baseRepo.RepoPath() {
|
||||
// Add a temporary remote
|
||||
tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
if err = gitrepo.AddGitRemote(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil {
|
||||
if err = gitrepo.GitRemoteAdd(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil {
|
||||
return nil, fmt.Errorf("AddRemote: %w", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := gitrepo.RemoveGitRemote(ctx, headRepo, tmpRemote); err != nil {
|
||||
logger.Error("GetPullRequestInfo: RemoveGitRemote: %v", err)
|
||||
if err := gitrepo.GitRemoteRemove(ctx, headRepo, tmpRemote); err != nil {
|
||||
logger.Error("GetPullRequestInfo: GitRemoteRemove: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -272,13 +272,13 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
|
||||
}
|
||||
}
|
||||
|
||||
err := gitrepo.RemoveGitRemote(ctx, repo, "origin")
|
||||
err := gitrepo.GitRemoteRemove(ctx, repo, "origin")
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err)
|
||||
}
|
||||
|
||||
if repo.HasWiki() {
|
||||
err = gitrepo.RemoveGitRemote(ctx, repo.WikiStorageRepo(), "origin")
|
||||
err = gitrepo.GitRemoteRemove(ctx, repo.WikiStorageRepo(), "origin")
|
||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user