diff --git a/src/args.rs b/src/args.rs index b03d88a806..09c173c008 100644 --- a/src/args.rs +++ b/src/args.rs @@ -34,9 +34,26 @@ 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_else(|| anyhow!("Coulden't get the CWD name"))? + .as_encoded_bytes(); + if cwd_file_name == b".git" { + cwd = cwd + .parent() + .ok_or_else(|| { + 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 }