You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -173,8 +197,10 @@ class RepositoryManager(private val project: Project) {
173
197
}
174
198
175
199
funclear() {
176
-
177
200
currentRepository =null
201
+
enabledBranches = emptyList()
202
+
branchState =BranchState.OnUnknownBranch
203
+
lastBranchState =null
178
204
setNewState(RepositoryManagerState.NoRepository)
179
205
}
180
206
@@ -223,4 +249,65 @@ class RepositoryManager(private val project: Project) {
223
249
}
224
250
}
225
251
252
+
@OptIn(DelicateCoroutinesApi::class)
253
+
privatesuspendfunevaluateBranchState() {
254
+
if (state !=RepositoryManagerState.Loaded|| repository ==null) return
255
+
256
+
val currentBranch = currentRepository?.currentBranch?.name
257
+
val repo = repository!!
258
+
259
+
// If no HEAD name, set to OnUnknownBranch
260
+
if (currentBranch.isNullOrBlank()) {
261
+
Logger.warn("No HEAD information found: ${currentRepository?.currentBranch}")
262
+
setBranchState(BranchState.OnUnknownBranch)
263
+
return
264
+
}
265
+
266
+
// If PR is loaded, set to OnPullRequestBranch
267
+
if (prState ==PullRequestState.Loaded) {
268
+
setBranchState(BranchState.OnPullRequestBranch)
269
+
return
270
+
}
271
+
272
+
// Check if current branch is in enabled branches
273
+
val isEnabledBranch = enabledBranches.any { it.name == currentBranch }
274
+
275
+
if (isEnabledBranch) {
276
+
Logger.info("Current branch is an analyzed branch: $currentBranch")
277
+
278
+
// Get the last analyzed commit for this branch
279
+
try {
280
+
val analysisResponse = api.getRepositoryWithAnalysis(repo.provider, repo.owner, repo.name)
281
+
val lastAnalysedCommit = analysisResponse.data.lastAnalysedCommit
282
+
val localHeadCommit =GitProvider.getHeadCommitSHA(project)
283
+
284
+
if (localHeadCommit !=null&& lastAnalysedCommit.sha != localHeadCommit) {
285
+
Logger.info("Local branch '$currentBranch' is outdated: Local Head ${localHeadCommit.substring(0, 7)} !== Last analysed Head ${lastAnalysedCommit.sha.substring(0, 7)}")
0 commit comments