mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 09:11:55 +00:00
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.
This commit is contained in:
parent
18b80f4008
commit
e1be0f5096
1 changed files with 28 additions and 27 deletions
|
@ -242,19 +242,24 @@ impl CommandHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
|
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_str = self.global_args.repository.as_deref().unwrap_or(".");
|
||||||
let wc_path = ui.cwd().join(wc_path_str);
|
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) => {
|
WorkspaceLoadError::NoWorkspaceHere(wc_path) => {
|
||||||
let message = format!("There is no jj repo in \"{}\"", wc_path_str);
|
let message = format!("There is no jj repo in \"{}\"", wc_path_str);
|
||||||
let git_dir = wc_path.join(".git");
|
let git_dir = wc_path.join(".git");
|
||||||
if git_dir.is_dir() {
|
if git_dir.is_dir() {
|
||||||
user_error_with_hint(
|
user_error_with_hint(
|
||||||
message,
|
message,
|
||||||
"It looks like this is a git repo. You can create a jj repo \
|
"It looks like this is a git repo. You can create a jj repo backed by it \
|
||||||
backed by it by running this:
|
by running this:
|
||||||
jj init --git-repo=.",
|
jj init --git-repo=.",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,11 +272,7 @@ jj init --git-repo=.",
|
||||||
)),
|
)),
|
||||||
WorkspaceLoadError::Path(e) => user_error(format!("{}: {}", e, e.error)),
|
WorkspaceLoadError::Path(e) => user_error(format!("{}: {}", e, e.error)),
|
||||||
WorkspaceLoadError::NonUnicodePath => user_error(err.to_string()),
|
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(
|
fn resolve_operation(
|
||||||
|
|
Loading…
Reference in a new issue