MCPcopy
hub / github.com/gogs/gogs / PushToBaseRepo

Method PushToBaseRepo

internal/database/pull.go:663–699  ·  view source on GitHub ↗

PushToBaseRepo pushes commits from branches of head repository to corresponding branches of base repository. FIXME: Only push branches that are actually updates?

()

Source from the content-addressed store, hash-verified

661// corresponding branches of base repository.
662// FIXME: Only push branches that are actually updates?
663func (pr *PullRequest) PushToBaseRepo() (err error) {
664 log.Trace("PushToBaseRepo[%d]: pushing commits to base repo 'refs/pull/%d/head'", pr.BaseRepoID, pr.Index)
665
666 headRepoPath := pr.HeadRepo.RepoPath()
667 headGitRepo, err := git.Open(headRepoPath)
668 if err != nil {
669 return errors.Newf("open repository: %v", err)
670 }
671
672 tmpRemote := fmt.Sprintf("tmp-pull-%d", pr.ID)
673 if err = headGitRepo.RemoteAdd(tmpRemote, pr.BaseRepo.RepoPath()); err != nil {
674 return errors.Newf("add remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
675 }
676
677 // Make sure to remove the remote even if the push fails
678 defer func() {
679 if err := headGitRepo.RemoteRemove(tmpRemote); err != nil {
680 log.Error("Failed to remove remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
681 }
682 }()
683
684 headRefspec := fmt.Sprintf("refs/pull/%d/head", pr.Index)
685 headFile := filepath.Join(pr.BaseRepo.RepoPath(), headRefspec)
686 if osutil.Exist(headFile) {
687 err = os.Remove(headFile)
688 if err != nil {
689 return errors.Newf("remove head file [repo_id: %d]: %v", pr.BaseRepoID, err)
690 }
691 }
692
693 err = headGitRepo.Push(tmpRemote, fmt.Sprintf("%s:%s", pr.HeadBranch, headRefspec))
694 if err != nil {
695 return errors.Newf("push: %v", err)
696 }
697
698 return nil
699}
700
701// AddToTaskQueue adds itself to pull request test task queue.
702func (pr *PullRequest) AddToTaskQueue() {

Callers 2

addHeadRepoTasksFunction · 0.80

Calls 6

ExistFunction · 0.92
RepoPathMethod · 0.80
RemoveMethod · 0.80
RemoteAddMethod · 0.65
RemoteRemoveMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected