-
Notifications
You must be signed in to change notification settings - Fork 122
feat:add --dryrun #1422
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
Merged
feat:add --dryrun #1422
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ff6d1ad
feat(remove_:add --dryrun
mengnankkkk a5902ce
feat:ci bug
mengnankkkk 01a8414
fix: ci bug2
mengnankkkk 2f89815
fix: chinese instead en
mengnankkkk a36e67b
Update remove.rs
mengnankkkk 7952569
Update libra/src/command/remove.rs
mengnankkkk a668026
fix:add post-processing
mengnankkkk 2dd7a56
Merge branch 'feat-mengnankk' of github.com:mengnankkkk/mega into fea…
mengnankkkk 1a0c5f0
Update libra/src/command/remove.rs
mengnankkkk 21e9343
fix: add consistent
mengnankkkk 77bf3d1
Merge branch 'feat-mengnankk' of github.com:mengnankkkk/mega into fea…
mengnankkkk f29c662
Merge branch 'main' into feat-mengnankk
genedna 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Simple test program to verify rm --dry-run functionality | ||
| use libra::command::remove::{execute, RemoveArgs}; | ||
| use std::fs; | ||
| use std::io::Write; | ||
| use tempfile::TempDir; | ||
|
|
||
| fn main() { | ||
| println!("Testing libra rm --dry-run functionality..."); | ||
|
|
||
| // Create a temporary directory for test files | ||
| let temp_dir = TempDir::new().expect("Failed to create temporary directory"); | ||
| let temp_path = temp_dir.path(); | ||
|
|
||
| // Create test files in the temporary directory | ||
| let file1_path = temp_path.join("file1.txt"); | ||
| let file2_path = temp_path.join("file2.txt"); | ||
|
|
||
| let mut file1 = fs::File::create(&file1_path).unwrap(); | ||
| file1.write_all(b"Test content 1").unwrap(); | ||
|
|
||
| let mut file2 = fs::File::create(&file2_path).unwrap(); | ||
| file2.write_all(b"Test content 2").unwrap(); | ||
|
|
||
| println!("Created test files in temporary directory: {:?}", temp_path); | ||
|
|
||
| // Test dry-run functionality | ||
| let args = RemoveArgs { | ||
| pathspec: vec![file1_path.to_string_lossy().to_string(), file2_path.to_string_lossy().to_string()], | ||
| cached: false, | ||
| recursive: false, | ||
| force: true, // Use force mode to avoid requiring git repository | ||
| dry_run: true, | ||
| }; | ||
|
|
||
| println!("\nExecuting: libra rm --dry-run --force on test files"); | ||
|
|
||
| match execute(args) { | ||
| Ok(_) => { | ||
| println!("✓ dry-run executed successfully!"); | ||
|
|
||
| // Verify files still exist | ||
| if file1_path.exists() && file2_path.exists() { | ||
| println!(" Files still exist after dry-run (correct behavior)"); | ||
| } else { | ||
| println!(" Error: dry-run should not actually delete files"); | ||
| } | ||
| } | ||
| Err(e) => { | ||
| println!("✗ dry-run execution failed: {:?}", e); | ||
| } | ||
| } | ||
|
|
||
| println!("\nTest completed, temporary directory will be automatically cleaned up"); | ||
| // The temporary directory will be automatically cleaned up when temp_dir goes out of scope | ||
| } | ||
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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,9 @@ pub struct RemoveArgs { | |||||||||||||||||
| /// force removal, skip validation | ||||||||||||||||||
| #[clap(short, long)] | ||||||||||||||||||
| pub force: bool, | ||||||||||||||||||
| /// show what would be removed without actually removing | ||||||||||||||||||
| #[clap(long)] | ||||||||||||||||||
| pub dry_run: bool, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| pub fn execute(args: RemoveArgs) -> Result<(), GitError> { | ||||||||||||||||||
|
|
@@ -44,6 +47,53 @@ pub fn execute(args: RemoveArgs) -> Result<(), GitError> { | |||||||||||||||||
| return Err(GitError::CustomError(error_msg)); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // In dry-run mode, show what would be removed but don't actually remove anything | ||||||||||||||||||
| if args.dry_run { | ||||||||||||||||||
| println!("Would remove the following:"); | ||||||||||||||||||
| for path_str in args.pathspec.iter() { | ||||||||||||||||||
| let path = PathBuf::from(path_str); | ||||||||||||||||||
| let path_wd = path.to_workdir().to_string_or_panic(); | ||||||||||||||||||
|
|
||||||||||||||||||
| if dirs.contains(path_str) { | ||||||||||||||||||
| // dir - find all files in this directory that are tracked | ||||||||||||||||||
| let entries = index.tracked_entries(0); | ||||||||||||||||||
| // Create directory prefix with proper path separator for cross-platform compatibility | ||||||||||||||||||
| let dir_prefix = if path_wd.is_empty() { | ||||||||||||||||||
| String::new() | ||||||||||||||||||
| } else if path_wd.ends_with(std::path::MAIN_SEPARATOR) { | ||||||||||||||||||
| path_wd.clone() | ||||||||||||||||||
| } else { | ||||||||||||||||||
| format!("{}{}", path_wd, std::path::MAIN_SEPARATOR) | ||||||||||||||||||
|
mengnankkkk marked this conversation as resolved.
|
||||||||||||||||||
| }; | ||||||||||||||||||
| for entry in entries.iter() { | ||||||||||||||||||
| if entry.name.starts_with(&dir_prefix) { | ||||||||||||||||||
| println!("rm '{}'", entry.name.bright_yellow()); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| if !args.cached { | ||||||||||||||||||
| println!("rm directory '{}'", path_str.bright_yellow()); | ||||||||||||||||||
| } | ||||||||||||||||||
| } else { | ||||||||||||||||||
| // file | ||||||||||||||||||
| if args.force { | ||||||||||||||||||
| // In force mode: always try to remove (matches actual execution logic) | ||||||||||||||||||
| // - If tracked, would be removed from index | ||||||||||||||||||
| // - If not tracked, would still be processed (and filesystem file deleted if not cached) | ||||||||||||||||||
| if index.tracked(&path_wd, 0) { | ||||||||||||||||||
| println!("rm '{}'", path_wd.bright_yellow()); | ||||||||||||||||||
| } else { | ||||||||||||||||||
| // Even untracked files are processed in force mode | ||||||||||||||||||
| println!("rm '{}'", path_wd.bright_yellow()); | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+82
to
+87
|
||||||||||||||||||
| if index.tracked(&path_wd, 0) { | |
| println!("rm '{}'", path_wd.bright_yellow()); | |
| } else { | |
| // Even untracked files are processed in force mode | |
| println!("rm '{}'", path_wd.bright_yellow()); | |
| } | |
| // In force mode, print removal message regardless of tracked status | |
| println!("rm '{}'", path_wd.bright_yellow()); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example won't work correctly because the
executefunction checks for repository existence at the beginning and returns early if no repository is found, making the force flag ineffective for this purpose.