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(git): add merge buttons for local branches and checkout for remote branches

Adam Eivyeae9122007f1
diff --git a/client/src/components/apps/tabs/GitTab.jsx b/client/src/components/apps/tabs/GitTab.jsx
index 1d520979ff..bd1dc286bb 100644
--- a/client/src/components/apps/tabs/GitTab.jsx
+++ b/client/src/components/apps/tabs/GitTab.jsx
@@ -97,6 +97,9 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
const [loadingRemote, setLoadingRemote] = useState(false);
const [deleting, setDeleting] = useState(null);
const [deleteConfirm, setDeleteConfirm] = useState(null);
+ const [merging, setMerging] = useState(null);
+ const [mergeConfirm, setMergeConfirm] = useState(null);
+ const [checkingOutRemote, setCheckingOutRemote] = useState(null);
const loadGitInfo = useCallback(async () => {
if (!repoPath) return;
@@ -287,6 +290,38 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
}
};
+ const handleMerge = async (branchName) => {
+ if (!repoPath || merging) return;
+ setMerging(branchName);
+ setMergeConfirm(null);
+ const result = await api.mergeBranch(repoPath, branchName).catch((err) => {
+ toast.error(`Merge failed: ${err.message}`);
+ return null;
+ });
+ setMerging(null);
+ if (result?.success) {
+ toast.success(`Merged ${branchName} into current branch`);
+ await loadGitInfo();
+ }
+ };
+
+ const handleCheckoutRemote = async (branchName) => {
+ if (!repoPath || checkingOutRemote) return;
+ setCheckingOutRemote(branchName);
+ const result = await api.checkoutRemoteBranch(repoPath, branchName).catch((err) => {
+ toast.error(`Checkout failed: ${err.message}`);
+ return null;
+ });
+ setCheckingOutRemote(null);
+ if (result?.success) {
+ toast.success(`Checked out ${branchName}`);
+ setRemoteBranches(prev => prev.map(b =>
+ b.name === branchName ? { ...b, hasLocal: true } : b
+ ));
+ await loadGitInfo();
+ }
+ };
+
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" />;
@@ -551,6 +586,33 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
)}
</button>
)}
+ {!branch.current && (
+ mergeConfirm === branch.name ? (
+ <div className="flex items-center gap-1">
+ <button
+ onClick={() => handleMerge(branch.name)}
+ disabled={merging === branch.name}
+ className="px-2 py-1 text-xs bg-port-accent/20 text-port-accent rounded hover:bg-port-accent/30 disabled:opacity-50"
+ >
+ {merging === branch.name ? 'Merging...' : 'Confirm'}
+ </button>
+ <button
+ onClick={() => setMergeConfirm(null)}
+ className="px-2 py-1 text-xs text-gray-400 hover:text-white"
+ >
+ Cancel
+ </button>
+ </div>
+ ) : (
+ <button
+ onClick={() => setMergeConfirm(branch.name)}
+ className="p-1.5 text-gray-400 hover:text-port-accent hover:bg-port-bg rounded"
+ title={`Merge ${branch.name} into current branch`}
+ >
+ <GitMerge size={14} />
+ </button>
+ )
+ )}
</div>
</div>
))}
@@ -610,6 +672,20 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {
{new Date(rb.lastCommitDate).toLocaleDateString()}
</span>
)}
+ {!rb.hasLocal && (
+ <button
+ onClick={() => handleCheckoutRemote(rb.name)}
+ disabled={checkingOutRemote === rb.name}
+ className="p-1.5 text-gray-400 hover:text-port-success hover:bg-port-bg rounded disabled:opacity-50"
+ title="Checkout locally"
+ >
+ {checkingOutRemote === rb.name ? (
+ <RefreshCw size={14} className="animate-spin" />
+ ) : (
+ <Download size={14} />
+ )}
+ </button>
+ )}
{!rb.isDefault && (
<>
{deleteConfirm === rb.name ? (
diff --git a/client/src/services/api.js b/client/src/services/api.js
index 5d2046206b..735bb06a4b 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -359,6 +359,14 @@ export const deleteBranch = (path, branch, { local = false, remote = false } = {
method: 'POST',
body: JSON.stringify({ path, branch, local, remote })
});
+export const mergeBranch = (path, branch) => request('/git/merge', {
+ method: 'POST',
+ body: JSON.stringify({ path, branch })
+});
+export const checkoutRemoteBranch = (path, branch) => request('/git/checkout-remote', {
+ 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 d1791853d3..b1d5d52c06 100644
--- a/server/routes/git.js
+++ b/server/routes/git.js
@@ -211,6 +211,30 @@ router.post('/remote-branches', asyncHandler(async (req, res) => {
res.json(result);
}));
+// POST /api/git/merge - Merge a branch into the current branch
+router.post('/merge', 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.mergeBranch(path, branch);
+ res.json(result);
+}));
+
+// POST /api/git/checkout-remote - Checkout a remote branch locally
+router.post('/checkout-remote', 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.checkoutRemoteBranch(path, branch);
+ 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;
diff --git a/server/services/git.js b/server/services/git.js
index 9e454eb753..8f97a32780 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -696,6 +696,30 @@ export async function deleteBranch(dir, branchName, { local = false, remote = fa
return { branch: branchName, results };
}
+/**
+ * Merge a branch into the current branch.
+ * Uses --no-ff to always create a merge commit for traceability.
+ * @param {string} dir - Working directory
+ * @param {string} branchName - Branch to merge into current
+ * @returns {Promise<{success: boolean, output: string}>}
+ */
+export async function mergeBranch(dir, branchName) {
+ const result = await execGit(['merge', '--no-ff', branchName], dir);
+ return { success: true, output: (result.stdout + result.stderr).trim() };
+}
+
+/**
+ * Checkout a remote branch that doesn't exist locally.
+ * Creates a local tracking branch from the remote ref.
+ * @param {string} dir - Working directory
+ * @param {string} branchName - Branch name (without origin/ prefix)
+ * @returns {Promise<{success: boolean, branch: string}>}
+ */
+export async function checkoutRemoteBranch(dir, branchName) {
+ await execGit(['checkout', '-b', branchName, `origin/${branchName}`], dir);
+ return { success: true, branch: branchName };
+}
+
/**
* Get comprehensive git info
*/