Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions supacode/Clients/Git/GitClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 3 additions & 3 deletions supacodeTests/GitClientBranchRefsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down