Skip to content
Merged
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
12 changes: 9 additions & 3 deletions desktop/internal/workbench/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ func (a *App) runBranchWrite(p *project, operation string, failed func(reason st
} else {
a.loadNestedRepos(p)
}
b.dialog = branchDialogNone
done(a, status)
if p.log.started {
a.loadLog(p)
}
b.dialog = branchDialogNone
done(a, status)
}
})
}
Expand Down Expand Up @@ -451,12 +451,16 @@ func (a *App) submitRename(p *project) {
return
}
branch := b.target
root := a.branchRoot(p)
a.performed("git.branch.rename", surfaceButton)
a.runBranchWrite(p, "git_branch_rename", a.text.Branch.RenameFailed,
func(ctx context.Context, kernel Kernel, root string) error {
return kernel.GitRenameBranch(ctx, root, branch, name)
},
func(a *App, status core.GitStatus) { a.notifySuccess(a.text.Branch.Renamed(name)) })
func(a *App, status core.GitStatus) {
a.renameLogReference(p, root, branch.FullName, "refs/heads/"+name, name)
a.notifySuccess(a.text.Branch.Renamed(name))
})
}

// submitRevision checks out the typed revision detached.
Expand Down Expand Up @@ -490,6 +494,7 @@ func (a *App) confirmDelete(p *project) {
return
}
branch := b.target
root := a.branchRoot(p)
var deleted core.GitBranchDeletion
a.performed("git.branch.delete", surfaceButton)
a.runBranchWrite(p, "git_branch_delete", a.text.Branch.DeleteFailed,
Expand All @@ -498,6 +503,7 @@ func (a *App) confirmDelete(p *project) {
return err
},
func(a *App, status core.GitStatus) {
a.dropLogReference(p, root, branch.FullName)
target := deleted.DeletedTarget
if len(target) > 10 {
target = target[:10]
Expand Down
5 changes: 4 additions & 1 deletion desktop/internal/workbench/branch_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ func (a *App) confirmDeleteTag(p *project) {
if b.busy {
return
}
name := b.target.ShortName
tag := b.target
name := tag.ShortName
root := a.branchRoot(p)
a.performed("git.tag.delete", surfaceButton)
a.runBranchWrite(p, "git_tag_delete", func(reason string) string {
return i18n.SharedFormat(a.language(), "desktop.tags.deleteFailed", map[string]string{"reason": reason})
Expand All @@ -121,6 +123,7 @@ func (a *App) confirmDeleteTag(p *project) {
return kernel.GitDeleteTag(ctx, root, name)
},
func(a *App, status core.GitStatus) {
a.dropLogReference(p, root, tag.FullName)
a.notifySuccess(i18n.SharedFormat(a.language(), "desktop.tags.deleted", map[string]string{"name": name}))
})
}
53 changes: 53 additions & 0 deletions desktop/internal/workbench/gitlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ func (a *App) loadLog(p *project) {
expanded, limit := l.expanded, a.gitLogLimit()
a.background(p, gitTimeout, func(ctx context.Context) func(*App) {
refs, sections, current, err := readReferences(ctx, kernel, root)
if err == nil && reference != "" && reference != headReference.FullName && !hasReference(refs.References, reference) {
reference = ""
}
var page core.GitHistoryPage
var graph core.Graph
if err == nil {
Expand Down Expand Up @@ -281,6 +284,15 @@ func (a *App) loadLog(p *project) {
return
}
l.refs, l.sections, l.current = refs, sections, current
if reference == "" && l.reference != "" {
l.reference, l.referenceLabel = "", ""
}
if l.refSelected != "" && l.refSelected != headReference.FullName && !hasReference(refs.References, l.refSelected) {
l.refSelected = ""
}
if s := a.logView.compareSource; s != nil && a.logView.compareRoot == p.logRepositoryRoot() && !hasReference(refs.References, s.FullName) {
a.logView.compareSource = nil
}
l.commits = page.Commits
l.byHash = indexCommits(page.Commits)
l.cursor, l.hasMore, l.limitReached = page.NextCursor, page.HasMore, page.LimitReached
Expand Down Expand Up @@ -419,6 +431,47 @@ func (a *App) setLogReference(p *project, full, short string) {
a.loadLog(p)
}

// hasReference reports that refs lists a reference with full name.
func hasReference(refs []core.GitReference, full string) bool {
return slices.ContainsFunc(refs, func(r core.GitReference) bool {
return r.FullName == full
})
}

// dropLogReference clears the log's walked, selected, or compared reference when it was deleted in root.
func (a *App) dropLogReference(p *project, root, full string) {
if full == "" || root != p.logRepositoryRoot() {
return
}
l := &p.log
if l.reference == full {
l.reference, l.referenceLabel = "", ""
}
if l.refSelected == full {
l.refSelected = ""
}
if s := a.logView.compareSource; s != nil && a.logView.compareRoot == root && s.FullName == full {
a.logView.compareSource = nil
}
}

// renameLogReference moves the log's walked, selected, or compared reference to its new name in root.
func (a *App) renameLogReference(p *project, root, oldFull, newFull, newShort string) {
if oldFull == "" || root != p.logRepositoryRoot() {
return
}
l := &p.log
if l.reference == oldFull {
l.reference, l.referenceLabel = newFull, newShort
}
if l.refSelected == oldFull {
l.refSelected = newFull
}
if s := a.logView.compareSource; s != nil && a.logView.compareRoot == root && s.FullName == oldFull {
s.FullName, s.ShortName = newFull, newShort
}
}

// logProjection is what one graph layout is made from, copied so the background work
// reads nothing the window thread changes.
type logProjection struct {
Expand Down
73 changes: 71 additions & 2 deletions desktop/internal/workbench/gitsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package workbench
import (
"os"
"path/filepath"
"slices"
"strings"
"testing"

Expand Down Expand Up @@ -251,11 +252,79 @@ func TestLogNewAndDeleteBranchFromTheBranchesPane(t *testing.T) {
if !ok {
t.Fatal("the log did not list the new branch")
}
p.log.refSelected = topic.FullName
h.settle()
v := &h.app.logView
i := slices.IndexFunc(v.refItems, func(r logRefRow) bool { return r.kind == logRefReference && r.short == "topic" })
if i < 0 {
t.Fatal("the reference pane does not show topic")
}
h.click(center(h.topHit(v.refs.RowID(i))))
h.settleChain()
if p.log.reference != topic.FullName || p.log.referenceLabel != "topic" || p.log.refSelected != topic.FullName {
t.Fatalf("after clicking topic: ref=%q label=%q selected=%q", p.log.reference, p.log.referenceLabel, p.log.refSelected)
}

h.clickNamed(h.app.text.Git.DeleteBranch)
h.settle()
if b.dialog != branchDialogDelete || b.target.FullName != topic.FullName {
t.Fatalf("dialog %v for %+v, want the delete confirmation of topic", b.dialog, b.target)
}
h.click(center(h.popupHit(h.app.text.Branch.DeleteButton)))
h.settleChain()
if p.log.err != nil {
t.Fatalf("log err after deleting filtered branch: %v", p.log.err)
}
if p.log.reference != "" || p.log.referenceLabel != "" || p.log.refSelected != "" {
t.Fatalf("after deleting topic: ref=%q label=%q selected=%q, want all cleared", p.log.reference, p.log.referenceLabel, p.log.refSelected)
}
if len(p.log.commits) == 0 {
t.Fatal("the log cleared commits after deleting the filtered branch")
}
if _, ok := p.log.findReference("refs/heads/main"); !ok {
t.Fatal("the reference pane lost main after deleting the filtered branch")
}

// Renaming the filtered current branch keeps the log on the renamed reference.
mainIdx := slices.IndexFunc(v.refItems, func(r logRefRow) bool { return r.kind == logRefReference && r.short == "main" })
if mainIdx < 0 {
t.Fatal("the reference pane does not show main")
}
h.click(center(h.topHit(v.refs.RowID(mainIdx))))
h.settleChain()
if p.log.reference != "refs/heads/main" {
t.Fatalf("after clicking main: ref=%q, want refs/heads/main", p.log.reference)
}
h.logRefMenu("main")
h.click(center(h.popupHit(h.app.text.Branch.Rename)))
h.settle()
if b.dialog != branchDialogRename || b.target.FullName != "refs/heads/main" {
t.Fatalf("dialog %v for %+v, want the rename dialog of main", b.dialog, b.target)
}
b.name.SetText("trunk")
h.settle()
h.app.submitRename(p)
h.settleChain()
if p.log.err != nil {
t.Fatalf("log err after renaming filtered branch: %v", p.log.err)
}
if p.log.reference != "refs/heads/trunk" || p.log.referenceLabel != "trunk" || p.log.refSelected != "refs/heads/trunk" {
t.Fatalf("after renaming main: ref=%q label=%q selected=%q", p.log.reference, p.log.referenceLabel, p.log.refSelected)
}

// If a filtered reference disappears outside the UI, reloading the log falls back to all
// references instead of failing git.historyPage and wiping the reference pane.
gitRun(t, dir, "branch", "ext")
h.app.setLogReference(p, "refs/heads/ext", "ext")
h.settleChain()
gitRun(t, dir, "branch", "-D", "ext")
h.app.loadLog(p)
h.settleChain()
if p.log.err != nil {
t.Fatalf("log err after external branch deletion: %v", p.log.err)
}
if p.log.reference != "" || p.log.referenceLabel != "" {
t.Fatalf("after external deletion: ref=%q label=%q, want cleared", p.log.reference, p.log.referenceLabel)
}
if len(p.log.commits) == 0 {
t.Fatal("the log has no commits after external deletion fallback")
}
}
Loading
Loading