diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 50e85ba27..5ea80af77 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -1241,6 +1241,10 @@ pulls.reject_count_1 = "%d change request"
pulls.reject_count_n = "%d change requests"
pulls.waiting_count_1 = "%d waiting review"
pulls.waiting_count_n = "%d waiting reviews"
+pulls.commits_count_1=This branch is %d commit behind the upstream.
+pulls.commits_count_n=This branch is %d commit behind the upstream.
+pulls.fetch_upstream=Fetch upstream
+pulls.upstream_up_to_date=No new commits to fetch
pulls.no_merge_desc = This pull request cannot be merged because all repository merge options are disabled.
pulls.no_merge_helper = Enable merge options in the repository settings or merge the pull request manually.
diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini
index 89a6282e5..3774668bb 100755
--- a/options/locale/locale_zh-CN.ini
+++ b/options/locale/locale_zh-CN.ini
@@ -1243,6 +1243,10 @@ pulls.reject_count_1=%d 变更请求
pulls.reject_count_n=%d 变更请求
pulls.waiting_count_1=%d 个正在等待审核
pulls.waiting_count_n=%d 个正在等待审核
+pulls.commits_count_1=当前分支落后上游分支 %d 个提交
+pulls.commits_count_n=当前分支落后上游分支 %d 个提交
+pulls.fetch_upstream=拉取上游更新
+pulls.upstream_up_to_date=上游分支没有新的更新
pulls.no_merge_desc=由于未启用合并选项,此合并请求无法被合并。
pulls.no_merge_helper=在项目设置中启用合并选项或者手工合并请求。
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 1546f53b7..8c768c9eb 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -790,6 +790,41 @@ func renderCode(ctx *context.Context) {
}
}
+ //如果是fork的仓库
+ if ctx.Repo.Repository.IsFork {
+ //获得fetchUpstream对应的分支参数
+ /*
+ // 1. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headBranch}
+ // 2. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}:{:headBranch}
+ // 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch}
+ */
+ baseGitRepo, err := git.OpenRepository(ctx.Repo.Repository.BaseRepo.RepoPath())
+ if err != nil {
+ log.Error("error open baseRepo:%s",ctx.Repo.Repository.BaseRepo.RepoPath())
+ }
+ defer baseGitRepo.Close()
+ if _,error:= baseGitRepo.GetBranch(ctx.Repo.BranchName);error==nil{
+ //base repo has the same branch, then compare between current repo branch and base repo's branch
+ compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName
+ ctx.SetParams("*",compareUrl)
+ }else{
+ //else, compare between current repo branch and base repo's default branch
+ compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch
+ ctx.SetParams("*",compareUrl)
+ }
+
+ _, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx)
+ defer headGitRepo.Close()
+ if compareInfo!= nil {
+ if compareInfo.Commits!=nil {
+ log.Info("compareInfoCommits数量:%d",compareInfo.Commits.Len())
+ ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len()
+ }else{
+ log.Info("compareInfo nothing different")
+ ctx.Data["FetchUpstreamCnt"] = 0
+ }
+ }
+ }
ctx.Data["Paths"] = paths
ctx.Data["TreeLink"] = treeLink
ctx.Data["TreeNames"] = treeNames
diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl
index b48efd498..2f123e473 100644
--- a/templates/repo/home.tmpl
+++ b/templates/repo/home.tmpl
@@ -119,6 +119,17 @@
+ {{if and .Repository.IsFork .PullRequestCtx.Allowed}}
+ {{if gt .FetchUpstreamCnt 0 }}
+
+
+
+ {{else}}
+
+
+
+ {{end}}
+ {{end}}
{{end}}
{{else}}