From 356037379a9b26e4163a2ac4f6d3c48402075748 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 25 Feb 2024 20:35:17 +0900 Subject: [PATCH] cli: narrow scope of canonicalized cwd in git_init() It's only needed to calculate relative path of canonicalized workspace_root, and I'm going to remove it. --- cli/src/commands/git.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/git.rs b/cli/src/commands/git.rs index 7a3edf23c..eeefbbb8b 100644 --- a/cli/src/commands/git.rs +++ b/cli/src/commands/git.rs @@ -379,9 +379,6 @@ pub fn git_init( colocate: bool, git_repo: Option<&str>, ) -> Result<(), CommandError> { - let cwd = command.cwd().canonicalize().unwrap(); - let relative_wc_path = file_util::relative_path(&cwd, workspace_root); - if colocate { let (workspace, repo) = Workspace::init_colocated_git(command.settings(), workspace_root)?; let workspace_command = command.for_loaded_repo(ui, workspace, repo)?; @@ -390,7 +387,7 @@ pub fn git_init( } if let Some(git_store_str) = git_repo { - let git_store_path = cwd.join(git_store_str); + let git_store_path = command.cwd().join(git_store_str); let (workspace, repo) = Workspace::init_external_git(command.settings(), workspace_root, &git_store_path)?; // Import refs first so all the reachable commits are indexed in @@ -414,6 +411,8 @@ pub fn git_init( print_trackable_remote_branches(ui, workspace_command.repo().view())?; } else { if workspace_root.join(".git").exists() { + let cwd = command.cwd().canonicalize().unwrap(); + let relative_wc_path = file_util::relative_path(&cwd, workspace_root); return Err(user_error_with_hint( "Did not create a jj repo because there is an existing Git repo in this directory.", format!(