cli: extract a function for loading the workspace
I want to be able to create a `WorkspaceCommandHelper` without
snapshotting the working copy. That will be useful when adding a
command for updating a stale working copy.
@@ -242,19 +242,24 @@ impl CommandHelper {
}
pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
+ let workspace = self.load_workspace(ui)?;
+ let mut workspace_command = self.resolve_operation(ui, workspace)?;
+ workspace_command.snapshot(ui)?;
+ Ok(workspace_command)
+ }
+
+ pub fn load_workspace(&self, ui: &Ui) -> Result<Workspace, CommandError> {
let wc_path_str = self.global_args.repository.as_deref().unwrap_or(".");
let wc_path = ui.cwd().join(wc_path_str);
- let workspace =
- Workspace::load(ui.settings(), &wc_path, &self.backend_factories).map_err(|err| {
- match err {
+ Workspace::load(ui.settings(), &wc_path, &self.backend_factories).map_err(|err| match err {
WorkspaceLoadError::NoWorkspaceHere(wc_path) => {
let message = format!("There is no jj repo in \"{}\"", wc_path_str);
let git_dir = wc_path.join(".git");
if git_dir.is_dir() {
user_error_with_hint(
message,
- "It looks like this is a git repo. You can create a jj repo \
- backed by it by running this:
+ "It looks like this is a git repo. You can create a jj repo backed by it \
+ by running this:
jj init --git-repo=.",
)
} else {
@@ -267,11 +272,7 @@ jj init --git-repo=.",
)),
WorkspaceLoadError::Path(e) => user_error(format!("{}: {}", e, e.error)),
WorkspaceLoadError::NonUnicodePath => user_error(err.to_string()),
- }
- })?;
- let mut workspace_command = self.resolve_operation(ui, workspace)?;
- workspace_command.snapshot(ui)?;
- Ok(workspace_command)
+ })
}
fn resolve_operation(
