@@ -27,6 +27,7 @@ class GitRepositoryService: ObservableObject {
2727 private var isStatusReloadPending = false
2828 private let statusReloadDebounceInterval : TimeInterval = 0.3
2929 private var inFlightStatusTask : Task < Void , Never > ?
30+ private var pendingReloadIsLightweight = true
3031
3132 init ( worktreePath: String ) {
3233 self . worktreePath = worktreePath
@@ -328,16 +329,16 @@ class GitRepositoryService: ObservableObject {
328329
329330 // MARK: - Status Loading
330331
331- func reloadStatus( ) {
332+ func reloadStatus( lightweight : Bool = false ) {
332333 Task { @MainActor [ weak self] in
333- self ? . reloadStatusDebouncedOnMain ( )
334+ self ? . reloadStatusDebouncedOnMain ( lightweight : lightweight )
334335 }
335336 }
336337
337338 /// Force immediate status reload without debouncing (for use after operations)
338339 private func reloadStatusImmediate( ) {
339340 Task { @MainActor [ weak self] in
340- await self ? . reloadStatusNowOnMain ( )
341+ await self ? . reloadStatusNowOnMain ( lightweight : false )
341342 }
342343 }
343344
@@ -347,7 +348,7 @@ class GitRepositoryService: ObservableObject {
347348 guard newPath != self . worktreePath else { return }
348349 self . worktreePath = newPath
349350 self . currentStatus = . empty
350- self . reloadStatusDebouncedOnMain ( )
351+ self . reloadStatusDebouncedOnMain ( lightweight : true )
351352 }
352353 }
353354
@@ -359,7 +360,7 @@ class GitRepositoryService: ObservableObject {
359360 await MainActor . run { original ? ( ) }
360361 return
361362 }
362- await self . reloadStatusNow ( )
363+ await self . reloadStatusNow ( lightweight : false )
363364 await MainActor . run {
364365 original ? ( )
365366 }
@@ -390,12 +391,16 @@ class GitRepositoryService: ObservableObject {
390391 }
391392
392393 private func reloadStatusInternal( ) async {
393- await reloadStatusNow ( )
394+ await reloadStatusNow ( lightweight : false )
394395 }
395396
396397 nonisolated
397- private func loadGitStatus( at path: String ) async throws -> GitStatus {
398- let detailedStatus = try await statusService. getDetailedStatus ( at: path)
398+ private func loadGitStatus( at path: String , lightweight: Bool ) async throws -> GitStatus {
399+ let detailedStatus = try await statusService. getDetailedStatus (
400+ at: path,
401+ includeUntracked: !lightweight,
402+ includeDiffStats: !lightweight
403+ )
399404
400405 return GitStatus (
401406 stagedFiles: detailedStatus. stagedFiles,
@@ -410,18 +415,19 @@ class GitRepositoryService: ObservableObject {
410415 )
411416 }
412417
413- private func reloadStatusNow( ) async {
418+ private func reloadStatusNow( lightweight : Bool ) async {
414419 let task = await MainActor . run { ( ) -> Task < Void , Never > ? in
415420 statusReloadTask? . cancel ( )
416421 isStatusReloadPending = false
422+ pendingReloadIsLightweight = true
417423
418424 let path = worktreePath
419425
420426 inFlightStatusTask? . cancel ( )
421427 let task = Task ( priority: . utility) { [ weak self] in
422428 guard let self else { return }
423429 do {
424- let status = try await self . loadGitStatus ( at: path)
430+ let status = try await self . loadGitStatus ( at: path, lightweight : lightweight )
425431 guard !Task. isCancelled else { return }
426432 await MainActor . run {
427433 // Guard against path changes while loading (e.g. worktree switch).
@@ -439,11 +445,17 @@ class GitRepositoryService: ObservableObject {
439445 }
440446
441447 @MainActor
442- private func reloadStatusDebouncedOnMain( ) {
448+ private func reloadStatusDebouncedOnMain( lightweight : Bool ) {
443449 if isStatusReloadPending {
450+ // Upgrade pending lightweight reload to full if requested.
451+ if pendingReloadIsLightweight && !lightweight {
452+ pendingReloadIsLightweight = false
453+ }
444454 return
445455 }
456+
446457 isStatusReloadPending = true
458+ pendingReloadIsLightweight = lightweight
447459
448460 statusReloadTask? . cancel ( )
449461 statusReloadTask = Task { [ weak self] in
@@ -458,12 +470,13 @@ class GitRepositoryService: ObservableObject {
458470 await MainActor . run {
459471 self . isStatusReloadPending = false
460472 }
461- await self . reloadStatusNow ( )
473+ let doLightweight = await MainActor . run { self . pendingReloadIsLightweight }
474+ await self . reloadStatusNow ( lightweight: doLightweight)
462475 }
463476 }
464477
465478 @MainActor
466- private func reloadStatusNowOnMain( ) async {
467- await reloadStatusNow ( )
479+ private func reloadStatusNowOnMain( lightweight : Bool ) async {
480+ await reloadStatusNow ( lightweight : lightweight )
468481 }
469482}
0 commit comments