Skip to content

Commit

Permalink
Merge pull request #200 from tomoakiichige/fix/add-subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan authored Jul 22, 2023
2 parents 41fdcb3 + 475c308 commit 4b8aaf3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/cmd/add.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::rename;
use std::fs::{create_dir_all, rename};
use std::path::PathBuf;

use anyhow::{bail, Result};
use anyhow::{anyhow, bail, Result};
use clap::Parser;
use console::style;
use dialoguer::Confirm;
Expand Down Expand Up @@ -80,12 +80,26 @@ impl Cmd {
return Ok(());
}

let parent_path = path
.parent()
.ok_or_else(|| {
anyhow!(
"Failed to determine parent path for the repository's new location: {}",
path.to_string_lossy()
)
})?
.to_path_buf();

create_dir_all(parent_path)?;

rename(&self.repo, &path)?;
info!(
"Added the repository successfully to: {}",
path.to_string_lossy(),
);

let repo = Repository::open(&path)?;

if let Some((name, p)) = profile {
p.apply(&mut repo.config()?)?;

Expand Down

0 comments on commit 4b8aaf3

Please sign in to comment.