|
1 | | -# library, with fallbacks to `git2` and the Git CLI when needed. Supports advanced features like sparse checkout and TOML-based configuration. |
@@ -42,7 +42,7 @@ All operations return [`SubmoduleError`](src/gitoxide_manager.rs:14) for consist |
42 | 42 | ## Usage |
43 | 43 |
|
44 | 44 | Use this module as the backend for CLI commands to manage submodules in a repository. See the project [README](README.md) for usage examples and configuration details. |
45 | | -"#] |
| 45 | +"] |
46 | 46 |
|
47 | 47 | use crate::config::{Config, SubmoduleConfig, SubmoduleGitOptions}; |
48 | 48 | use gix::Repository; |
@@ -387,33 +387,35 @@ impl GitoxideSubmoduleManager { |
387 | 387 |
|
388 | 388 | // Clean up any existing broken submodule state |
389 | 389 | let target_path = std::path::Path::new(workdir).join(path); |
390 | | - |
| 390 | + |
391 | 391 | // Always try to clean up, even if the directory doesn't exist |
392 | 392 | // because there might be git metadata left behind |
393 | | - |
| 393 | + |
394 | 394 | // Try to deinitialize the submodule first |
395 | 395 | let _ = Command::new("git") |
396 | 396 | .args(["submodule", "deinit", "-f", path]) |
397 | 397 | .current_dir(workdir) |
398 | 398 | .output(); |
399 | | - |
| 399 | + |
400 | 400 | // Remove the submodule from .gitmodules and .git/config |
401 | 401 | let _ = Command::new("git") |
402 | 402 | .args(["rm", "-f", path]) |
403 | 403 | .current_dir(workdir) |
404 | 404 | .output(); |
405 | | - |
| 405 | + |
406 | 406 | // Remove the directory if it exists |
407 | 407 | if target_path.exists() { |
408 | 408 | let _ = std::fs::remove_dir_all(&target_path); |
409 | 409 | } |
410 | | - |
| 410 | + |
411 | 411 | // Clean up git modules directory |
412 | | - let git_modules_path = std::path::Path::new(workdir).join(".git/modules").join(path); |
| 412 | + let git_modules_path = std::path::Path::new(workdir) |
| 413 | + .join(".git/modules") |
| 414 | + .join(path); |
413 | 415 | if git_modules_path.exists() { |
414 | 416 | let _ = std::fs::remove_dir_all(&git_modules_path); |
415 | 417 | } |
416 | | - |
| 418 | + |
417 | 419 | // Also try to clean up parent directories in git modules if they're empty |
418 | 420 | if let Some(parent) = git_modules_path.parent() { |
419 | 421 | let _ = std::fs::remove_dir(parent); // This will only succeed if empty |
|
0 commit comments