mirror of
https://github.com/openai/codex.git
synced 2026-05-01 20:02:05 +03:00
Fixes #8214 by removing the '--staged' flag from the undo git restore command. This ensures that while the working tree is reverted to the snapshot state, the user's staged changes (index) are preserved, preventing data loss. Also adds a regression test.
This commit is contained in:
@@ -469,15 +469,18 @@ fn restore_to_commit_inner(
|
||||
repo_prefix: Option<&Path>,
|
||||
commit_id: &str,
|
||||
) -> Result<(), GitToolingError> {
|
||||
// `git restore` resets both the index and working tree to the snapshot commit.
|
||||
// `git restore` resets the working tree to the snapshot commit.
|
||||
// We intentionally avoid --staged to preserve user's staged changes.
|
||||
// While this might leave some Codex-staged changes in the index (if Codex ran `git add`),
|
||||
// it prevents data loss for users who use the index as a save point.
|
||||
// Data safety > cleanliness.
|
||||
// Example:
|
||||
// git restore --source <commit> --worktree --staged -- <prefix>
|
||||
// git restore --source <commit> --worktree -- <prefix>
|
||||
let mut restore_args = vec![
|
||||
OsString::from("restore"),
|
||||
OsString::from("--source"),
|
||||
OsString::from(commit_id),
|
||||
OsString::from("--worktree"),
|
||||
OsString::from("--staged"),
|
||||
OsString::from("--"),
|
||||
];
|
||||
if let Some(prefix) = repo_prefix {
|
||||
|
||||
Reference in New Issue
Block a user