Skip to content

fix: resolve rewind file path when running from subdirectory#663

Merged
Soph merged 2 commits intoentireio:mainfrom
mvanhorn:osc/661-fix-rewind-subdir-path
Mar 9, 2026
Merged

fix: resolve rewind file path when running from subdirectory#663
Soph merged 2 commits intoentireio:mainfrom
mvanhorn:osc/661-fix-rewind-subdir-path

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Mar 9, 2026

Summary

Fixes #661

When Rewind() restores files from a checkpoint, f.Name from go-git is repo-relative (e.g., src/app.js). The deletion path already correctly resolves absolute paths via filepath.Join(repoRoot, relPath), but the restoration path passed f.Name directly to os.MkdirAll and os.WriteFile, which resolve relative to CWD. When running from a subdirectory, files were restored to the wrong location.

Changes

  • Resolve f.Name to an absolute path using filepath.Join(repoRoot, f.Name) before creating directories and writing files
  • Mirrors the pattern already used by the deletion logic on line 386

Testing

  • Run entire rewind from a subdirectory within a repo and verify files are restored to their correct repo-relative paths
  • Existing integration tests in subdirectory_test.go cover the subdirectory scenario for hooks; this fix addresses the rewind path specifically

This contribution was developed with AI assistance (Claude Code).

f.Name from go-git is repo-relative, but os.MkdirAll and os.WriteFile
resolve relative to CWD. When running from a subdirectory, files were
restored to the wrong location. Use filepath.Join(repoRoot, f.Name)
to mirror the deletion path which already uses repoRoot.

Fixes entireio#661

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: 2ae6d1b68c23
Copy link
Copy Markdown
Collaborator

@Soph Soph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. Added some tests.

@Soph Soph merged commit 1cb7852 into entireio:main Mar 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Rewind() restores files to wrong path when CWD is a subdirectory of repo root

2 participants