Move PushToBaseRepo from models to services/pull (#9352)
This commit is contained in:
parent
6715677b2b
commit
ce2d488c94
6 changed files with 57 additions and 53 deletions
|
@ -7,8 +7,6 @@ package models
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
|
@ -631,48 +629,6 @@ func (pr *PullRequest) UpdateCols(cols ...string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// PushToBaseRepo pushes commits from branches of head repository to
|
||||
// corresponding branches of base repository.
|
||||
// FIXME: Only push branches that are actually updates?
|
||||
func (pr *PullRequest) PushToBaseRepo() (err error) {
|
||||
log.Trace("PushToBaseRepo[%d]: pushing commits to base repo '%s'", pr.BaseRepoID, pr.GetGitRefName())
|
||||
|
||||
headRepoPath := pr.HeadRepo.RepoPath()
|
||||
headGitRepo, err := git.OpenRepository(headRepoPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("OpenRepository: %v", err)
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
tmpRemoteName := fmt.Sprintf("tmp-pull-%d", pr.ID)
|
||||
if err = headGitRepo.AddRemote(tmpRemoteName, pr.BaseRepo.RepoPath(), false); err != nil {
|
||||
return fmt.Errorf("headGitRepo.AddRemote: %v", err)
|
||||
}
|
||||
// Make sure to remove the remote even if the push fails
|
||||
defer func() {
|
||||
if err := headGitRepo.RemoveRemote(tmpRemoteName); err != nil {
|
||||
log.Error("PushToBaseRepo: RemoveRemote: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
headFile := pr.GetGitRefName()
|
||||
|
||||
// Remove head in case there is a conflict.
|
||||
file := path.Join(pr.BaseRepo.RepoPath(), headFile)
|
||||
|
||||
_ = os.Remove(file)
|
||||
|
||||
if err = git.Push(headRepoPath, git.PushOptions{
|
||||
Remote: tmpRemoteName,
|
||||
Branch: fmt.Sprintf("%s:%s", pr.HeadBranch, headFile),
|
||||
Force: true,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Push: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsWorkInProgress determine if the Pull Request is a Work In Progress by its title
|
||||
func (pr *PullRequest) IsWorkInProgress() bool {
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
|
|
|
@ -190,8 +190,6 @@ func TestPullRequest_UpdateCols(t *testing.T) {
|
|||
CheckConsistencyFor(t, pr)
|
||||
}
|
||||
|
||||
// TODO TestPullRequest_PushToBaseRepo
|
||||
|
||||
func TestPullRequestList_LoadAttributes(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue