Skip to content

Commit 648957f

Browse files
committed
fine tune
1 parent a7ed2dd commit 648957f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,7 @@ pulls.delete.text = Do you really want to delete this pull request? (This will p
19481948
pulls.recently_pushed_new_branches = You pushed on branch <strong>%[1]s</strong> %[2]s
19491949
pulls.upstream_diverging_prompt_behind_1 = This branch is %d commit behind %s
19501950
pulls.upstream_diverging_prompt_behind_n = This branch is %d commits behind %s
1951+
pulls.upstream_diverging_prompt_base_newer = The base branch %s is newer than this branch
19511952
pulls.upstream_diverging_merge = Sync fork
19521953

19531954
pull.deleted_branch = (deleted):%s

routers/web/repo/view_home.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ func prepareUpstreamDivergingInfo(ctx *context.Context) {
184184
upstreamDivergingInfo, err := repo_service.GetUpstreamDivergingInfo(ctx, ctx.Repo.Repository, ctx.Repo.BranchName)
185185
if err != nil {
186186
if !errors.Is(err, util.ErrNotExist) && !errors.Is(err, util.ErrInvalidArgument) {
187-
// TODO: if the fork repo has new commits, there will be an error, at the moment we are not able to handle it, should be improved in the future
188-
log.Debug("GetUpstreamDivergingInfo: %v", err)
187+
log.Error("GetUpstreamDivergingInfo: %v", err)
189188
}
190189
return
191190
}

services/repository/merge_upstream.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
)
1919

2020
type UpstreamDivergingInfo struct {
21+
BaseIsNewer bool
2122
CommitsBehind int
2223
CommitsAhead int
2324
}
@@ -106,7 +107,8 @@ func GetUpstreamDivergingInfo(ctx context.Context, repo *repo_model.Repository,
106107
// so at the moment, we are not able to handle this case, should be improved in the future
107108
diff, err := git.GetDivergingCommits(ctx, repo.BaseRepo.RepoPath(), baseBranch.CommitID, forkBranch.CommitID)
108109
if err != nil {
109-
return nil, err
110+
info.BaseIsNewer = baseBranch.UpdatedUnix > forkBranch.UpdatedUnix
111+
return info, nil
110112
}
111113
info.CommitsBehind, info.CommitsAhead = diff.Behind, diff.Ahead
112114
return info, nil

templates/repo/code/upstream_diverging_info.tmpl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
{{if and .UpstreamDivergingInfo .UpstreamDivergingInfo.CommitsBehind}}
1+
{{if and .UpstreamDivergingInfo (or .UpstreamDivergingInfo.BaseIsNewer .UpstreamDivergingInfo.CommitsBehind)}}
22
<div class="ui message flex-text-block">
33
<div class="tw-flex-1">
44
{{$upstreamLink := printf "%s/src/branch/%s" .Repository.BaseRepo.Link (.BranchName|PathEscapeSegments)}}
55
{{$upstreamHtml := HTMLFormat `<a href="%s">%s:%s</a>` $upstreamLink .Repository.BaseRepo.FullName .BranchName}}
6-
{{ctx.Locale.TrN .UpstreamDivergingInfo.CommitsBehind "repo.pulls.upstream_diverging_prompt_behind_1" "repo.pulls.upstream_diverging_prompt_behind_n" .UpstreamDivergingInfo.CommitsBehind $upstreamHtml}}
6+
{{if .UpstreamDivergingInfo.CommitsBehind}}
7+
{{ctx.Locale.TrN .UpstreamDivergingInfo.CommitsBehind "repo.pulls.upstream_diverging_prompt_behind_1" "repo.pulls.upstream_diverging_prompt_behind_n" .UpstreamDivergingInfo.CommitsBehind $upstreamHtml}}
8+
{{else}}
9+
{{ctx.Locale.Tr "repo.pulls.upstream_diverging_prompt_base_newer" $upstreamHtml}}
10+
{{end}}
711
</div>
812
{{if .CanWriteCode}}
913
<button class="ui compact green button tw-m-0 link-action" data-url="{{.Repository.Link}}/branches/merge-upstream?branch={{.BranchName}}">

0 commit comments

Comments
 (0)