mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
feat(git): expose repo name
This commit is contained in:
parent
75cf1b2005
commit
37a4c3eb4e
|
@ -2,6 +2,7 @@ package segments
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"oh-my-posh/environment"
|
||||||
"oh-my-posh/properties"
|
"oh-my-posh/properties"
|
||||||
"oh-my-posh/regex"
|
"oh-my-posh/regex"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -50,6 +51,7 @@ type Git struct {
|
||||||
StashCount int
|
StashCount int
|
||||||
WorktreeCount int
|
WorktreeCount int
|
||||||
IsWorkTree bool
|
IsWorkTree bool
|
||||||
|
RepoName string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -114,6 +116,7 @@ func (g *Git) Enabled() bool {
|
||||||
if !g.shouldDisplay() {
|
if !g.shouldDisplay() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
g.RepoName = environment.Base(g.env, g.realFolder)
|
||||||
displayStatus := g.props.GetBool(FetchStatus, false)
|
displayStatus := g.props.GetBool(FetchStatus, false)
|
||||||
if displayStatus {
|
if displayStatus {
|
||||||
g.setGitStatus()
|
g.setGitStatus()
|
||||||
|
|
|
@ -44,6 +44,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
|
||||||
env.MockGitCommand(fileInfo.Path, "", "describe", "--tags", "--exact-match")
|
env.MockGitCommand(fileInfo.Path, "", "describe", "--tags", "--exact-match")
|
||||||
env.On("IsWsl").Return(false)
|
env.On("IsWsl").Return(false)
|
||||||
env.On("HasParentFilePath", ".git").Return(fileInfo, nil)
|
env.On("HasParentFilePath", ".git").Return(fileInfo, nil)
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
g := &Git{
|
g := &Git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
@ -60,6 +61,7 @@ func TestEnabledInWorkingTree(t *testing.T) {
|
||||||
env.On("HasCommand", "git").Return(true)
|
env.On("HasCommand", "git").Return(true)
|
||||||
env.On("GOOS").Return("")
|
env.On("GOOS").Return("")
|
||||||
env.On("IsWsl").Return(false)
|
env.On("IsWsl").Return(false)
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
fileInfo := &environment.FileInfo{
|
fileInfo := &environment.FileInfo{
|
||||||
Path: "/dev/folder_worktree/.git",
|
Path: "/dev/folder_worktree/.git",
|
||||||
ParentFolder: "/dev/folder_worktree",
|
ParentFolder: "/dev/folder_worktree",
|
||||||
|
@ -87,6 +89,7 @@ func TestEnabledInSubmodule(t *testing.T) {
|
||||||
env.On("HasCommand", "git").Return(true)
|
env.On("HasCommand", "git").Return(true)
|
||||||
env.On("GOOS").Return("")
|
env.On("GOOS").Return("")
|
||||||
env.On("IsWsl").Return(false)
|
env.On("IsWsl").Return(false)
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
fileInfo := &environment.FileInfo{
|
fileInfo := &environment.FileInfo{
|
||||||
Path: "/dev/parent/test-submodule/.git",
|
Path: "/dev/parent/test-submodule/.git",
|
||||||
ParentFolder: "/dev/parent/test-submodule",
|
ParentFolder: "/dev/parent/test-submodule",
|
||||||
|
@ -115,6 +118,7 @@ func TestEnabledInSeparateGitDir(t *testing.T) {
|
||||||
env.On("HasCommand", "git").Return(true)
|
env.On("HasCommand", "git").Return(true)
|
||||||
env.On("GOOS").Return("")
|
env.On("GOOS").Return("")
|
||||||
env.On("IsWsl").Return(false)
|
env.On("IsWsl").Return(false)
|
||||||
|
env.On("PathSeparator").Return("/")
|
||||||
fileInfo := &environment.FileInfo{
|
fileInfo := &environment.FileInfo{
|
||||||
Path: "/dev/parent/test-separate-git-dir/.git",
|
Path: "/dev/parent/test-separate-git-dir/.git",
|
||||||
ParentFolder: "/dev/parent/test-separate-git-dir",
|
ParentFolder: "/dev/parent/test-separate-git-dir",
|
||||||
|
|
|
@ -115,6 +115,7 @@ instead of the repo path.
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
||||||
|
- `.RepoName`: `string` - the repo folder name
|
||||||
- `.Working`: `GitStatus` - changes in the worktree (see below)
|
- `.Working`: `GitStatus` - changes in the worktree (see below)
|
||||||
- `.Staging`: `GitStatus` - staged changes in the work tree (see below)
|
- `.Staging`: `GitStatus` - staged changes in the work tree (see below)
|
||||||
- `.HEAD`: `string` - the current HEAD context (branch/rebase/merge/...)
|
- `.HEAD`: `string` - the current HEAD context (branch/rebase/merge/...)
|
||||||
|
|
Loading…
Reference in a new issue