@@ -1186,19 +1186,35 @@ func CleanUpPullRequest(ctx *context.Context) {
11861186
11871187 fullBranchName := pr .HeadRepo .Owner .Name + "/" + pr .HeadBranch
11881188
1189- gitRepo , err := git .OpenRepository (pr .HeadRepo .RepoPath ())
1190- if err != nil {
1191- ctx .ServerError (fmt .Sprintf ("OpenRepository[%s]" , pr .HeadRepo .RepoPath ()), err )
1192- return
1189+ var gitBaseRepo * git.Repository
1190+
1191+ // Assume that the base repo is the current context (almost certainly)
1192+ if ctx .Repo != nil && ctx .Repo .Repository .ID == pr .BaseRepoID && ctx .Repo .GitRepo != nil {
1193+ gitBaseRepo = ctx .Repo .GitRepo
1194+ } else {
1195+ // If not just open it
1196+ gitBaseRepo , err = git .OpenRepository (pr .BaseRepo .RepoPath ())
1197+ if err != nil {
1198+ ctx .ServerError (fmt .Sprintf ("OpenRepository[%s]" , pr .BaseRepo .RepoPath ()), err )
1199+ return
1200+ }
1201+ defer gitBaseRepo .Close ()
11931202 }
1194- defer gitRepo .Close ()
11951203
1196- gitBaseRepo , err := git .OpenRepository (pr .BaseRepo .RepoPath ())
1197- if err != nil {
1198- ctx .ServerError (fmt .Sprintf ("OpenRepository[%s]" , pr .BaseRepo .RepoPath ()), err )
1199- return
1204+ // Now assume that the head repo is the same as the base repo (reasonable chance)
1205+ gitRepo := gitBaseRepo
1206+ // But if not: is it the same as the context?
1207+ if pr .BaseRepoID != pr .HeadRepoID && ctx .Repo != nil && ctx .Repo .Repository != nil && ctx .Repo .Repository .ID == pr .HeadRepoID && ctx .Repo .GitRepo != nil {
1208+ gitRepo = ctx .Repo .GitRepo
1209+ } else if pr .BaseRepoID != pr .HeadRepoID {
1210+ // Otherwise just load it up
1211+ gitRepo , err = git .OpenRepository (pr .HeadRepo .RepoPath ())
1212+ if err != nil {
1213+ ctx .ServerError (fmt .Sprintf ("OpenRepository[%s]" , pr .HeadRepo .RepoPath ()), err )
1214+ return
1215+ }
1216+ defer gitRepo .Close ()
12001217 }
1201- defer gitBaseRepo .Close ()
12021218
12031219 defer func () {
12041220 ctx .JSON (http .StatusOK , map [string ]interface {}{
0 commit comments