-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cloned repositories to application config
- Loading branch information
Showing
2 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,18 +1,35 @@ | ||
use std::path::Path; | ||
|
||
use crate::cli::AddArgs; | ||
use crate::config::Config; | ||
use crate::config::{Config, RepositoryConfig}; | ||
use crate::git::clone::{clone_repository, get_clone_path}; | ||
|
||
pub fn add(args: &AddArgs, config: &mut Config, data_dir: &Path) -> eyre::Result<()> { | ||
// TODO: Resolve the right clone path in the following priority order | ||
// 1. args.path | ||
// 2. configuration file | ||
// 3. get_clone_path | ||
let clone_path = get_clone_path(data_dir, &args.url)?; | ||
let _repo = clone_repository(&clone_path, &args.url, args.branch.as_deref(), args.force)?; | ||
// TODO: What *should* the name be? The whole URL? Just the path part of the URL? | ||
// TODO: What to do if the repository is already added? | ||
let Some((_, name)) = args.url.rsplit_once('/') else { | ||
eyre::bail!("Failed to parse URL '{}'", args.url) | ||
}; | ||
let name = name.to_string(); | ||
|
||
// TODO: Save the configuration parameters to a config file. | ||
let clone_path = if let Some(cli_path) = &args.path { | ||
cli_path.to_path_buf() | ||
} else { | ||
get_clone_path(data_dir, &args.url)? | ||
}; | ||
|
||
let repo_config = RepositoryConfig { | ||
path: clone_path, | ||
remote_url: args.url.clone(), | ||
branch: args.branch.clone(), | ||
}; | ||
|
||
let _repo = clone_repository( | ||
&repo_config.path, | ||
&args.url, | ||
args.branch.as_deref(), | ||
args.force, | ||
)?; | ||
config.repositories.insert(name, repo_config); | ||
Ok(()) | ||
} |
This file contains 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