Spaces:
Sleeping
Sleeping
File size: 1,998 Bytes
a5d1c1b 61b1da1 a5d1c1b 61b1da1 a5d1c1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import prompts from 'prompts';
import { projectConfigManager } from '../config/project-config.js';
import { cacheService } from '../services/cache-service.js';
import { syncService } from '../services/sync-service.js';
import { logger } from '../utils/logger.js';
import { outputResult, outputError, OutputOptions } from '../utils/output.js';
export interface ResetOptions extends OutputOptions {
yes?: boolean;
}
export async function handleReset(options: ResetOptions = {}): Promise<void> {
const workspaceRoot = projectConfigManager.findEvbRoot();
if (!workspaceRoot) {
return outputError(
'Not inside an Ever-Brain project. Run `evb init <repo>` first.',
'NOT_IN_WORKSPACE',
options
);
}
const dirty = cacheService.computeDirtyState(workspaceRoot);
if (!dirty.isDirty) {
outputResult({ status: 'clean', message: 'Working tree is already clean.' }, options, () => {
logger.info('Working tree is already clean. Nothing to reset.');
});
return;
}
if (!options.yes && process.stdout.isTTY) {
const totalCount = dirty.modified.length + dirty.added.length + dirty.deleted.length;
const response = await prompts({
type: 'confirm',
name: 'confirm',
message: `Discard all ${totalCount} uncommitted local modifications and reset to remote baseline?`,
initial: false,
});
if (!response.confirm) {
logger.info('Reset cancelled.');
return;
}
}
try {
// Re-sync with force=true to restore baseline
const syncRes = await syncService.sync(workspaceRoot, { force: true });
outputResult(
{
status: 'reset_complete',
filesRestored: syncRes.total,
},
options,
() => {
logger.success('Local modifications discarded. Reset to clean remote baseline complete.');
}
);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : String(err);
outputError(message, 'RESET_ERROR', options);
}
}
|