Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: add prune-merged-branches button to Local Branches panel in app Git tab

Adam Eivy61bf2ac5e702
diff --git a/client/src/components/apps/tabs/GitTab.jsx b/client/src/components/apps/tabs/GitTab.jsx
index eb46d065a9..7139562352 100644
--- a/client/src/components/apps/tabs/GitTab.jsx
+++ b/client/src/components/apps/tabs/GitTab.jsx
@@ -328,6 +328,7 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
};
const mergedBranchCount = remoteBranches.filter(rb => rb.merged && !rb.isDefault).length;
+ const localMergedCount = branches.filter(b => b.merged).length;
const handleCleanupMerged = async () => {
if (!repoPath || cleaningUp) return;
@@ -552,7 +553,38 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
{/* Local Branches */}
<div className="bg-port-card border border-port-border rounded-xl p-4">
- <h3 className="text-sm font-medium text-gray-400 mb-3">Local Branches</h3>
+ <div className="flex flex-wrap items-center justify-between gap-2 mb-3">
+ <h3 className="text-sm font-medium text-gray-400">Local Branches</h3>
+ <div className="flex flex-wrap items-center gap-2">
+ {localMergedCount > 0 && !cleanupConfirm && (
+ <button
+ onClick={() => setCleanupConfirm('local')}
+ disabled={cleaningUp}
+ className={`flex items-center gap-1 text-xs ${touchBtnCls} text-port-warning hover:text-port-error disabled:opacity-50`}
+ >
+ <Trash2 size={12} />
+ {cleaningUp ? 'Cleaning...' : `Clean ${localMergedCount} merged`}
+ </button>
+ )}
+ {cleanupConfirm === 'local' && (
+ <div className="flex flex-wrap items-center gap-1">
+ <button
+ onClick={handleCleanupMerged}
+ disabled={cleaningUp}
+ className={`px-2 py-1 ${touchBtnCls} text-xs bg-port-error/20 text-port-error rounded hover:bg-port-error/30 disabled:opacity-50`}
+ >
+ {cleaningUp ? 'Deleting...' : `Delete ${localMergedCount} merged`}
+ </button>
+ <button
+ onClick={() => setCleanupConfirm(false)}
+ className={`px-2 py-1 ${touchBtnCls} text-xs text-gray-400 hover:text-white`}
+ >
+ Cancel
+ </button>
+ </div>
+ )}
+ </div>
+ </div>
<div className="space-y-2 max-h-64 overflow-auto">
{branches.map((branch) => (
<div
@@ -568,6 +600,12 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
<span className={`text-sm truncate ${branch.current ? 'text-port-accent font-medium' : 'text-gray-300'}`}>
{branch.name}
</span>
+ {branch.merged && (
+ <span className="flex items-center gap-1 text-xs text-port-success px-1.5 py-0.5 bg-port-success/10 rounded shrink-0">
+ <GitMerge size={10} />
+ merged
+ </span>
+ )}
{branch.tracking && (
<span className="text-xs text-gray-500 shrink-0">
{branch.ahead > 0 && <span className="text-port-success">+{branch.ahead}</span>}
@@ -670,7 +708,7 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
<div className="flex flex-wrap items-center gap-2">
{mergedBranchCount > 0 && !cleanupConfirm && (
<button
- onClick={() => setCleanupConfirm(true)}
+ onClick={() => setCleanupConfirm('remote')}
disabled={cleaningUp}
className={`flex items-center gap-1 text-xs ${touchBtnCls} text-port-warning hover:text-port-error disabled:opacity-50`}
>
@@ -678,7 +716,7 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
{cleaningUp ? 'Cleaning...' : `Clean ${mergedBranchCount} merged`}
</button>
)}
- {cleanupConfirm && (
+ {cleanupConfirm === 'remote' && (
<div className="flex flex-wrap items-center gap-1">
<button
onClick={handleCleanupMerged}
diff --git a/server/services/git.js b/server/services/git.js
index 467ef4dd86..07cf3786cf 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -595,15 +595,33 @@ export async function getRepoBranches(dir) {
*/
export async function getBranches(dir) {
// Get branches with verbose info (includes tracking)
- const result = await execGit(
- ['branch', '-vv', '--format=%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)'],
+ const [result, { baseBranch }] = await Promise.all([
+ execGit(
+ ['branch', '-vv', '--format=%(HEAD)|%(refname:short)|%(upstream:short)|%(upstream:track)'],
+ dir,
+ { ignoreExitCode: true }
+ ),
+ getRepoBranches(dir)
+ ]);
+
+ const defaultBranch = baseBranch || 'main';
+ const protectedSet = new Set(PROTECTED_BRANCHES);
+ protectedSet.add(defaultBranch);
+
+ const mergedResult = await execGit(
+ ['branch', '--merged', defaultBranch, '--format=%(refname:short)'],
dir,
{ ignoreExitCode: true }
);
+ const mergedSet = new Set(mergedResult.stdout.trim().split('\n').filter(Boolean));
- const branches = result.stdout.trim().split('\n').filter(Boolean).map(parseBranchVerboseLine);
-
- return branches;
+ return result.stdout.trim().split('\n').filter(Boolean)
+ .map(parseBranchVerboseLine)
+ .map(b => ({
+ ...b,
+ isDefault: b.name === defaultBranch,
+ merged: !b.current && !protectedSet.has(b.name) && mergedSet.has(b.name)
+ }));
}
/**