easegit-cli 1.0.4 → 1.0.6

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.
@@ -36,7 +36,7 @@ export declare function getCheckpointInfo(refName: string): {
36
36
  commitSha: string;
37
37
  } | null;
38
38
  /**
39
- * Restore working directory from a tree SHA
39
+ * Restore working directory from a commit SHA (restores all files including untracked)
40
40
  */
41
41
  export declare function restoreFromTree(commitSha: string): void;
42
42
  /**
@@ -123,9 +123,8 @@ function createCheckpointRef(treeSha, operation) {
123
123
  const timestamp = Date.now();
124
124
  const refName = `refs/easegit/checkpoints/${timestamp}`;
125
125
  // 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];
126
+ // Use multiple -m flags for multi-line messages (Windows compatible)
127
+ const commitArgs = ['commit-tree', treeSha, '-m', `EaseGit checkpoint before ${operation}`, '-m', `Timestamp: ${timestamp}`];
129
128
  try {
130
129
  const head = gitExec(['rev-parse', 'HEAD']);
131
130
  commitArgs.splice(2, 0, '-p', head);
@@ -143,7 +142,8 @@ function createCheckpointRef(treeSha, operation) {
143
142
  */
144
143
  function getLatestCheckpointRef() {
145
144
  try {
146
- const refs = gitExec(['for-each-ref', 'refs/easegit/checkpoints/', '--sort=-refname', '--format=%(refname)', '--count=1']);
145
+ // Use -version:refname to sort refs numerically by the timestamp in the refname
146
+ const refs = gitExec(['for-each-ref', 'refs/easegit/checkpoints/', '--sort=-version:refname', '--format=%(refname)', '--count=1']);
147
147
  return refs || null;
148
148
  }
149
149
  catch {
@@ -172,14 +172,19 @@ function getCheckpointInfo(refName) {
172
172
  }
173
173
  }
174
174
  /**
175
- * Restore working directory from a tree SHA
175
+ * Restore working directory from a commit SHA (restores all files including untracked)
176
176
  */
177
177
  function restoreFromTree(commitSha) {
178
- const repoRoot = getRepoRoot();
179
- // Clear working directory (except .git)
178
+ // Get the tree from the commit
179
+ const treeSha = gitExec(['rev-parse', `${commitSha}^{tree}`]);
180
+ // Clear working directory first (except .git)
180
181
  gitExec(['clean', '-fd']);
181
- // Checkout the tree without moving HEAD
182
- gitExec(['checkout', commitSha, '--', '.']);
182
+ // Read the tree into index
183
+ gitExec(['read-tree', treeSha]);
184
+ // Checkout all files from index into working directory
185
+ gitExec(['checkout-index', '-f', '-a']);
186
+ // Reset the index to match the restored tree so git status shows clean
187
+ gitExec(['reset', '--mixed']);
183
188
  }
184
189
  /**
185
190
  * 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.4",
3
+ "version": "1.0.6",
4
4
  "description": "Automatic checkpoints before Git can hurt you",
5
5
  "main": "dist/index.js",
6
6
  "bin": {