adds claude-generated commit messages and a recent commits panel to the git view - adds log tailing in the explorer, branch merging and a clean up button

This commit is contained in:
2026-11-04 10:07:52 +01:00
parent 600d4874d2
commit cc6651c08a
49 changed files with 1944 additions and 180 deletions
@@ -3,6 +3,7 @@ import HelderCore
import SwiftUI
/// Local and origin branches; a click switches, but only while the working tree is clean.
/// A right click offers to merge the branch into the current one.
struct GitBranchesPanel: View {
let model: WorkspaceModel
let store: SourceControlStore
@@ -60,7 +61,8 @@ struct GitBranchesPanel: View {
name: name, remote: remote, current: current, locked: !current && store.isDirty,
meta: current ? "current" : (tracked ? "tracked" : ""),
action: canSwitch ? (remote && !tracked ? "checkout →" : "switch →") : "",
clickable: !current && !isCurrentUpstream
clickable: !current && !isCurrentUpstream,
menu: .branch(name: name, remote: remote, current: store.state.branch, isDirty: store.isDirty)
)
}
}
@@ -74,6 +76,7 @@ private struct BranchItem {
let meta: String
let action: String
let clickable: Bool
let menu: ContextTarget
}
private struct BranchRow: View {
@@ -112,6 +115,9 @@ private struct BranchRow: View {
model.perform(.switchBranch(item.name, remote: item.remote))
}
.pointerHand(item.clickable && !item.locked)
.overlay(RightClickArea { point in
model.perform(.showContextMenu(item.menu, anchor: point))
})
.tracksHover($isHovered)
.modifier(LockedTip(isLocked: item.locked))
}
@@ -131,12 +137,12 @@ private struct LockedTip: ViewModifier {
/// Puts the enclosing scroll view's scrollers over the content, so rows keep their 16px right padding.
/// A legacy scroller would take its width from the rows whenever the list overflows.
private struct OverlayScrollers: NSViewRepresentable {
struct OverlayScrollers: NSViewRepresentable {
func makeNSView(context: Context) -> OverlayScrollersProbe { OverlayScrollersProbe() }
func updateNSView(_ view: OverlayScrollersProbe, context: Context) { view.apply() }
}
private final class OverlayScrollersProbe: NSView {
final class OverlayScrollersProbe: NSView {
private var observer: NSObjectProtocol?
override func viewDidMoveToWindow() {
+78 -41
View File
@@ -2,7 +2,7 @@ import AppKit
import HelderCore
import SwiftUI
/// The message field over the author, the ⌘↵ hint and the Commit split button.
/// The message field over Gen. Commit Message, the author, the ⌘↵ hint and the three commit buttons.
struct GitCommitBlock: View {
let model: WorkspaceModel
let store: SourceControlStore
@@ -22,12 +22,13 @@ struct GitCommitBlock: View {
}
.animation(Metrics.colorTransition, value: isFocused)
HStack(spacing: 16) {
GenerateMessageButton(model: model, store: store)
if let author = store.author {
Text(author).typeRole(Typography.path).foregroundStyle(Palette.textMuted).lineLimit(1)
}
Text("⌘↵ commits").typeRole(Typography.path).foregroundStyle(Palette.text4).fixedSize()
Spacer(minLength: 0)
CommitSplitButton(model: model, store: store)
CommitButtons(model: model, store: store)
}
.padding(.leading, 16)
.padding(.trailing, 14)
@@ -43,57 +44,93 @@ struct GitCommitBlock: View {
}
}
/// `Commit N files` plus a caret that opens Commit / Commit and push. Amber only when git would accept it,
/// but both parts always run, so git's own refusal shows in the console.
private struct CommitSplitButton: View {
/// `Gen. Commit Message`: the Claude CLI writes the message for the staged changes. Dims while nothing is staged
/// and while a message is being written.
private struct GenerateMessageButton: View {
let model: WorkspaceModel
let store: SourceControlStore
@State private var mainHovered = false
@State private var caretHovered = false
@State private var caretFrame = CGRect.zero
@State private var hovered = false
var body: some View {
let ready = store.canCommitNow
let count = store.stagedPathCount
HStack(spacing: 0) {
Button { model.perform(.commit) } label: {
Text(count > 0 ? "Commit \(count) file\(count == 1 ? "" : "s")" : "Nothing staged")
let color = hovered ? Palette.text1 : Palette.text3
Button { model.perform(.generateCommitMessage) } label: {
HStack(spacing: 7) {
SparkGlyph()
.stroke(color, style: StrokeStyle(lineWidth: 1.1 * 12 / 16, lineJoin: .round))
.frame(width: 12, height: 12)
Text(store.isGeneratingMessage ? "Generating…" : "Gen. Commit Message")
.typeRole(Typography.gitCommitButton)
.padding(.horizontal, 18)
.frame(minWidth: GitMetrics.commitButtonMinWidth)
.frame(height: GitMetrics.commitButton)
.background(fill(ready: ready, hovered: mainHovered))
.contentShape(Rectangle())
.foregroundStyle(color)
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover($mainHovered)
Button(action: openMenu) {
GitIconView(icon: .chevronDown, size: 14)
.frame(width: GitMetrics.commitButton, height: GitMetrics.commitButton)
.background(fill(ready: ready, hovered: caretHovered))
.overlay(alignment: .leading) { Rectangle().fill(Palette.editor).frame(width: Metrics.hairline) }
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover($caretHovered)
.background(GlobalFrameReader(frame: $caretFrame))
.padding(.horizontal, 12)
.frame(height: GitMetrics.commitButton)
.background(hovered ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover($hovered)
.disabledLook(!store.canGenerateMessage)
.fixedSize()
}
}
/// `Add, Stage & Commit` and `Commit N files` beside the primary `Commit and push`. The last two dim while nothing is staged;
/// with files staged they always run, so git's refusal of an empty message shows in the console.
private struct CommitButtons: View {
let model: WorkspaceModel
let store: SourceControlStore
@State private var stageAllHovered = false
@State private var commitHovered = false
@State private var pushHovered = false
var body: some View {
let count = store.stagedPathCount
HStack(spacing: 8) {
secondaryButton("Add, Stage & Commit", command: .stageAllAndCommit, hovered: $stageAllHovered)
.disabledLook(!store.canStageAllAndCommit)
HStack(spacing: 8) {
secondaryButton(count > 0 ? "Commit \(count) file\(count == 1 ? "" : "s")" : "Nothing staged",
command: .commit, hovered: $commitHovered)
Button { model.perform(.commitAndPush) } label: {
Text("Commit and push")
.typeRole(Typography.gitCommitButton)
.foregroundStyle(store.canCommitNow ? Palette.badgeText : Palette.textMuted)
.padding(.horizontal, 18)
.frame(height: GitMetrics.commitButton)
.background(pushFill, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover($pushHovered)
}
.disabledLook(count == 0)
}
.foregroundStyle(ready ? Palette.badgeText : Palette.textMuted)
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.fixedSize()
}
private func fill(ready: Bool, hovered: Bool) -> Color {
if ready { return hovered ? Palette.amberDeep : Palette.amber }
return hovered ? Palette.commitIdleHover : Palette.raised
private func secondaryButton(_ title: String, command: Command, hovered: Binding<Bool>) -> some View {
Button { model.perform(command) } label: {
Text(title)
.typeRole(Typography.gitCommitButton)
.foregroundStyle(hovered.wrappedValue ? Palette.text1 : Palette.text3)
.padding(.horizontal, 18)
.frame(minWidth: GitMetrics.commitButtonMinWidth)
.frame(height: GitMetrics.commitButton)
.background(hovered.wrappedValue ? Palette.hover : .clear, in: RoundedRectangle(cornerRadius: Metrics.radiusSmall))
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusSmall).strokeBorder(Palette.raised, lineWidth: Metrics.hairline))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.pointerHand()
.tracksHover(hovered)
}
/// The menu hangs under the caret, right-aligned to it.
private func openMenu() {
let anchor = CGPoint(x: caretFrame.maxX - Metrics.contextMenuWidth, y: caretFrame.maxY + 4)
model.perform(.showContextMenu(.commitMenu, anchor: anchor))
private var pushFill: Color {
if store.canCommitNow { return pushHovered ? Palette.amberDeep : Palette.amber }
return pushHovered ? Palette.commitIdleHover : Palette.raised
}
}
@@ -0,0 +1,83 @@
import HelderCore
import SwiftUI
/// The bottom strip's right end on a wide window: the last commits of the current branch, read-only.
struct GitCommitsPanel: View {
let store: SourceControlStore
var body: some View {
VStack(spacing: 0) {
header
if !store.state.isRepository {
placeholder("— no repository")
} else if store.recentCommits.isEmpty {
placeholder("no commits yet")
} else {
ScrollView {
TimelineView(.periodic(from: .now, by: 30)) { context in
LazyVStack(alignment: .leading, spacing: 0) {
ForEach(store.recentCommits, id: \.hash) { commit in
CommitRow(commit: commit, now: context.date)
}
}
.padding(.bottom, 12)
}
.background(OverlayScrollers())
}
.scrollIndicators(.automatic)
}
Spacer(minLength: 0)
}
.clipped()
}
private var header: some View {
HStack(spacing: 12) {
Text("[ commits ]").typeRole(Typography.panelLabel).foregroundStyle(Palette.text4).fixedSize()
Spacer(minLength: 0)
if store.state.isRepository {
Text(store.state.branch)
.typeRole(Typography.path)
.foregroundStyle(Palette.textMuted)
.lineLimit(1)
.truncationMode(.middle)
}
}
.padding(.horizontal, 16)
.frame(height: GitMetrics.stripHeader)
}
private func placeholder(_ text: String) -> some View {
Text(text)
.typeRole(Typography.path)
.foregroundStyle(Palette.text4)
.padding(.horizontal, 16)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
private struct CommitRow: View {
let commit: GitCommitSummary
let now: Date
var body: some View {
HStack(spacing: 10) {
Text(commit.hash).typeRole(Typography.gitStats).foregroundStyle(Palette.amber).fixedSize()
Text(commit.subject)
.typeRole(Typography.path)
.foregroundStyle(Palette.text2)
.lineLimit(1)
.truncationMode(.tail)
.frame(maxWidth: .infinity, alignment: .leading)
HStack(spacing: 0) {
Text(commit.author).lineLimit(1).truncationMode(.tail).frame(maxWidth: 140, alignment: .trailing)
Text(" · \(RelativeTime.text(commit.date, now: now))").fixedSize()
}
.typeRole(Typography.meta)
.foregroundStyle(Palette.text4)
.layoutPriority(1)
}
.padding(.horizontal, 16)
.frame(height: GitMetrics.branchRow)
}
}
+5 -2
View File
@@ -1,7 +1,7 @@
import HelderCore
import SwiftUI
/// `[ git ]`, the branch and its place against origin, then Pull, Push and Close.
/// `[ git ]`, the branch and its place against origin, then Pull, Push, Clean up and Close.
struct GitTopBar: View {
let model: WorkspaceModel
let store: SourceControlStore
@@ -21,9 +21,12 @@ struct GitTopBar: View {
trailing: state.behind > 0 ? "↓\(state.behind)" : nil) { model.perform(.pull) }
GitBarButton(icon: .arrowUpFromLine, label: store.busy == .push ? "Pushing…" : "Push",
trailing: state.ahead > 0 ? "↑\(state.ahead)" : nil) { model.perform(.push) }
GitBarButton(icon: .eraser, label: "Clean up", trailing: nil) { model.perform(.context(.gitCleanUp)) }
.disabledLook(!store.canCleanUp)
GitBarButton(icon: .minimize, label: "Close", trailing: "⌘G") { model.perform(.closeGitView) }
}
.padding(.horizontal, 14)
.padding(.leading, model.layout.isFullScreen ? 14 : Metrics.trafficLightInset)
.padding(.trailing, 14)
.frame(height: GitMetrics.topBar)
.background(Palette.panel)
.hairline(.bottom)
+36 -7
View File
@@ -25,18 +25,27 @@ struct GitView: View {
}
}
/// The console left, the branches right, 230pt tall.
/// The console left, the branches right, 230pt tall; a wide window adds the commit list after them.
private struct GitBottomStrip: View {
let model: WorkspaceModel
let store: SourceControlStore
var body: some View {
HStack(spacing: 0) {
GitConsolePanel(model: model, store: store)
.frame(maxWidth: .infinity)
Hairline(.vertical)
GitBranchesPanel(model: model, store: store)
.frame(maxWidth: .infinity)
GeometryReader { proxy in
let layout = GitStripLayout(width: proxy.size.width)
HStack(spacing: 0) {
GitConsolePanel(model: model, store: store)
.frame(width: layout.console)
Hairline(.vertical)
GitBranchesPanel(model: model, store: store)
.frame(width: layout.branches)
if let commits = layout.commits {
Hairline(.vertical)
GitCommitsPanel(store: store)
.frame(width: commits)
}
Spacer(minLength: 0)
}
}
.frame(height: GitMetrics.bottomStrip)
.background(Palette.panel)
@@ -44,6 +53,23 @@ private struct GitBottomStrip: View {
}
}
/// The widths of the bottom strip's panels for one strip width.
struct GitStripLayout: Equatable {
var console: CGFloat
var branches: CGFloat
/// Nil while the room left after the two capped panels is under `GitMetrics.commitsMinWidth`.
var commits: CGFloat?
init(width: CGFloat) {
let hairline = Metrics.hairline
let share = max(0, (width - hairline) / 2).rounded(.down)
console = min(GitMetrics.consoleMaxWidth, share)
branches = min(GitMetrics.branchesMaxWidth, share)
let left = width - console - branches - 2 * hairline
commits = left >= GitMetrics.commitsMinWidth ? left : nil
}
}
/// The Git view's fixed sizes, from the design handoff.
enum GitMetrics {
static let topBar: CGFloat = 44
@@ -68,6 +94,9 @@ enum GitMetrics {
static let diffGutter: CGFloat = 52
static let diffGap: CGFloat = 28
static let bottomStrip: CGFloat = 230
static let consoleMaxWidth: CGFloat = 820
static let branchesMaxWidth: CGFloat = 820
static let commitsMinWidth: CGFloat = 260
static let stripHeader: CGFloat = 32
static let branchRow: CGFloat = 28
}