diff --git a/README.md b/README.md index 415e036b40..220e31c6fd 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) -##### Current version: 0.8.39 +##### Current version: 0.8.40 | Web | UI | Preview | |:-------------:|:-------:|:-------:| diff --git a/gogs.go b/gogs.go index 4c9a627dea..1e4241fd76 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.8.39.0219" +const APP_VER = "0.8.40.0219" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/pull.go b/models/pull.go index 67f103e8d5..bf16d98fa7 100644 --- a/models/pull.go +++ b/models/pull.go @@ -20,7 +20,6 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/setting" - "strconv" ) type PullRequestType int @@ -483,35 +482,28 @@ func (pr *PullRequest) UpdatePatch() (err error) { return nil } +// PushToBaseRepo pushes commits from branches of head repository to +// corresponding branches of base repository. +// FIXME: could fail after user force push head repo, should we always force push here? +// FIXME: Only push branches that are actually updates? func (pr *PullRequest) PushToBaseRepo() (err error) { - log.Trace("PushToBase[%d]: pushing commits to base repo refs/pull/%d/head", pr.ID, pr.ID) + log.Trace("PushToBaseRepo[%[1]d]: pushing commits to base repo 'refs/pull/%[1]d/head'", pr.ID) - branch := pr.HeadBranch - - if err = pr.BaseRepo.GetOwner(); err != nil { - return fmt.Errorf("Could not get base repo owner data: %v", err) - } else if err = pr.HeadRepo.GetOwner(); err != nil { - return fmt.Errorf("Could not get head repo owner data: %v", err) - } - - headRepoPath := RepoPath(pr.HeadRepo.Owner.Name, pr.HeadRepo.Name) - - prIdStr := strconv.FormatInt(pr.ID, 10) - tmpRemoteName := "tmp-pull-" + branch + "-" + prIdStr - repo, err := git.OpenRepository(headRepoPath) + headRepoPath := pr.HeadRepo.RepoPath() + headGitRepo, err := git.OpenRepository(headRepoPath) if err != nil { - return fmt.Errorf("Unable to open head repository: %v", err) + return fmt.Errorf("OpenRepository: %v", err) } - if err = repo.AddRemote(tmpRemoteName, RepoPath(pr.BaseRepo.Owner.Name, pr.BaseRepo.Name), false); err != nil { - return fmt.Errorf("Unable to add remote to head repository: %v", err) + 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 repo.RemoveRemote(tmpRemoteName) + defer headGitRepo.RemoveRemote(tmpRemoteName) - pushRef := branch+":"+"refs/pull/"+prIdStr+"/head" - if err = git.Push(headRepoPath, tmpRemoteName, pushRef); err != nil { - return fmt.Errorf("Error pushing: %v", err) + if err = git.Push(headRepoPath, tmpRemoteName, fmt.Sprintf("%s:refs/pull/%d/head", pr.HeadBranch, pr.Index)); err != nil { + return fmt.Errorf("Push: %v", err) } return nil diff --git a/templates/.VERSION b/templates/.VERSION index bbea7d5964..356e27b108 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.8.39.0219 \ No newline at end of file +0.8.40.0219 \ No newline at end of file