@@ -6,15 +6,12 @@ package repository
6
6
import (
7
7
"context"
8
8
"fmt"
9
- "strconv"
10
- "time"
11
9
12
10
git_model "code.gitea.io/gitea/models/git"
13
11
issue_model "code.gitea.io/gitea/models/issues"
14
12
repo_model "code.gitea.io/gitea/models/repo"
15
13
user_model "code.gitea.io/gitea/models/user"
16
14
"code.gitea.io/gitea/modules/git"
17
- "code.gitea.io/gitea/modules/log"
18
15
repo_module "code.gitea.io/gitea/modules/repository"
19
16
"code.gitea.io/gitea/modules/util"
20
17
"code.gitea.io/gitea/services/pull"
@@ -105,31 +102,29 @@ func GetUpstreamDivergingInfo(ctx context.Context, gitRepo *git.Repository, repo
105
102
return info , nil
106
103
}
107
104
108
- // Add a temporary remote
109
- tmpRemote := strconv .FormatInt (time .Now ().UnixNano (), 10 )
110
- if err = gitRepo .AddRemote (tmpRemote , repo .BaseRepo .RepoPath (), false ); err != nil {
111
- log .Error ("GetUpstreamDivergingInfo: AddRemote: %v" , err )
112
- }
113
- defer func () {
114
- if err := gitRepo .RemoveRemote (tmpRemote ); err != nil {
115
- log .Error ("GetUpstreamDivergingInfo: RemoveRemote: %v" , err )
116
- }
117
- }()
118
-
119
- var remoteBranch string
120
- _ , remoteBranch , err = gitRepo .GetMergeBase (tmpRemote , baseBranch .CommitID , forkBranch .CommitID )
121
- if err != nil {
122
- log .Error ("GetMergeBase: %v" , err )
123
- }
124
-
125
- baseBranch .CommitID , err = git .GetFullCommitID (gitRepo .Ctx , gitRepo .Path , remoteBranch )
126
- if err != nil {
127
- baseBranch .CommitID = remoteBranch
128
- }
129
-
130
105
diff , err := git .GetDivergingCommits (gitRepo .Ctx , gitRepo .Path , baseBranch .CommitID , forkBranch .CommitID )
131
106
if err != nil {
132
107
info .BaseIsNewer = baseBranch .UpdatedUnix > forkBranch .UpdatedUnix
108
+ if ! info .BaseIsNewer {
109
+ var (
110
+ baseCommitID git.ObjectID
111
+ headCommit * git.Commit
112
+ )
113
+
114
+ gitRepo .GetCommit (forkBranch .CommitID )
115
+
116
+ if baseCommitID , err = gitRepo .ConvertToGitID (baseBranch .CommitID ); err != nil {
117
+ return info , nil
118
+ }
119
+
120
+ if headCommit , err = gitRepo .GetCommit (forkBranch .CommitID ); err != nil {
121
+ return info , nil
122
+ }
123
+
124
+ if isAncester , _ := headCommit .HasPreviousCommit (baseCommitID ); ! isAncester {
125
+ info .BaseIsNewer = true
126
+ }
127
+ }
133
128
return info , nil
134
129
}
135
130
info .CommitsBehind , info .CommitsAhead = diff .Behind , diff .Ahead
0 commit comments