Skip to content

Commit e4541e6

Browse files
julianknutsenclaude
andcommitted
Show origin vs upstream location for in-flight branches in wl me
Queries dolt_remote_branches after fetch to determine where each wl/* branch has been pushed: "origin", "upstream", "origin + upstream", or "local only". Displayed alongside each in-flight branch item. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 89c4b18 commit e4541e6

1 file changed

Lines changed: 60 additions & 7 deletions

File tree

cmd/wl/cmd_me.go

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func runMe(cmd *cobra.Command, stdout, _ io.Writer) error {
102102
if len(branchItems) > 0 {
103103
fmt.Fprintf(stdout, "\n%s\n", style.Bold.Render("In-flight branches (not yet on main):"))
104104
for _, bi := range branchItems {
105-
fmt.Fprintf(stdout, " %-12s %-30s %s\n", bi.id, bi.title, style.Dim.Render(bi.branch))
105+
fmt.Fprintf(stdout, " %-12s %-30s %-18s %s\n", bi.id, bi.title, style.Dim.Render(bi.location), style.Dim.Render(bi.branch))
106106
}
107107
printed = true
108108
}
@@ -181,9 +181,59 @@ func queryClaimedAsOf(dbDir, handle, ref string) [][]string {
181181

182182
// branchItem represents a wanted item found on a wl/* branch.
183183
type branchItem struct {
184-
id string
185-
title string
186-
branch string
184+
id string
185+
title string
186+
branch string
187+
location string // "local only", "origin", "upstream", "origin + upstream"
188+
}
189+
190+
// remoteBranchSet returns the set of branch names that exist on remotes,
191+
// keyed by the local branch name (e.g. "wl/alice/w-123" → {"origin": true}).
192+
func remoteBranchSet(dbDir string) map[string]map[string]bool {
193+
csv, err := commons.DoltSQLQuery(dbDir, "SELECT name FROM dolt_remote_branches")
194+
if err != nil {
195+
return nil
196+
}
197+
rows := wlParseCSV(csv)
198+
result := make(map[string]map[string]bool)
199+
for i, row := range rows {
200+
if i == 0 || len(row) < 1 { // skip header
201+
continue
202+
}
203+
// name is "origin/wl/alice/w-123" or "upstream/wl/alice/w-123"
204+
name := row[0]
205+
slashIdx := strings.Index(name, "/")
206+
if slashIdx < 0 {
207+
continue
208+
}
209+
remote := name[:slashIdx]
210+
localName := name[slashIdx+1:]
211+
if result[localName] == nil {
212+
result[localName] = make(map[string]bool)
213+
}
214+
result[localName][remote] = true
215+
}
216+
return result
217+
}
218+
219+
// branchLocation returns a human-readable location string for a branch.
220+
func branchLocation(remotes map[string]map[string]bool, branch string) string {
221+
if remotes == nil {
222+
return "local only"
223+
}
224+
rm := remotes[branch]
225+
onOrigin := rm["origin"]
226+
onUpstream := rm["upstream"]
227+
switch {
228+
case onOrigin && onUpstream:
229+
return "origin + upstream"
230+
case onOrigin:
231+
return "origin"
232+
case onUpstream:
233+
return "upstream"
234+
default:
235+
return "local only"
236+
}
187237
}
188238

189239
// listBranchItems scans wl/<handle>/* branches and returns items that differ
@@ -195,6 +245,8 @@ func listBranchItems(dbDir, handle string, skipIDs map[string]bool) []branchItem
195245
return nil
196246
}
197247

248+
remotes := remoteBranchSet(dbDir)
249+
198250
var items []branchItem
199251
for _, branch := range branches {
200252
wantedID := extractBranchWantedID(branch)
@@ -215,9 +267,10 @@ func listBranchItems(dbDir, handle string, skipIDs map[string]bool) []branchItem
215267
continue
216268
}
217269
items = append(items, branchItem{
218-
id: rows[1][0],
219-
title: rows[1][1],
220-
branch: branch,
270+
id: rows[1][0],
271+
title: rows[1][1],
272+
branch: branch,
273+
location: branchLocation(remotes, branch),
221274
})
222275
}
223276
return items

0 commit comments

Comments
 (0)