summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers/helpers/worktree_helper.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/controllers/helpers/worktree_helper.go')
-rw-r--r--pkg/gui/controllers/helpers/worktree_helper.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go
index db59b1afe..bebf2cc66 100644
--- a/pkg/gui/controllers/helpers/worktree_helper.go
+++ b/pkg/gui/controllers/helpers/worktree_helper.go
@@ -3,7 +3,9 @@ package helpers
import (
"errors"
"io/fs"
+ "log"
"os"
+ "path/filepath"
"strings"
"github.com/jesseduffield/gocui"
@@ -263,3 +265,38 @@ func (self *WorktreeHelper) ViewBranchWorktreeOptions(branchName string, canChec
},
})
}
+
+func (self *WorktreeHelper) GetCurrentRepoName() string {
+ pwd, err := os.Getwd()
+ if err != nil {
+ log.Fatalln(err.Error())
+ }
+
+ // check if .git is a file or a directory
+ gitPath := filepath.Join(pwd, ".git")
+ gitFileInfo, err := os.Stat(gitPath)
+ if err != nil {
+ log.Fatalln(err.Error())
+ }
+
+ // must be a worktree or bare repo
+ if !gitFileInfo.IsDir() {
+ worktreeGitPath, ok := git_commands.WorktreeGitPath(pwd)
+ if !ok {
+ return basePath()
+ }
+
+ // now we just jump up three directories to get the repo name
+ return filepath.Base(filepath.Dir(filepath.Dir(filepath.Dir(worktreeGitPath))))
+ }
+
+ return basePath()
+}
+
+func basePath() string {
+ pwd, err := os.Getwd()
+ if err != nil {
+ log.Fatalln(err.Error())
+ }
+ return filepath.Base(pwd)
+}