diff --git a/src/main/kotlin/com/gitvantage/app/AppState.kt b/src/main/kotlin/com/gitvantage/app/AppState.kt index 49caf75..aae54e7 100644 --- a/src/main/kotlin/com/gitvantage/app/AppState.kt +++ b/src/main/kotlin/com/gitvantage/app/AppState.kt @@ -2770,7 +2770,7 @@ class AppState(private val scope: CoroutineScope) { val vms = views() return mapOf( "all" to vms.size, - "dirty" to vms.count { it.isDirty }, + "dirty" to vms.count { it.dirtyAnywhere }, "aging" to vms.count { it.aging }, "unpushed" to vms.count { it.ahead > 0 }, "behind" to vms.count { it.repo.behind > 0 }, @@ -2803,7 +2803,7 @@ class AppState(private val scope: CoroutineScope) { entries[id]?.addedAt?.let { System.currentTimeMillis() - it.toEpochMilli() < Meta.RECENT_MS } ?: false private fun statusPredicate(v: RepoView): Boolean = when (status) { - "dirty" -> v.isDirty + "dirty" -> v.dirtyAnywhere "aging" -> v.aging "unpushed" -> v.ahead > 0 "behind" -> v.repo.behind > 0 diff --git a/src/main/kotlin/com/gitvantage/app/Derive.kt b/src/main/kotlin/com/gitvantage/app/Derive.kt index 8954c72..84c3c0b 100644 --- a/src/main/kotlin/com/gitvantage/app/Derive.kt +++ b/src/main/kotlin/com/gitvantage/app/Derive.kt @@ -205,6 +205,14 @@ data class RepoView( * [Repo.worktreesUnlanded] counts folders; this counts the ones still allowed to speak up. */ val worktreesUnlanded get() = worktrees.count { it.rollsUp } + + /** + * Uncommitted changes in this checkout or in any of its linked worktrees — what the Dirty + * filter selects. Kept apart from [isDirty], which stays about this checkout alone because it + * drives the row's badges and its Commit button, and neither of those can act on another folder. + * Read raw like [isDirty]: a snooze silences alerts, it doesn't make a tree clean. + */ + val dirtyAnywhere get() = isDirty || worktrees.any { it.wt.dirtyCount > 0 } } /** Contextual primary action pill. */ diff --git a/src/main/kotlin/com/gitvantage/ui/Bars.kt b/src/main/kotlin/com/gitvantage/ui/Bars.kt index 6778f68..6402ec6 100644 --- a/src/main/kotlin/com/gitvantage/ui/Bars.kt +++ b/src/main/kotlin/com/gitvantage/ui/Bars.kt @@ -276,7 +276,7 @@ fun StatusBar(state: AppState) { // key, label, and the hover explanation of what the filter selects. val chips = listOf( Triple("all", "All", "Every tracked repository."), - Triple("dirty", "Dirty", "Repos with uncommitted changes — staged, modified, or untracked files."), + Triple("dirty", "Dirty", "Repos with uncommitted changes — staged, modified, or untracked files — in the main checkout or any of its worktrees."), Triple("aging", "Aging", "Repos whose uncommitted changes have been sitting for over 24 hours."), Triple("unpushed", "Unpushed", "Repos with local commits that haven't been pushed to their upstream yet."), Triple("behind", "Behind", "Repos whose branch is behind its upstream — there are commits to pull in."), diff --git a/src/test/kotlin/com/gitvantage/app/DirtyFilterTest.kt b/src/test/kotlin/com/gitvantage/app/DirtyFilterTest.kt new file mode 100644 index 0000000..d39a4d2 --- /dev/null +++ b/src/test/kotlin/com/gitvantage/app/DirtyFilterTest.kt @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2026 Raman Gupta +// SPDX-License-Identifier: GPL-3.0-or-later + +package com.gitvantage.app + +import androidx.compose.ui.graphics.Color +import com.gitvantage.model.Repo +import com.gitvantage.model.Worktree +import com.gitvantage.model.WorktreeAlerts +import de.infix.testBalloon.framework.core.testSuite + +/** + * What the Dirty filter selects: uncommitted work in the repo's own checkout *or* in any of its + * linked worktrees — while the row's own [RepoView.isDirty], which drives its badges and Commit + * button, stays about the checkout the row stands for. + */ +val DirtyFilter by testSuite { + + fun tree(dirty: Int) = Worktree( + path = "/w/side", head = "abc1234", branch = "side", bare = false, + locked = false, lockReason = null, prunable = false, prunableReason = null, + isMain = false, dirtyCount = dirty, + ) + + fun view(unstaged: Int = 0, treeDirty: Int? = null, treeSnoozed: Boolean = false) = deriveView( + Repo(id = "/w", name = "w", branch = "main", unstaged = unstaged), + Color.Unspecified, emptyList(), + worktrees = listOfNotNull(treeDirty?.let { + WorktreeView( + wt = tree(it), repoId = "/w", alerts = WorktreeAlerts(), + snoozed = treeSnoozed, snoozedFor = if (treeSnoozed) "2d" else null, parentAlertsOn = true, + ) + }), + ) + + test("a clean checkout with a dirty worktree is dirty for the filter, not for the row") { + val v = view(treeDirty = 3) + assert(v.dirtyAnywhere) + assert(!v.isDirty) + } + + test("a dirty checkout is dirty either way") { + assert(view(unstaged = 1).dirtyAnywhere) + assert(view(unstaged = 1, treeDirty = 0).dirtyAnywhere) + } + + test("clean everywhere stays out of the filter") { + assert(!view().dirtyAnywhere) + assert(!view(treeDirty = 0).dirtyAnywhere) + } + + test("a snoozed worktree still counts — a snooze doesn't make a tree clean") { + assert(view(treeDirty = 2, treeSnoozed = true).dirtyAnywhere) + } +}