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 local branch management to git status page

Adam Eivy208fe422464e
diff --git a/client/src/pages/DevTools.jsx b/client/src/pages/DevTools.jsx
index 085c067271..815b24b48b 100644
--- a/client/src/pages/DevTools.jsx
+++ b/client/src/pages/DevTools.jsx
@@ -1,6 +1,6 @@
import { useState, useEffect, useRef, Fragment } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
-import { GitBranch, Plus, Minus, FileText, Clock, RefreshCw, Activity, Image, X, XCircle, Cpu, MemoryStick, Terminal, Trash2, MessageSquarePlus, Info, Save, Maximize2, RotateCcw, Download, Rocket } from 'lucide-react';
+import { GitBranch, Plus, Minus, FileText, Clock, RefreshCw, Activity, Image, X, XCircle, Cpu, MemoryStick, Terminal, Trash2, MessageSquarePlus, Info, Save, Maximize2, RotateCcw, Download, Rocket, Upload, ArrowUpDown, Check } from 'lucide-react';
import toast from 'react-hot-toast';
import * as api from '../services/api';
import socket from '../services/socket';
@@ -1762,6 +1762,10 @@ export function GitPage() {
const [updating, setUpdating] = useState(false);
const [releasing, setReleasing] = useState(false);
const [showReleaseConfirm, setShowReleaseConfirm] = useState(false);
+ const [branches, setBranches] = useState([]);
+ const [checkingOut, setCheckingOut] = useState(null);
+ const [pushing, setPushing] = useState(null);
+ const [syncing, setSyncing] = useState(null);
const selectedApp = apps.find(a => a.id === selectedAppId);
const repoPath = selectedApp?.repoPath || '';
@@ -1784,12 +1788,16 @@ export function GitPage() {
const loadGitInfo = async () => {
if (!repoPath) return;
setLoading(true);
- const info = await api.getGitInfo(repoPath).catch(() => null);
+ const [info, branchesResult] = await Promise.all([
+ api.getGitInfo(repoPath).catch(() => null),
+ api.getBranches(repoPath).catch(() => ({ branches: [] }))
+ ]);
let comparison = null;
if (info?.baseBranch && info?.devBranch) {
comparison = await api.getBranchComparison(repoPath, info.baseBranch, info.devBranch).catch(() => null);
}
setGitInfo(info);
+ setBranches(branchesResult.branches || []);
setBranchComparison(comparison);
setLoading(false);
};
@@ -1864,6 +1872,41 @@ export function GitPage() {
}
};
+ const handleCheckout = async (branchName) => {
+ if (!repoPath || checkingOut) return;
+ setCheckingOut(branchName);
+ const result = await api.checkoutBranch(repoPath, branchName).catch(() => null);
+ setCheckingOut(null);
+ if (result?.success) {
+ toast.success(`Switched to ${branchName}`);
+ await loadGitInfo();
+ }
+ };
+
+ const handlePush = async (branchName) => {
+ if (!repoPath || pushing) return;
+ setPushing(branchName);
+ const result = await api.pushBranch(repoPath, branchName).catch(() => null);
+ setPushing(null);
+ if (result?.success) {
+ toast.success(`Pushed ${branchName}`);
+ await loadGitInfo();
+ }
+ };
+
+ const handleSync = async (branchName) => {
+ if (!repoPath || syncing) return;
+ setSyncing(branchName);
+ const result = await api.syncBranch(repoPath, branchName).catch(() => null);
+ setSyncing(null);
+ if (result?.success) {
+ toast.success(`Synced ${branchName}`);
+ await loadGitInfo();
+ } else if (result?.error) {
+ toast.error(`Sync failed: ${result.error}`);
+ }
+ };
+
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" />;
@@ -2035,23 +2078,103 @@ export function GitPage() {
</div>
{/* Recent Commits */}
- <div className="bg-port-card border border-port-border rounded-xl p-4">
- <h3 className="text-sm font-medium text-gray-400 mb-3">Recent Commits</h3>
- <div className="space-y-2">
- {gitInfo.recentCommits?.map((commit, i) => (
- <div key={i} className="py-2 border-b border-port-border last:border-0">
- <div className="flex items-center gap-2">
- <code className="text-xs text-port-accent">{commit.hash}</code>
- <span className="text-sm text-white truncate">{commit.message}</span>
+ <div className="space-y-4">
+ <div className="bg-port-card border border-port-border rounded-xl p-4">
+ <h3 className="text-sm font-medium text-gray-400 mb-3">Recent Commits</h3>
+ <div className="space-y-2">
+ {gitInfo.recentCommits?.map((commit, i) => (
+ <div key={i} className="py-2 border-b border-port-border last:border-0">
+ <div className="flex items-center gap-2">
+ <code className="text-xs text-port-accent">{commit.hash}</code>
+ <span className="text-sm text-white truncate">{commit.message}</span>
+ </div>
+ <div className="text-xs text-gray-500 mt-1">
+ {commit.author} • {new Date(commit.date).toLocaleDateString()}
+ </div>
</div>
- <div className="text-xs text-gray-500 mt-1">
- {commit.author} • {new Date(commit.date).toLocaleDateString()}
+ ))}
+ {(!gitInfo.recentCommits || gitInfo.recentCommits.length === 0) && (
+ <div className="text-gray-500 text-sm">No commits</div>
+ )}
+ </div>
+ </div>
+
+ {/* 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="space-y-2 max-h-64 overflow-auto">
+ {branches.map((branch) => (
+ <div
+ key={branch.name}
+ className={`flex items-center justify-between py-2 px-2 rounded-lg ${branch.current ? 'bg-port-accent/10 border border-port-accent/30' : 'hover:bg-port-bg'}`}
+ >
+ <div className="flex items-center gap-2 min-w-0 flex-1">
+ {branch.current ? (
+ <Check size={14} className="text-port-accent shrink-0" />
+ ) : (
+ <GitBranch size={14} className="text-gray-500 shrink-0" />
+ )}
+ <span className={`text-sm truncate ${branch.current ? 'text-port-accent font-medium' : 'text-gray-300'}`}>
+ {branch.name}
+ </span>
+ {branch.tracking && (
+ <span className="text-xs text-gray-500 shrink-0">
+ {branch.ahead > 0 && <span className="text-port-success">+{branch.ahead}</span>}
+ {branch.ahead > 0 && branch.behind > 0 && ' / '}
+ {branch.behind > 0 && <span className="text-port-warning">-{branch.behind}</span>}
+ </span>
+ )}
+ </div>
+ <div className="flex items-center gap-1 shrink-0">
+ {!branch.current && (
+ <button
+ onClick={() => handleCheckout(branch.name)}
+ disabled={checkingOut === branch.name}
+ className="p-1.5 text-gray-400 hover:text-white hover:bg-port-bg rounded disabled:opacity-50"
+ title="Checkout"
+ >
+ {checkingOut === branch.name ? (
+ <RefreshCw size={14} className="animate-spin" />
+ ) : (
+ <Check size={14} />
+ )}
+ </button>
+ )}
+ {branch.tracking && branch.ahead > 0 && (
+ <button
+ onClick={() => handlePush(branch.name)}
+ disabled={pushing === branch.name}
+ className="p-1.5 text-gray-400 hover:text-port-success hover:bg-port-bg rounded disabled:opacity-50"
+ title="Push"
+ >
+ {pushing === branch.name ? (
+ <RefreshCw size={14} className="animate-spin" />
+ ) : (
+ <Upload size={14} />
+ )}
+ </button>
+ )}
+ {branch.tracking && (
+ <button
+ onClick={() => handleSync(branch.name)}
+ disabled={syncing === branch.name}
+ className="p-1.5 text-gray-400 hover:text-port-accent hover:bg-port-bg rounded disabled:opacity-50"
+ title="Sync (pull & push)"
+ >
+ {syncing === branch.name ? (
+ <RefreshCw size={14} className="animate-spin" />
+ ) : (
+ <ArrowUpDown size={14} />
+ )}
+ </button>
+ )}
+ </div>
</div>
- </div>
- ))}
- {(!gitInfo.recentCommits || gitInfo.recentCommits.length === 0) && (
- <div className="text-gray-500 text-sm">No commits</div>
- )}
+ ))}
+ {branches.length === 0 && (
+ <div className="text-gray-500 text-sm">No branches found</div>
+ )}
+ </div>
</div>
</div>
</div>
diff --git a/client/src/services/api.js b/client/src/services/api.js
index 517befec19..8e7aeb3c47 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -232,6 +232,22 @@ export const pushBranch = (path, branch) => request('/git/push', {
method: 'POST',
body: JSON.stringify({ path, branch })
});
+export const getBranches = (path) => request('/git/branches', {
+ method: 'POST',
+ body: JSON.stringify({ path })
+});
+export const checkoutBranch = (path, branch) => request('/git/checkout', {
+ method: 'POST',
+ body: JSON.stringify({ path, branch })
+});
+export const pullBranch = (path) => request('/git/pull', {
+ method: 'POST',
+ body: JSON.stringify({ path })
+});
+export const syncBranch = (path, branch) => request('/git/sync', {
+ method: 'POST',
+ body: JSON.stringify({ path, branch })
+});
// Usage
export const getUsage = () => request('/usage');
diff --git a/server/routes/git.js b/server/routes/git.js
index d6cbb7cdf4..a042ec0a41 100644
--- a/server/routes/git.js
+++ b/server/routes/git.js
@@ -140,4 +140,52 @@ router.post('/info', asyncHandler(async (req, res) => {
res.json(info);
}));
+// POST /api/git/branches - Get all local branches
+router.post('/branches', asyncHandler(async (req, res) => {
+ const { path } = req.body;
+
+ if (!path) {
+ throw new ServerError('path is required', { status: 400, code: 'VALIDATION_ERROR' });
+ }
+
+ const branches = await git.getBranches(path);
+ res.json({ branches });
+}));
+
+// POST /api/git/checkout - Switch to a branch
+router.post('/checkout', asyncHandler(async (req, res) => {
+ const { path, branch } = req.body;
+
+ if (!path || !branch) {
+ throw new ServerError('path and branch are required', { status: 400, code: 'VALIDATION_ERROR' });
+ }
+
+ const result = await git.checkout(path, branch);
+ res.json(result);
+}));
+
+// POST /api/git/pull - Pull changes from remote
+router.post('/pull', 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.pull(path);
+ res.json(result);
+}));
+
+// POST /api/git/sync - Sync branch (pull then push)
+router.post('/sync', asyncHandler(async (req, res) => {
+ const { path, branch } = req.body;
+
+ if (!path) {
+ throw new ServerError('path is required', { status: 400, code: 'VALIDATION_ERROR' });
+ }
+
+ const result = await git.syncBranch(path, branch);
+ res.json(result);
+}));
+
export default router;
diff --git a/server/services/git.js b/server/services/git.js
index ac06251b7c..39c0fb095f 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -377,6 +377,75 @@ export async function getRepoBranches(dir) {
};
}
+/**
+ * Get all local branches with tracking info
+ * @returns {Promise<Array<{name: string, current: boolean, tracking: string|null, ahead: number, behind: number}>>}
+ */
+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)'],
+ dir,
+ { ignoreExitCode: true }
+ );
+
+ const branches = result.stdout.trim().split('\n').filter(Boolean).map(line => {
+ const [head, name, upstream, track] = line.split('|');
+ const aheadMatch = track?.match(/ahead (\d+)/);
+ const behindMatch = track?.match(/behind (\d+)/);
+
+ return {
+ name,
+ current: head === '*',
+ tracking: upstream || null,
+ ahead: aheadMatch ? parseInt(aheadMatch[1], 10) : 0,
+ behind: behindMatch ? parseInt(behindMatch[1], 10) : 0
+ };
+ });
+
+ return branches;
+}
+
+/**
+ * Pull changes from remote for current branch
+ */
+export async function pull(dir) {
+ const result = await execGit(['pull', '--rebase', '--autostash'], dir);
+ return { success: true, output: result.stdout + result.stderr };
+}
+
+/**
+ * Sync branch - pull then push
+ */
+export async function syncBranch(dir, branch = null) {
+ const currentBranch = branch || await getBranch(dir);
+
+ // First pull with rebase
+ const pullResult = await execGit(['pull', '--rebase', '--autostash', 'origin', currentBranch], dir, { ignoreExitCode: true });
+ const pullSuccess = !pullResult.stderr?.includes('fatal') && !pullResult.stderr?.includes('CONFLICT');
+
+ if (!pullSuccess) {
+ return {
+ success: false,
+ error: pullResult.stderr || 'Pull failed',
+ pulled: false,
+ pushed: false
+ };
+ }
+
+ // Then push
+ const pushResult = await execGit(['push', 'origin', currentBranch], dir, { ignoreExitCode: true });
+ const pushSuccess = !pushResult.stderr?.includes('rejected') && !pushResult.stderr?.includes('fatal');
+
+ return {
+ success: pushSuccess,
+ pulled: true,
+ pushed: pushSuccess,
+ output: pullResult.stdout + pushResult.stdout,
+ error: pushSuccess ? null : pushResult.stderr
+ };
+}
+
/**
* Check if a .changelog/ directory exists in the repo
*/