Skip to content

Commit 15193a7

Browse files
committed
allow organize to move repositories into a child directory of their current location
1 parent b6f2b81 commit 15193a7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gitoxide-core/src/organize.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,17 @@ fn handle(
198198
destination.display()
199199
)),
200200
Mode::Execute => {
201-
std::fs::create_dir_all(destination.parent().expect("repo destination is not the root"))?;
201+
if destination.starts_with(git_workdir) {
202+
let tempdir = tempfile::tempdir_in(canonicalized_destination)?;
203+
let tempdest = tempdir.path().join(destination.file_name().expect("repo destination is not the root"));
204+
std::fs::rename(git_workdir, &tempdest)?;
205+
std::fs::create_dir_all(destination.parent().expect("repo destination is not the root"))?;
206+
std::fs::rename(&tempdest, &destination)?;
207+
} else {
208+
std::fs::create_dir_all(destination.parent().expect("repo destination is not the root"))?;
209+
std::fs::rename(git_workdir, &destination)?;
210+
}
202211
progress.done(format!("Moving {} to {}", git_workdir.display(), destination.display()));
203-
std::fs::rename(git_workdir, &destination)?;
204212
}
205213
}
206214
Ok(())

0 commit comments

Comments
 (0)