diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 38cf285e7..b6b8ea46f 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -91,7 +91,7 @@ impl GitBackend { let mut buf = Vec::new(); git_target_file.read_to_end(&mut buf).unwrap(); let git_repo_path_str = String::from_utf8(buf).unwrap(); - let git_repo_path = std::fs::canonicalize(store_path.join(git_repo_path_str)).unwrap(); + let git_repo_path = store_path.join(git_repo_path_str).canonicalize().unwrap(); let repo = git2::Repository::open(git_repo_path).unwrap(); // TODO: Delete this migration code in early 2022 or so if let Ok(notes) = repo.notes(Some(COMMITS_NOTES_REF)) { diff --git a/lib/src/workspace.rs b/lib/src/workspace.rs index 61d10d817..54f9e6cef 100644 --- a/lib/src/workspace.rs +++ b/lib/src/workspace.rs @@ -168,7 +168,7 @@ impl Workspace { ) -> Result<(Self, Arc), WorkspaceInitError> { let jj_dir = create_jj_dir(&workspace_root)?; - let repo_dir = std::fs::canonicalize(repo.repo_path()).unwrap(); + let repo_dir = repo.repo_path().canonicalize().unwrap(); let mut repo_file = File::create(jj_dir.join("repo")).unwrap(); repo_file .write_all(repo_dir.to_str().unwrap().as_bytes()) @@ -208,7 +208,7 @@ impl Workspace { let mut buf = Vec::new(); repo_file.read_to_end(&mut buf).unwrap(); let repo_path_str = String::from_utf8(buf).unwrap(); - repo_dir = std::fs::canonicalize(jj_dir.join(repo_path_str)).unwrap(); + repo_dir = jj_dir.join(repo_path_str).canonicalize().unwrap(); if !repo_dir.is_dir() { return Err(WorkspaceLoadError::RepoDoesNotExist(repo_dir)); } diff --git a/lib/tests/test_workspace.rs b/lib/tests/test_workspace.rs index 760278de0..be46b2cca 100644 --- a/lib/tests/test_workspace.rs +++ b/lib/tests/test_workspace.rs @@ -74,7 +74,7 @@ fn test_init_additional_workspace(use_git: bool) { assert_eq!(ws2.workspace_id(), ws2_id); assert_eq!( *ws2.repo_path(), - std::fs::canonicalize(workspace.repo_path()).unwrap() + workspace.repo_path().canonicalize().unwrap() ); assert_eq!(*ws2.workspace_root(), ws2_root); let same_workspace = Workspace::load(&settings, ws2_root); @@ -83,7 +83,7 @@ fn test_init_additional_workspace(use_git: bool) { assert_eq!(same_workspace.workspace_id(), ws2_id); assert_eq!( *same_workspace.repo_path(), - std::fs::canonicalize(workspace.repo_path()).unwrap() + workspace.repo_path().canonicalize().unwrap() ); assert_eq!(same_workspace.workspace_root(), ws2.workspace_root()); } diff --git a/src/commands.rs b/src/commands.rs index 405d8f606..24d06a298 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1716,14 +1716,14 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(), } else { fs::create_dir(&wc_path).unwrap(); } - let wc_path = std::fs::canonicalize(&wc_path).unwrap(); + let wc_path = wc_path.canonicalize().unwrap(); if let Some(git_store_str) = &args.git_repo { let mut git_store_path = ui.cwd().join(git_store_str); if !git_store_path.ends_with(".git") { git_store_path = git_store_path.join(".git"); } - git_store_path = std::fs::canonicalize(&git_store_path).unwrap(); + git_store_path = git_store_path.canonicalize().unwrap(); // If the git repo is inside the workspace, use a relative path to it so the // whole workspace can be moved without breaking. if let Ok(relative_path) = git_store_path.strip_prefix(&wc_path) { @@ -1757,7 +1757,7 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &InitArgs) -> Result<(), } else { Workspace::init_local(ui.settings(), wc_path.clone())?; }; - let cwd = std::fs::canonicalize(&ui.cwd()).unwrap(); + let cwd = ui.cwd().canonicalize().unwrap(); let relative_wc_path = ui::relative_path(&cwd, &wc_path); writeln!(ui, "Initialized repo in \"{}\"", relative_wc_path.display())?; Ok(())