Repository navigation
Fix #261: port local repository workflows to native Windows #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ba1a9e
Fix #261: make local repository workflows native on Windows
acoliver 74687ff
Merge remote-tracking branch 'origin/main' into issue261
acoliver 48d3eff
Restore CI compatibility after syncing main
acoliver 625017f
Make Git cleanup regression test self-contained
acoliver 1b9f8b0
Harden Windows repository preparation boundaries
acoliver 4e4a43c
Fix cross-platform cleanup validation
acoliver e3e1512
Address final repository preparation review findings
acoliver 4122315
Resolve remaining repository preparation reviews
acoliver 932e001
Deduplicate cleanup parent traversal
acoliver fea5ca9
Merge remote-tracking branch 'origin/main' into issue261
acoliver 75b21a1
Resolve fixture overlap after syncing main
acoliver 030d343
Harden Windows path normalization after review
acoliver 503c1b2
Document portable directory cleanup errors
acoliver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
dev-docs/tmux-scenarios/windows-local-repository-prep.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| { | ||
| "config": { | ||
| "cols": 100, | ||
| "rows": 32, | ||
| "history_limit": 2000, | ||
| "initial_wait_ms": 100, | ||
| "assert_mode": "strict" | ||
| }, | ||
| "steps": [ | ||
| { "waitFor": "LLxprt Jefe" }, | ||
| { "key": "i" }, | ||
| { "waitFor": "Issues" }, | ||
| { "key": "Enter" }, | ||
| { "waitFor": "Send to Agent" }, | ||
| { "key": "Enter" }, | ||
| { "waitFor": "Dirty Working Copy" }, | ||
| { "expect": "( Cancel )" }, | ||
| { "capture": "windows-local-repository-dirty-safety" }, | ||
| { "key": "Escape" }, | ||
| { "waitForNot": "Dirty Working Copy" }, | ||
| { "key": "Escape" }, | ||
| { "key": "q" }, | ||
| { "waitForExit": 3000 } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Issue #261 plan: native Windows repository and GitHub workflows | ||
|
|
||
| ## Goal | ||
|
|
||
| Make local repository, Git, GitHub, issue, and pull-request preparation use | ||
| native executable/argv and filesystem boundaries on Windows, while preserving | ||
| remote Linux shell plans and Unix behavior. | ||
|
|
||
| ## RED | ||
|
|
||
| 1. Add a deterministic TUI scenario for the local dirty-copy preparation and | ||
| confirmation path, with no network operations. | ||
| 2. Add executable-resolution tests for Windows `PATH`/`PATHEXT`, paths containing | ||
| spaces and Unicode, explicit overrides, and missing executables. | ||
| 3. Add real-Git integration tests rooted beneath spaces and Unicode that cover | ||
| clone, refresh/default-branch preparation, linked worktrees, dirty detection, | ||
| argv-like filenames, and cleanup. | ||
| 4. Add pure path-policy tests for mixed/trailing separators, Windows | ||
| case-insensitive comparison without mutating display values, long paths, and | ||
| precise UNC rejection. | ||
| 5. Add cleanup tests proving no `git clean` is planned, only enumerated untracked | ||
| paths are removed, owned metadata is retained, and filesystem removal errors | ||
| stop before tracked changes are reset. | ||
| 6. Add GitHub command-boundary tests proving every argument remains a distinct | ||
| `OsString` and the resolved `gh` executable is used. | ||
|
|
||
| ## GREEN | ||
|
|
||
| 1. Introduce a typed local-tool executable resolver shared by Git and GitHub CLI | ||
| boundaries, including native Windows `PATHEXT` behavior. | ||
| 2. Route local Git operations through a typed `GitCommand` boundary with explicit | ||
| argv, noninteractive environment, typed spawn/exit failures, and no shell. | ||
| 3. Route all GitHub CLI operations through a resolved `gh` command constructor; | ||
| retain existing command-planning/parsing APIs and error categorization. | ||
| 4. Introduce a local-path policy for comparison and supported-path validation. | ||
| Preserve original `PathBuf` values for display and subprocess arguments; | ||
| reject UNC work directories early with actionable text until they have a | ||
| dedicated behavioral environment. | ||
| 5. Replace `git clean` with `git ls-files --others --exclude-standard -z` plus | ||
| individually constrained filesystem removals. Surface Windows lock failures | ||
| and do not proceed to `reset --hard` after partial cleanup failure. | ||
| 6. Keep `issue_prep_remote` Unix command strings unchanged and add regression | ||
| assertions proving that boundary. | ||
|
|
||
| ## REFACTOR and review | ||
|
|
||
| - Keep side effects in Git/GitHub/filesystem boundaries and state transitions | ||
| deterministic. | ||
| - Verify repository registration, issue and PR handoff call the new boundaries. | ||
| - Audit deletion/reclone ownership and ensure no broad deletion is introduced. | ||
| - Run focused Windows and Unix checks, strict Clippy, locked build/test, and the | ||
| full CI verification suite. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| //! Ownership-scoped local dirty-worktree cleanup. | ||
|
|
||
| use std::collections::HashSet; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| #[cfg(unix)] | ||
| use std::ffi::OsString; | ||
| #[cfg(unix)] | ||
| use std::os::unix::ffi::OsStringExt; | ||
|
|
||
| use super::{git_capture, git_require_success, require_success}; | ||
|
|
||
| pub(in crate::app_input) fn discard_workdir_changes(work_dir: &Path) -> Result<(), String> { | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| let output = git_capture( | ||
| work_dir, | ||
| [ | ||
| "-c", | ||
| "core.quotepath=false", | ||
| "ls-files", | ||
| "--others", | ||
| "--exclude-standard", | ||
| "-z", | ||
| ], | ||
| )?; | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| require_success(&output, "ls-files --others --exclude-standard -z")?; | ||
| let untracked = parse_changed_paths(&output.stdout)?; | ||
| for relative in &untracked { | ||
| remove_untracked_path(work_dir, relative)?; | ||
| } | ||
| remove_empty_untracked_parents(work_dir, &untracked)?; | ||
| restore_tracked_paths(work_dir) | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| fn restore_tracked_paths(work_dir: &Path) -> Result<(), String> { | ||
| let output = git_capture( | ||
| work_dir, | ||
| [ | ||
| "-c", | ||
| "core.quotepath=false", | ||
| "diff", | ||
| "--name-only", | ||
| "-z", | ||
| "HEAD", | ||
| ], | ||
| )?; | ||
| require_success(&output, "diff --name-only -z HEAD")?; | ||
| for relative in parse_changed_paths(&output.stdout)? { | ||
| git_require_success( | ||
| work_dir, | ||
| [ | ||
| std::ffi::OsStr::new("restore"), | ||
| std::ffi::OsStr::new("--source=HEAD"), | ||
| std::ffi::OsStr::new("--staged"), | ||
| std::ffi::OsStr::new("--worktree"), | ||
| std::ffi::OsStr::new("--"), | ||
| relative.as_os_str(), | ||
| ], | ||
| )?; | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| } | ||
|
acoliver marked this conversation as resolved.
Resolved
acoliver marked this conversation as resolved.
Resolved
|
||
| Ok(()) | ||
|
acoliver marked this conversation as resolved.
Resolved
acoliver marked this conversation as resolved.
Resolved
|
||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| fn parse_changed_paths(stdout: &[u8]) -> Result<Vec<PathBuf>, String> { | ||
| let mut paths = parse_paths(stdout)?; | ||
| paths.retain(|path| !is_owned_path(path)); | ||
| Ok(paths) | ||
| } | ||
|
|
||
| fn is_owned_path(path: &Path) -> bool { | ||
| path.components().next().is_some_and(|component| { | ||
| let value = component.as_os_str().to_string_lossy(); | ||
| value.eq_ignore_ascii_case(".jefe") || value.eq_ignore_ascii_case(".llxprt") | ||
| }) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| fn parse_paths(stdout: &[u8]) -> Result<Vec<PathBuf>, String> { | ||
| stdout | ||
| .split(|byte| *byte == 0) | ||
| .filter(|raw| !raw.is_empty()) | ||
| .map(|raw| { | ||
| let path = path_from_git_bytes(raw)?; | ||
| let safe = !path.is_absolute() | ||
| && path | ||
| .components() | ||
| .all(|component| matches!(component, std::path::Component::Normal(_))); | ||
| if safe { | ||
| Ok(path) | ||
| } else { | ||
| Err(format!("git returned an unsafe path: {}", path.display())) | ||
| } | ||
| }) | ||
| .collect() | ||
|
acoliver marked this conversation as resolved.
Resolved
acoliver marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| #[cfg(unix)] | ||
| fn path_from_git_bytes(raw: &[u8]) -> Result<PathBuf, String> { | ||
| if raw.is_empty() { | ||
| return Err("git returned an empty path".to_owned()); | ||
| } | ||
| Ok(PathBuf::from(OsString::from_vec(raw.to_vec()))) | ||
| } | ||
|
|
||
| #[cfg(not(unix))] | ||
| fn path_from_git_bytes(raw: &[u8]) -> Result<PathBuf, String> { | ||
| std::str::from_utf8(raw) | ||
| .map(PathBuf::from) | ||
| .map_err(|error| format!("git returned a non-UTF-8 path: {error}")) | ||
| } | ||
|
|
||
| fn remove_untracked_path(work_dir: &Path, relative: &Path) -> Result<(), String> { | ||
| let path = work_dir.join(relative); | ||
| let metadata = std::fs::symlink_metadata(&path).map_err(|error| { | ||
| format!( | ||
| "Failed to inspect untracked path {} before cleanup: {error}. Close programs using the file and retry.", | ||
| path.display() | ||
| ) | ||
| })?; | ||
| let result = if metadata.is_dir() && !metadata.file_type().is_symlink() { | ||
| std::fs::remove_dir(&path) | ||
| } else { | ||
| std::fs::remove_file(&path) | ||
| }; | ||
| result.map_err(|error| { | ||
| format!( | ||
| "Failed to remove untracked path {}: {error}. Close programs using the file and retry.", | ||
| path.display() | ||
| ) | ||
| }) | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| } | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
|
|
||
| fn remove_empty_untracked_parents(work_dir: &Path, paths: &[PathBuf]) -> Result<(), String> { | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
| let mut candidates = HashSet::new(); | ||
| for relative in paths { | ||
| let mut parent = relative.parent(); | ||
| while let Some(candidate) = parent.filter(|value| !value.as_os_str().is_empty()) { | ||
| candidates.insert(candidate.to_path_buf()); | ||
| parent = candidate.parent(); | ||
| } | ||
| } | ||
| let mut candidates = candidates.into_iter().collect::<Vec<_>>(); | ||
| candidates.sort_by_key(|path| std::cmp::Reverse(path.components().count())); | ||
| for candidate in candidates { | ||
| let directory = work_dir.join(candidate); | ||
| match std::fs::remove_dir(&directory) { | ||
| Ok(()) => {} | ||
| Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} | ||
| Err(error) if is_directory_not_empty(&error, &directory) => {} | ||
| Err(error) => { | ||
| return Err(format!( | ||
| "Failed to remove empty untracked directory {}: {error}", | ||
| directory.display() | ||
| )); | ||
| } | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn is_directory_not_empty(error: &std::io::Error, _path: &Path) -> bool { | ||
| matches!(error.raw_os_error(), Some(39 | 66 | 145)) | ||
| } | ||
|
acoliver marked this conversation as resolved.
Resolved
|
||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn owned_metadata_names_are_ascii_case_insensitive() { | ||
| assert!(is_owned_path(Path::new(".JEFE/cache.json"))); | ||
| assert!(is_owned_path(Path::new(".LlXpRt/LLXPRT.md"))); | ||
| assert!(!is_owned_path(Path::new("nested/.JEFE/cache.json"))); | ||
| } | ||
|
|
||
| #[test] | ||
| fn shared_parent_already_removed_is_successful() { | ||
| let root = tempfile::tempdir() | ||
| .unwrap_or_else(|error| panic!("create cleanup test directory: {error}")); | ||
| let shared = root.path().join("shared"); | ||
| std::fs::create_dir(&shared) | ||
| .unwrap_or_else(|error| panic!("create shared directory: {error}")); | ||
| let paths = vec![PathBuf::from("shared/one"), PathBuf::from("shared/two")]; | ||
|
|
||
| let result = remove_empty_untracked_parents(root.path(), &paths); | ||
|
|
||
| assert!(result.is_ok(), "shared-parent cleanup failed: {result:?}"); | ||
| assert!(!shared.exists()); | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.