diff --git a/supacode/Clients/Git/GitClient.swift b/supacode/Clients/Git/GitClient.swift index 39549ac5..f2c54153 100644 --- a/supacode/Clients/Git/GitClient.swift +++ b/supacode/Clients/Git/GitClient.swift @@ -586,20 +586,25 @@ struct GitClient { nonisolated private func parseLocalRefsWithUpstream(_ output: String) -> [String] { output .split(whereSeparator: \.isNewline) - .compactMap { line in + .flatMap { line -> [String] in let parts = line.split(separator: "\t", omittingEmptySubsequences: false) guard let local = parts.first else { - return nil + return [] } let localRef = String(local).trimmingCharacters(in: .whitespacesAndNewlines) let upstreamRef = parts.count > 1 ? String(parts[1]).trimmingCharacters(in: .whitespacesAndNewlines) : "" + + var refs: [String] = [] + if !localRef.isEmpty { + refs.append(localRef) + } if !upstreamRef.isEmpty { - return upstreamRef + refs.append(upstreamRef) } - return localRef.isEmpty ? nil : localRef + return refs } } diff --git a/supacodeTests/GitClientBranchRefsTests.swift b/supacodeTests/GitClientBranchRefsTests.swift index f5671e11..6d943ded 100644 --- a/supacodeTests/GitClientBranchRefsTests.swift +++ b/supacodeTests/GitClientBranchRefsTests.swift @@ -12,7 +12,7 @@ actor ShellCallStore { } struct GitClientBranchRefsTests { - @Test func branchRefsUsesUpstreamsOrLocalRefs() async throws { + @Test func branchRefsIncludesLocalAndUpstreamRefs() async throws { let store = ShellCallStore() let output = """ feature\torigin/feature @@ -31,7 +31,7 @@ struct GitClientBranchRefsTests { let refs = try await client.branchRefs(for: repoRoot) - let expected = ["origin/bugfix", "origin/feature", "main"] + let expected = ["bugfix", "feature", "main", "origin/bugfix", "origin/feature"] .sorted { $0.localizedStandardCompare($1) == .orderedAscending } #expect(refs == expected) let calls = await store.calls @@ -57,7 +57,7 @@ struct GitClientBranchRefsTests { let refs = try await client.branchRefs(for: repoRoot) - #expect(refs == ["origin/main"]) + #expect(refs == ["head", "main", "origin/main"]) } @Test func defaultRemoteBranchRefStripsPrefix() async throws {