feat: implement default Git identity management and local identity check
This commit is contained in:
@@ -605,6 +605,10 @@ const sanitizeSettingsUpdate = (payload) => {
|
||||
const trimmed = candidate.defaultAgent.trim();
|
||||
result.defaultAgent = trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
if (typeof candidate.defaultGitIdentityId === 'string') {
|
||||
const trimmed = candidate.defaultGitIdentityId.trim();
|
||||
result.defaultGitIdentityId = trimmed.length > 0 ? trimmed : undefined;
|
||||
}
|
||||
if (typeof candidate.queueModeEnabled === 'boolean') {
|
||||
result.queueModeEnabled = candidate.queueModeEnabled;
|
||||
}
|
||||
@@ -3366,6 +3370,22 @@ async function main(options = {}) {
|
||||
}
|
||||
});
|
||||
|
||||
app.get('/api/git/has-local-identity', async (req, res) => {
|
||||
const { hasLocalIdentity } = await getGitLibraries();
|
||||
try {
|
||||
const directory = req.query.directory;
|
||||
if (!directory) {
|
||||
return res.status(400).json({ error: 'directory parameter is required' });
|
||||
}
|
||||
|
||||
const hasLocal = await hasLocalIdentity(directory);
|
||||
res.json({ hasLocalIdentity: hasLocal });
|
||||
} catch (error) {
|
||||
console.error('Failed to check local git identity:', error);
|
||||
res.status(500).json({ error: 'Failed to check local git identity' });
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/git/set-identity', async (req, res) => {
|
||||
const { getProfile, setLocalIdentity, getGlobalIdentity } = await getGitLibraries();
|
||||
try {
|
||||
|
||||
@@ -160,6 +160,18 @@ export async function getCurrentIdentity(directory) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function hasLocalIdentity(directory) {
|
||||
const git = simpleGit(normalizeDirectoryPath(directory));
|
||||
|
||||
try {
|
||||
const localName = await git.getConfig('user.name', 'local').catch(() => null);
|
||||
const localEmail = await git.getConfig('user.email', 'local').catch(() => null);
|
||||
return Boolean(localName?.value || localEmail?.value);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function setLocalIdentity(directory, profile) {
|
||||
const git = simpleGit(normalizeDirectoryPath(directory));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user