easegit-cli 1.0.5 → 1.0.7

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.
@@ -51,16 +51,19 @@ const path = __importStar(require("path"));
51
51
  * Execute a Git command and return output
52
52
  */
53
53
  function gitExec(args, cwd) {
54
- try {
55
- return (0, child_process_1.execSync)(`git ${args.join(' ')}`, {
56
- cwd: cwd || process.cwd(),
57
- encoding: 'utf8',
58
- stdio: ['pipe', 'pipe', 'pipe']
59
- }).trim();
60
- }
61
- catch (error) {
62
- throw new Error(`Git command failed: ${error.message}`);
63
- }
54
+ const result = (0, child_process_1.spawnSync)('git', args, {
55
+ cwd: cwd || process.cwd(),
56
+ encoding: 'utf8',
57
+ stdio: ['pipe', 'pipe', 'pipe']
58
+ });
59
+ if (result.error) {
60
+ throw new Error(`Git command failed: ${result.error.message}`);
61
+ }
62
+ if (result.status !== 0) {
63
+ const stderr = result.stderr ? result.stderr.toString().trim() : '';
64
+ throw new Error(`Git command failed: ${stderr || 'Unknown error'}`);
65
+ }
66
+ return (result.stdout || '').toString().trim();
64
67
  }
65
68
  /**
66
69
  * Check if current directory is a Git repository
@@ -123,9 +126,8 @@ function createCheckpointRef(treeSha, operation) {
123
126
  const timestamp = Date.now();
124
127
  const refName = `refs/easegit/checkpoints/${timestamp}`;
125
128
  // Create a commit object for the checkpoint
126
- const message = `EaseGit checkpoint before ${operation}\nTimestamp: ${timestamp}`;
127
- // Use current HEAD as parent if it exists
128
- const commitArgs = ['commit-tree', treeSha, '-m', message];
129
+ // Use multiple -m flags for multi-line messages (Windows compatible)
130
+ const commitArgs = ['commit-tree', treeSha, '-m', `EaseGit checkpoint before ${operation}`, '-m', `Timestamp: ${timestamp}`];
129
131
  try {
130
132
  const head = gitExec(['rev-parse', 'HEAD']);
131
133
  commitArgs.splice(2, 0, '-p', head);
@@ -178,12 +180,14 @@ function getCheckpointInfo(refName) {
178
180
  function restoreFromTree(commitSha) {
179
181
  // Get the tree from the commit
180
182
  const treeSha = gitExec(['rev-parse', `${commitSha}^{tree}`]);
183
+ // Clear working directory first (except .git)
184
+ gitExec(['clean', '-fd']);
181
185
  // Read the tree into index
182
186
  gitExec(['read-tree', treeSha]);
183
187
  // Checkout all files from index into working directory
184
188
  gitExec(['checkout-index', '-f', '-a']);
185
- // Clean up any files that existed in the old checkpoint but not the new one
186
- gitExec(['clean', '-fd']);
189
+ // Reset the index to match the restored tree so git status shows clean
190
+ gitExec(['reset', '--mixed']);
187
191
  }
188
192
  /**
189
193
  * Check if there are merge conflicts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easegit-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Automatic checkpoints before Git can hurt you",
5
5
  "main": "dist/index.js",
6
6
  "bin": {