Skip to content

Commit c67a914

Browse files
committed
Fix repo root display in convert
Previously, `git prole` would say things like `Converting ~/projects to a worktree repository at ~/projects/my-repo`, which is misleading. Now it will say `Converting ~/projects/my-repo to a worktree repository`.
1 parent c204a0b commit c67a914

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ where
217217
// - `convert_bare_dot_git`
218218
// - `convert_bare_dot_git_from_parent`
219219
// - `convert_common_parent`
220-
let repo = git.path().repo_root_or_git_common_dir_if_bare()?;
220+
let repo = git.path().repo_root_display()?;
221221
let repo = repo
222222
.parent()
223223
.ok_or_else(|| miette!("Repository path has no parent: {repo}"))?;

src/git/path.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,32 @@ where
3232
Self(git)
3333
}
3434

35-
/// If in a working tree, get the repository root (`git rev-parse --show-toplevel`). If the
36-
/// repository is bare, get the `.git` directory (`git rev-parse --git-dir`). Otherwise, error.
35+
/// Get the path of the repository root, for display purposes only.
36+
///
37+
/// If in a working tree, get the repository root (`git rev-parse --show-toplevel`).
38+
///
39+
/// If the repository is bare, get the `.git` directory (`git rev-parse --git-dir`):
40+
/// - If it's named `.git`, get its parent.
41+
/// - Otherwise, return it directly.
42+
///
43+
/// Otherwise, error.
3744
#[instrument(level = "trace")]
38-
pub fn repo_root_or_git_common_dir_if_bare(&self) -> miette::Result<Utf8PathBuf> {
45+
pub fn repo_root_display(&self) -> miette::Result<Utf8PathBuf> {
3946
if self.0.worktree().is_inside()? {
4047
self.0.worktree().root()
4148
} else if self.0.config().is_bare()? {
42-
self.git_common_dir()
49+
let git_dir = self.git_common_dir()?;
50+
let git_dir_basename = git_dir
51+
.file_name()
52+
.ok_or_else(|| miette!("Git directory has no basename: {git_dir}"))?;
53+
if git_dir_basename == ".git" {
54+
Ok(git_dir
55+
.parent()
56+
.ok_or_else(|| miette!("Git directory has no parent: {git_dir}"))?
57+
.to_owned())
58+
} else {
59+
Ok(git_dir)
60+
}
4361
} else {
4462
Err(miette!(
4563
"Path is not in a working tree or a bare repository: {}",

0 commit comments

Comments
 (0)