Skip to content

Commit 2e78c83

Browse files
committed
feat(desktop): sort base branch candidates by priority and recency
Prioritize main/master and release branches, sorting each group by the most recent commit date. This makes it easier to select the correct base branch when creating a PR. 🪄 Commit via GitWand
1 parent e418c2b commit 2e78c83

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

apps/desktop/src/components/PrCreateView.vue

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,45 @@ const forkTargets = computed(() => {
6868
const bareRemoteName = (ref: string) => ref.replace(/^[^/]+\//, "");
6969
7070
// ─── Base branch candidates ─────────────────────────────
71+
// Order: main/master first, then release/* branches, then the rest —
72+
// each group sorted by most-recently-updated first.
7173
const baseCandidates = computed<string[]>(() => {
74+
// Bare branch name → most recent commit date across its local + remote refs.
75+
const lastUpdated = new Map<string, number>();
76+
const noteDate = (bare: string, date: string) => {
77+
const ts = Date.parse(date) || 0;
78+
const prev = lastUpdated.get(bare);
79+
if (prev === undefined || ts > prev) lastUpdated.set(bare, ts);
80+
};
81+
7282
const locals = new Set<string>();
73-
const remoteOnly: string[] = [];
83+
const remoteOnly = new Set<string>();
7484
for (const b of props.branches) {
75-
if (!b.isRemote && b.name !== props.currentBranch) locals.add(b.name);
85+
if (!b.isRemote && b.name !== props.currentBranch) {
86+
locals.add(b.name);
87+
noteDate(b.name, b.lastCommitDate);
88+
}
7689
}
7790
for (const b of props.branches) {
7891
if (b.isRemote) {
7992
const bare = bareRemoteName(b.name);
80-
if (!locals.has(bare) && bare !== props.currentBranch) remoteOnly.push(bare);
93+
if (bare !== props.currentBranch) {
94+
if (!locals.has(bare)) remoteOnly.add(bare);
95+
noteDate(bare, b.lastCommitDate);
96+
}
8197
}
8298
}
83-
return [...Array.from(locals).sort(), ...Array.from(new Set(remoteOnly)).sort()];
99+
100+
const names = [...locals, ...remoteOnly];
101+
const byRecent = (a: string, b: string) =>
102+
(lastUpdated.get(b) ?? 0) - (lastUpdated.get(a) ?? 0) || a.localeCompare(b);
103+
104+
const primary = names.filter((n) => n === "main" || n === "master").sort(byRecent);
105+
const release = names.filter((n) => n.startsWith("release/")).sort(byRecent);
106+
const picked = new Set([...primary, ...release]);
107+
const rest = names.filter((n) => !picked.has(n)).sort(byRecent);
108+
109+
return [...primary, ...release, ...rest];
84110
});
85111
86112
const defaultBase = computed<string>(() => {

0 commit comments

Comments
 (0)