revert-ai 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/README.md +103 -0
- package/bin/revert-ai.js +589 -0
- package/index.js +4 -0
- package/package.json +74 -0
- package/src/core/AgentDetector.js +27 -0
- package/src/core/AgentParser.js +34 -0
- package/src/core/AiderSessionParser.js +143 -0
- package/src/core/ClaudeSessionParser.js +243 -0
- package/src/core/DependencyCascading.js +74 -0
- package/src/core/DependencyResolver.js +206 -0
- package/src/core/Operation.js +39 -0
- package/src/core/OperationPreview.js +176 -0
- package/src/core/RedoManager.js +270 -0
- package/src/core/SessionTracker.js +98 -0
- package/src/core/UndoManager.js +207 -0
- package/src/core/UndoTracker.js +72 -0
- package/src/hooks/claude-tracker.js +92 -0
- package/src/i18n/i18n.js +72 -0
- package/src/i18n/languages.js +471 -0
- package/src/utils/diffRenderer.js +112 -0
- package/src/utils/formatting.js +15 -0
- package/src/utils/gitHelper.js +66 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
|
|
3
|
+
export class GitHelper {
|
|
4
|
+
/**
|
|
5
|
+
* Check if the current directory is inside a Git repository.
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
8
|
+
static isGitRepository() {
|
|
9
|
+
try {
|
|
10
|
+
execSync('git rev-parse --is-inside-work-tree 2>/dev/null');
|
|
11
|
+
return true;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Check if there are any uncommitted changes (dirty index or working tree).
|
|
19
|
+
* @returns {boolean}
|
|
20
|
+
*/
|
|
21
|
+
static isWorkspaceDirty() {
|
|
22
|
+
if (!this.isGitRepository()) return false;
|
|
23
|
+
try {
|
|
24
|
+
const status = execSync('git status --porcelain', { encoding: 'utf8' }).trim();
|
|
25
|
+
return status.length > 0;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Save the current state of the workspace to a Git stash.
|
|
33
|
+
* @param {string} message
|
|
34
|
+
* @returns {boolean}
|
|
35
|
+
*/
|
|
36
|
+
static saveStash(message = 'revert-ai: Pre-undo backup') {
|
|
37
|
+
if (!this.isGitRepository()) return false;
|
|
38
|
+
try {
|
|
39
|
+
execSync(`git stash save "${message}"`, { stdio: 'inherit' });
|
|
40
|
+
return true;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error('Failed to create Git stash:', e.message);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Create a Git checkpoint commit.
|
|
49
|
+
* @param {string} message
|
|
50
|
+
* @returns {string|null} commit hash or null
|
|
51
|
+
*/
|
|
52
|
+
static createCheckpointCommit(message = 'revert-ai: Checkpoint before undo') {
|
|
53
|
+
if (!this.isGitRepository()) return null;
|
|
54
|
+
try {
|
|
55
|
+
// Stage all changes (created, modified, deleted)
|
|
56
|
+
execSync('git add -A');
|
|
57
|
+
// Commit without run hooks to be fast/safe
|
|
58
|
+
execSync(`git commit -m "${message}" --no-verify`, { stdio: 'ignore' });
|
|
59
|
+
const hash = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
|
|
60
|
+
return hash;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error('Failed to create Git checkpoint commit:', e.message);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|