(maybe_config: Result<Config, AppError>, path: &str)
| 134 | } |
| 135 | |
| 136 | pub fn import(maybe_config: Result<Config, AppError>, path: &str) -> Result<(), AppError> { |
| 137 | let path = fs::canonicalize(Path::new(path))?; |
| 138 | let project_path = path.to_str().ok_or(AppError::InternalError("project path is not valid unicode"))?.to_owned(); |
| 139 | let file_name = AppError::require(path.file_name(), AppError::UserError("Import path needs to be valid".to_string()))?; |
| 140 | let project_name: String = file_name.to_string_lossy().into_owned(); |
| 141 | let maybe_settings = maybe_config.ok().map(|c| c.settings); |
| 142 | let new_project = load_project(maybe_settings, path.clone(), &project_name)?; |
| 143 | let new_project_with_path = Project { |
| 144 | override_path: Some(project_path), |
| 145 | ..new_project |
| 146 | }; |
| 147 | config::write_project(&new_project_with_path)?; |
| 148 | Ok(()) |
| 149 | } |
| 150 | |
| 151 | fn load_project(maybe_settings: Option<Settings>, path_to_repo: PathBuf, name: &str) -> Result<Project, AppError> { |
| 152 | let repo: Repository = Repository::open(path_to_repo)?; |
no test coverage detected