Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,7 @@ where
// - `convert_bare_dot_git`
// - `convert_bare_dot_git_from_parent`
// - `convert_common_parent`
let repo = git.path().repo_root_or_git_common_dir_if_bare()?;
let repo = repo
.parent()
.ok_or_else(|| miette!("Repository path has no parent: {repo}"))?;
let repo = git.path().repo_root_display()?;
let worktrees = git.worktree().list()?;

let destination = Self::destination_plan(&worktrees, &opts)?;
Expand Down
26 changes: 22 additions & 4 deletions src/git/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,32 @@ where
Self(git)
}

/// If in a working tree, get the repository root (`git rev-parse --show-toplevel`). If the
/// repository is bare, get the `.git` directory (`git rev-parse --git-dir`). Otherwise, error.
/// Get the path of the repository root, for display purposes only.
///
/// If in a working tree, get the repository root (`git rev-parse --show-toplevel`).
///
/// If the repository is bare, get the `.git` directory (`git rev-parse --git-dir`):
/// - If it's named `.git`, get its parent.
/// - Otherwise, return it directly.
///
/// Otherwise, error.
#[instrument(level = "trace")]
pub fn repo_root_or_git_common_dir_if_bare(&self) -> miette::Result<Utf8PathBuf> {
pub fn repo_root_display(&self) -> miette::Result<Utf8PathBuf> {
if self.0.worktree().is_inside()? {
self.0.worktree().root()
} else if self.0.config().is_bare()? {
self.git_common_dir()
let git_dir = self.git_common_dir()?;
let git_dir_basename = git_dir
.file_name()
.ok_or_else(|| miette!("Git directory has no basename: {git_dir}"))?;
if git_dir_basename == ".git" {
Ok(git_dir
.parent()
.ok_or_else(|| miette!("Git directory has no parent: {git_dir}"))?
.to_owned())
} else {
Ok(git_dir)
}
} else {
Err(miette!(
"Path is not in a working tree or a bare repository: {}",
Expand Down
Loading