Skip to content

Commit 0b1d01a

Browse files
committed
Revert this stuff.
1 parent 9306b05 commit 0b1d01a

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

dir/dir.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dir
22

33
import (
4+
"strings"
5+
46
"github.com/joshmedeski/sesh/v2/git"
57
"github.com/joshmedeski/sesh/v2/oswrap"
68
"github.com/joshmedeski/sesh/v2/pathwrap"
@@ -39,12 +41,38 @@ func (d *RealDir) Dir(path string) (isDir bool, absPath string) {
3941
}
4042

4143
func (d *RealDir) RootDir(path string) (hasRootDir bool, absPath string) {
42-
isGit, absPath, err := d.git.GitRoot(path)
43-
if err != nil {
44-
return false, ""
44+
isGitBare, absPath := gitBareRootDir(d, path)
45+
if isGitBare {
46+
return true, absPath
4547
}
48+
isGit, absPath := gitRootDir(d, path)
4649
if isGit {
4750
return true, absPath
4851
}
4952
return false, ""
5053
}
54+
55+
func gitBareRootDir(d *RealDir, path string) (hasRootDir bool, absPath string) {
56+
isGitBare, commonDir, _ := d.git.GitCommonDir(path)
57+
if isGitBare && strings.HasSuffix(commonDir, "/.bare") {
58+
topLevelDir := strings.TrimSuffix(commonDir, "/.bare")
59+
relativePath := strings.TrimPrefix(path, topLevelDir)
60+
firstDir := strings.Split(relativePath, string("/"))[1]
61+
name, err := d.path.Abs(topLevelDir + "/" + firstDir)
62+
if err != nil {
63+
return false, ""
64+
}
65+
return true, name
66+
} else {
67+
return false, ""
68+
}
69+
}
70+
71+
func gitRootDir(d *RealDir, path string) (hasDir bool, absPath string) {
72+
isGit, topLevelDir, _ := d.git.ShowTopLevel(path)
73+
if isGit && topLevelDir != "" {
74+
return true, topLevelDir
75+
} else {
76+
return false, ""
77+
}
78+
}

namer/namer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (n *RealNamer) Name(path string) (string, error) {
3535
}
3636

3737
strategies := []func(*RealNamer, string) (string, error){
38+
gitBareName,
3839
gitName,
3940
dirName,
4041
}

seshcli/root.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,24 @@ package seshcli
33
import (
44
"fmt"
55

6-
"github.com/joshmedeski/sesh/v2/git"
7-
"github.com/joshmedeski/sesh/v2/home"
8-
"github.com/joshmedeski/sesh/v2/lister"
6+
"github.com/joshmedeski/sesh/lister"
7+
"github.com/joshmedeski/sesh/namer"
98
cli "github.com/urfave/cli/v2"
109
)
1110

12-
func Root(l lister.Lister, git git.Git, home home.Home) *cli.Command {
11+
func Root(l lister.Lister, n namer.Namer) *cli.Command {
1312
return &cli.Command{
1413
Name: "root",
1514
Aliases: []string{"r"},
16-
Usage: "Show the root for the active session",
15+
Usage: "Show the root from the active session",
1716
UseShortOptionHandling: true,
1817
Flags: []cli.Flag{},
1918
Action: func(cCtx *cli.Context) error {
2019
session, exists := l.GetAttachedTmuxSession()
2120
if !exists {
22-
return cli.Exit("Not attached to tmux session", 1)
21+
return cli.Exit("No root found for session", 1)
2322
}
24-
_, path, err := git.GitRoot(session.Path)
25-
if err != nil {
26-
return cli.Exit(err, 1)
27-
}
28-
root, err := home.ShortenHome(path)
23+
root, err := n.RootName(session.Path)
2924
if err != nil {
3025
return cli.Exit(err, 1)
3126
}

seshcli/seshcli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func App(version string) cli.App {
7676
Last(lister, tmux),
7777
Connect(connector, icon, dir),
7878
Clone(cloner),
79-
Root(lister, git, home),
79+
Root(lister, namer),
8080
Preview(previewer),
8181
},
8282
}

0 commit comments

Comments
 (0)