mirror of
https://github.com/siteboon/claudecodeui.git
synced 2025-12-13 05:39:41 +00:00
feat: auto-populate git config from system
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import express from 'express';
|
import express from 'express';
|
||||||
import { userDb } from '../database/db.js';
|
import { userDb } from '../database/db.js';
|
||||||
import { authenticateToken } from '../middleware/auth.js';
|
import { authenticateToken } from '../middleware/auth.js';
|
||||||
|
import { getSystemGitConfig } from '../utils/gitConfig.js';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
|
||||||
@@ -10,7 +11,19 @@ const router = express.Router();
|
|||||||
router.get('/git-config', authenticateToken, async (req, res) => {
|
router.get('/git-config', authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
const gitConfig = userDb.getGitConfig(userId);
|
let gitConfig = userDb.getGitConfig(userId);
|
||||||
|
|
||||||
|
// If database is empty, try to get from system git config
|
||||||
|
if (!gitConfig || (!gitConfig.git_name && !gitConfig.git_email)) {
|
||||||
|
const systemConfig = await getSystemGitConfig();
|
||||||
|
|
||||||
|
// If system has values, save them to database for this user
|
||||||
|
if (systemConfig.git_name || systemConfig.git_email) {
|
||||||
|
userDb.updateGitConfig(userId, systemConfig.git_name, systemConfig.git_email);
|
||||||
|
gitConfig = systemConfig;
|
||||||
|
console.log(`Auto-populated git config from system for user ${userId}: ${systemConfig.git_name} <${systemConfig.git_email}>`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
24
server/utils/gitConfig.js
Normal file
24
server/utils/gitConfig.js
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { exec } from 'child_process';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read git configuration from system's global git config
|
||||||
|
* @returns {Promise<{git_name: string|null, git_email: string|null}>}
|
||||||
|
*/
|
||||||
|
export async function getSystemGitConfig() {
|
||||||
|
try {
|
||||||
|
const [nameResult, emailResult] = await Promise.all([
|
||||||
|
execAsync('git config --global user.name').catch(() => ({ stdout: '' })),
|
||||||
|
execAsync('git config --global user.email').catch(() => ({ stdout: '' }))
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
git_name: nameResult.stdout.trim() || null,
|
||||||
|
git_email: emailResult.stdout.trim() || null
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return { git_name: null, git_email: null };
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user