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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat(git): add remote branches view with merge status and branch deletion
Adam Eivy18e1adf77c54
diff --git a/client/src/components/apps/tabs/GitTab.jsx b/client/src/components/apps/tabs/GitTab.jsxindex 1d920ff2d4..cbe1d0f68e 100644--- a/client/src/components/apps/tabs/GitTab.jsx+++ b/client/src/components/apps/tabs/GitTab.jsx@@ -1,5 +1,5 @@import { useState, useEffect, useCallback } from 'react';-import { GitBranch, Plus, Minus, FileText, RefreshCw, Download, Rocket, Upload, ArrowUpDown, Check } from 'lucide-react';+import { GitBranch, Plus, Minus, FileText, RefreshCw, Download, Rocket, Upload, ArrowUpDown, Check, Trash2, GitMerge, Globe } from 'lucide-react';import toast from 'react-hot-toast';import BrailleSpinner from '../../BrailleSpinner';import * as api from '../../../services/api';@@ -92,6 +92,11 @@ export default function GitTab({ appId, appName, repoPath }) {const [pushing, setPushing] = useState(null);const [syncing, setSyncing] = useState(null);const [pushingAll, setPushingAll] = useState(false);+ const [remoteBranches, setRemoteBranches] = useState([]);+ const [defaultBranch, setDefaultBranch] = useState('main');+ const [loadingRemote, setLoadingRemote] = useState(false);+ const [deleting, setDeleting] = useState(null);+ const [deleteConfirm, setDeleteConfirm] = useState(null);const loadGitInfo = useCallback(async () => {if (!repoPath) return;@@ -110,9 +115,21 @@ export default function GitTab({ appId, appName, repoPath }) {setLoading(false);}, [repoPath]);+ const loadRemoteBranches = useCallback(async () => {+ if (!repoPath) return;+ setLoadingRemote(true);+ const result = await api.getRemoteBranches(repoPath).catch(() => null);+ if (result) {+ setRemoteBranches(result.branches || []);+ setDefaultBranch(result.defaultBranch || 'main');+ }+ setLoadingRemote(false);+ }, [repoPath]);+useEffect(() => {loadGitInfo();- }, [loadGitInfo]);+ loadRemoteBranches();+ }, [loadGitInfo, loadRemoteBranches]);const loadDiff = async () => {if (!repoPath) return;@@ -234,6 +251,22 @@ export default function GitTab({ appId, appName, repoPath }) {await loadGitInfo();};+ const handleDeleteBranch = async (branchName, { local, remote }) => {+ if (!repoPath || deleting) return;+ setDeleting(branchName);+ setDeleteConfirm(null);+ const result = await api.deleteBranch(repoPath, branchName, { local, remote }).catch((err) => {+ toast.error(`Delete failed: ${err.message}`);+ return null;+ });+ setDeleting(null);+ if (result) {+ const parts = Object.entries(result.results || {}).map(([k, v]) => `${k}: ${v}`);+ toast.success(`Branch ${branchName} — ${parts.join(', ')}`);+ await Promise.all([loadGitInfo(), loadRemoteBranches()]);+ }+ };+const getStatusIcon = (file) => {if (file.added) return <Plus size={14} className="text-port-success" />;if (file.deleted) return <Minus size={14} className="text-port-error" />;@@ -508,6 +541,102 @@ export default function GitTab({ appId, appName, repoPath }) {</div></div></div>++ {/* Remote Branches */}+ <div className="bg-port-card border border-port-border rounded-xl p-4">+ <div className="flex items-center justify-between mb-3">+ <div className="flex items-center gap-2">+ <Globe size={16} className="text-gray-400" />+ <h3 className="text-sm font-medium text-gray-400">Remote Branches</h3>+ {remoteBranches.length > 0 && (+ <span className="text-xs text-gray-500">({remoteBranches.length})</span>+ )}+ </div>+ <button+ onClick={loadRemoteBranches}+ disabled={loadingRemote}+ className="text-xs text-port-accent hover:underline disabled:opacity-50"+ >+ {loadingRemote ? 'Refreshing...' : 'Refresh'}+ </button>+ </div>+ {loadingRemote && remoteBranches.length === 0 ? (+ <div className="text-center py-4"><BrailleSpinner text="Loading remote branches" /></div>+ ) : (+ <div className="space-y-1.5 max-h-80 overflow-auto">+ {remoteBranches.map((rb) => (+ <div+ key={rb.fullRef}+ className={`flex items-center justify-between py-2 px-2 rounded-lg hover:bg-port-bg ${rb.isDefault ? 'bg-port-accent/5' : ''}`}+ >+ <div className="flex items-center gap-2 min-w-0 flex-1">+ <GitBranch size={14} className={rb.isDefault ? 'text-port-accent shrink-0' : 'text-gray-500 shrink-0'} />+ <span className={`text-sm truncate ${rb.isDefault ? 'text-port-accent font-medium' : 'text-gray-300'}`}>+ {rb.name}+ </span>+ {rb.merged && !rb.isDefault && (+ <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>+ )}+ {rb.hasLocal && (+ <span className="text-xs text-gray-500 shrink-0">local</span>+ )}+ </div>+ <div className="flex items-center gap-2 shrink-0">+ {rb.lastCommitDate && (+ <span className="text-xs text-gray-500">+ {new Date(rb.lastCommitDate).toLocaleDateString()}+ </span>+ )}+ {!rb.isDefault && (+ <>+ {deleteConfirm === rb.name ? (+ <div className="flex items-center gap-1">+ <button+ onClick={() => handleDeleteBranch(rb.name, { local: rb.hasLocal, remote: true })}+ disabled={deleting === rb.name}+ className="px-2 py-1 text-xs bg-port-error/20 text-port-error rounded hover:bg-port-error/30 disabled:opacity-50"+ >+ {deleting === rb.name ? 'Deleting...' : rb.hasLocal ? 'Delete both' : 'Delete remote'}+ </button>+ {rb.hasLocal && (+ <button+ onClick={() => handleDeleteBranch(rb.name, { local: false, remote: true })}+ disabled={deleting === rb.name}+ className="px-2 py-1 text-xs bg-port-warning/20 text-port-warning rounded hover:bg-port-warning/30 disabled:opacity-50"+ >+ Remote only+ </button>+ )}+ <button+ onClick={() => setDeleteConfirm(null)}+ className="px-2 py-1 text-xs text-gray-400 hover:text-white"+ >+ Cancel+ </button>+ </div>+ ) : (+ <button+ onClick={() => setDeleteConfirm(rb.name)}+ className="p-1.5 text-gray-500 hover:text-port-error hover:bg-port-bg rounded"+ title="Delete branch"+ >+ <Trash2 size={14} />+ </button>+ )}+ </>+ )}+ </div>+ </div>+ ))}+ {remoteBranches.length === 0 && !loadingRemote && (+ <div className="text-gray-500 text-sm">No remote branches found</div>+ )}+ </div>+ )}+ </div></div>) : (<div className="bg-port-card border border-port-border rounded-xl p-8 text-center text-gray-500">diff --git a/client/src/services/api.js b/client/src/services/api.jsindex 2284c79394..2d1a2bd09d 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -349,6 +349,15 @@ export const syncBranch = (path, branch) => request('/git/sync', {method: 'POST',body: JSON.stringify({ path, branch })});+export const getRemoteBranches = (path) => request('/git/remote-branches', {+ method: 'POST',+ body: JSON.stringify({ path })+});+export const deleteBranch = (path, branch, { local = false, remote = false } = {}) =>+ request('/git/delete-branch', {+ method: 'POST',+ body: JSON.stringify({ path, branch, local, remote })+ });// Usageexport const getUsage = () => request('/usage');diff --git a/server/routes/git.js b/server/routes/git.jsindex e3b0148a40..d1791853d3 100644--- a/server/routes/git.js+++ b/server/routes/git.js@@ -199,4 +199,32 @@ router.post('/sync', asyncHandler(async (req, res) => {res.json(result);}));+// POST /api/git/remote-branches - Get remote branches with merge status+router.post('/remote-branches', asyncHandler(async (req, res) => {+ const { path } = req.body;++ if (!path) {+ throw new ServerError('path is required', { status: 400, code: 'VALIDATION_ERROR' });+ }++ const result = await git.getRemoteBranches(path);+ res.json(result);+}));++// POST /api/git/delete-branch - Delete a branch locally and/or remotely+router.post('/delete-branch', asyncHandler(async (req, res) => {+ const { path, branch, local, remote } = req.body;++ if (!path || !branch) {+ throw new ServerError('path and branch are required', { status: 400, code: 'VALIDATION_ERROR' });+ }++ if (!local && !remote) {+ throw new ServerError('at least one of local or remote must be true', { status: 400, code: 'VALIDATION_ERROR' });+ }++ const result = await git.deleteBranch(path, branch, { local, remote });+ res.json(result);+}));+export default router;diff --git a/server/services/git.js b/server/services/git.jsindex 421ef36716..17025af90d 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -584,6 +584,104 @@ export async function ensureLatest(dir) {return { success: true, branch: currentBranch, stashed, conflict: false, error: null };}+/**+ * Get remote branches with merge status relative to the default branch.+ * Returns branches that exist on origin, indicating whether each has been+ * fully merged into the default branch and whether a local copy exists.+ */+export async function getRemoteBranches(dir) {+ // Fetch latest refs+ await execGit(['fetch', 'origin', '--prune'], dir, { ignoreExitCode: true });++ // Detect default branch+ const { baseBranch } = await getRepoBranches(dir);+ const defaultBranch = baseBranch || 'main';++ // Get all remote branches+ const result = await execGit(+ ['branch', '-r', '--format=%(refname:short)|%(committerdate:iso8601)|%(authorname)'],+ dir,+ { ignoreExitCode: true }+ );++ // Get merged remote branches relative to default branch+ const mergedResult = await execGit(+ ['branch', '-r', '--merged', defaultBranch, '--format=%(refname:short)'],+ dir,+ { ignoreExitCode: true }+ );+ const mergedSet = new Set(mergedResult.stdout.trim().split('\n').filter(Boolean));++ // Get local branches for cross-reference+ const localResult = await execGit(['branch', '--format=%(refname:short)'], dir, { ignoreExitCode: true });+ const localSet = new Set(localResult.stdout.trim().split('\n').filter(Boolean));++ const remoteBranches = result.stdout.trim().split('\n').filter(Boolean)+ .map(line => {+ const [fullRef, date, author] = line.split('|');+ // Strip "origin/" prefix+ const name = fullRef.replace(/^origin\//, '');+ // Skip HEAD pointer+ if (name === 'HEAD' || fullRef.includes('HEAD')) return null;+ return {+ name,+ fullRef,+ merged: mergedSet.has(fullRef),+ hasLocal: localSet.has(name),+ lastCommitDate: date?.trim() || null,+ author: author?.trim() || null,+ isDefault: name === defaultBranch+ };+ })+ .filter(Boolean);++ return { branches: remoteBranches, defaultBranch };+}++/**+ * Delete a branch locally, remotely, or both.+ * @param {string} dir - Working directory+ * @param {string} branchName - Branch name to delete+ * @param {object} options+ * @param {boolean} options.local - Delete local branch+ * @param {boolean} options.remote - Delete remote branch+ */+export async function deleteBranch(dir, branchName, { local = false, remote = false } = {}) {+ // Safety: never delete default branches+ const { baseBranch } = await getRepoBranches(dir);+ const protectedBranches = ['main', 'master', 'dev', 'develop', 'release'];+ if (baseBranch) protectedBranches.push(baseBranch);+ if (protectedBranches.includes(branchName)) {+ throw new Error(`Cannot delete protected branch: ${branchName}`);+ }++ // Safety: don't delete the current branch+ const currentBranch = await getBranch(dir);+ if (currentBranch === branchName && local) {+ throw new Error(`Cannot delete the currently checked-out branch: ${branchName}`);+ }++ const results = {};++ if (local) {+ const localResult = await execGit(['branch', '-D', branchName], dir, { ignoreExitCode: true });+ results.local = localResult.exitCode === 0+ ? 'deleted'+ : localResult.stderr?.includes('not found') ? 'not found' : `failed: ${localResult.stderr?.trim()}`;+ }++ if (remote) {+ const remoteResult = await execGit(['push', 'origin', '--delete', branchName], dir, { ignoreExitCode: true });+ results.remote = remoteResult.exitCode === 0+ ? 'deleted'+ : remoteResult.stderr?.includes('not found') || remoteResult.stderr?.includes('does not exist')+ ? 'not found'+ : `failed: ${remoteResult.stderr?.trim()}`;+ }++ return { branch: branchName, results };+}+/*** Get comprehensive git info*/