File tree 2 files changed +23
-8
lines changed
2 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -217,10 +217,7 @@ where
217
217
// - `convert_bare_dot_git`
218
218
// - `convert_bare_dot_git_from_parent`
219
219
// - `convert_common_parent`
220
- let repo = git. path ( ) . repo_root_or_git_common_dir_if_bare ( ) ?;
221
- let repo = repo
222
- . parent ( )
223
- . ok_or_else ( || miette ! ( "Repository path has no parent: {repo}" ) ) ?;
220
+ let repo = git. path ( ) . repo_root_display ( ) ?;
224
221
let worktrees = git. worktree ( ) . list ( ) ?;
225
222
226
223
let destination = Self :: destination_plan ( & worktrees, & opts) ?;
Original file line number Diff line number Diff line change @@ -32,14 +32,32 @@ where
32
32
Self ( git)
33
33
}
34
34
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.
37
44
#[ 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 > {
39
46
if self . 0 . worktree ( ) . is_inside ( ) ? {
40
47
self . 0 . worktree ( ) . root ( )
41
48
} 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
+ }
43
61
} else {
44
62
Err ( miette ! (
45
63
"Path is not in a working tree or a bare repository: {}" ,
You can’t perform that action at this time.
0 commit comments