From 0c00dc8a6c4bb8444553e61d700bdc911da42d46 Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Mon, 6 Oct 2025 13:54:28 +0300 Subject: [PATCH 1/2] fix(repo-dir): check if the current cwd is .git before setting the default cwd Fixes gitui-org/gitui/issues/2732 --- src/args.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/args.rs b/src/args.rs index b03d88a806..bfeb492fe6 100644 --- a/src/args.rs +++ b/src/args.rs @@ -34,9 +34,24 @@ pub fn process_cmdline() -> Result { let workdir = arg_matches.get_one::("workdir").map(PathBuf::from); - let gitdir = arg_matches - .get_one::("directory") - .map_or_else(|| PathBuf::from("."), PathBuf::from); + let gitdir = 'blk: { + let mut cwd = env::current_dir()?; + let cwd_file_name = cwd + .file_name() + .ok_or(anyhow!("Coulden't get the CWD name"))? + .as_encoded_bytes(); + if cwd_file_name == b".git" { + cwd = cwd + .parent() + .ok_or(anyhow!( + "Coulden't find the parent directory of .git" + ))? + .to_path_buf(); + } + break 'blk arg_matches + .get_one::("directory") + .map_or_else(|| cwd, PathBuf::from); + }; let repo_path = if let Some(w) = workdir { RepoPath::Workdir { gitdir, workdir: w } From 41645e9b7d0b378bff6e568ad2b937c179f5b91e Mon Sep 17 00:00:00 2001 From: Anas Elgarhy Date: Mon, 6 Oct 2025 14:07:44 +0300 Subject: [PATCH 2/2] fix(args.rs): clippy errors --- src/args.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/args.rs b/src/args.rs index bfeb492fe6..09c173c008 100644 --- a/src/args.rs +++ b/src/args.rs @@ -38,14 +38,16 @@ pub fn process_cmdline() -> Result { let mut cwd = env::current_dir()?; let cwd_file_name = cwd .file_name() - .ok_or(anyhow!("Coulden't get the CWD name"))? + .ok_or_else(|| anyhow!("Coulden't get the CWD name"))? .as_encoded_bytes(); if cwd_file_name == b".git" { cwd = cwd .parent() - .ok_or(anyhow!( - "Coulden't find the parent directory of .git" - ))? + .ok_or_else(|| { + anyhow!( + "Coulden't find the parent directory of .git" + ) + })? .to_path_buf(); } break 'blk arg_matches