easegit-cli 1.0.4 → 1.0.5

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
  /**
@@ -143,7 +143,8 @@ function createCheckpointRef(treeSha, operation) {
143
143
  */
144
144
  function getLatestCheckpointRef() {
145
145
  try {
146
- const refs = gitExec(['for-each-ref', 'refs/easegit/checkpoints/', '--sort=-refname', '--format=%(refname)', '--count=1']);
146
+ // Use -version:refname to sort refs numerically by the timestamp in the refname
147
+ const refs = gitExec(['for-each-ref', 'refs/easegit/checkpoints/', '--sort=-version:refname', '--format=%(refname)', '--count=1']);
147
148
  return refs || null;
148
149
  }
149
150
  catch {
@@ -172,14 +173,17 @@ function getCheckpointInfo(refName) {
172
173
  }
173
174
  }
174
175
  /**
175
- * Restore working directory from a tree SHA
176
+ * Restore working directory from a commit SHA (restores all files including untracked)
176
177
  */
177
178
  function restoreFromTree(commitSha) {
178
- const repoRoot = getRepoRoot();
179
- // Clear working directory (except .git)
179
+ // Get the tree from the commit
180
+ const treeSha = gitExec(['rev-parse', `${commitSha}^{tree}`]);
181
+ // Read the tree into index
182
+ gitExec(['read-tree', treeSha]);
183
+ // Checkout all files from index into working directory
184
+ gitExec(['checkout-index', '-f', '-a']);
185
+ // Clean up any files that existed in the old checkpoint but not the new one
180
186
  gitExec(['clean', '-fd']);
181
- // Checkout the tree without moving HEAD
182
- gitExec(['checkout', commitSha, '--', '.']);
183
187
  }
184
188
  /**
185
189
  * 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.5",
4
4
  "description": "Automatic checkpoints before Git can hurt you",
5
5
  "main": "dist/index.js",
6
6
  "bin": {