mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
09a4489216
commit
bcf7d59e83
|
@ -46,7 +46,10 @@ An alternative is to use the [Posh-Git segment][poshgit]
|
||||||
"properties": {
|
"properties": {
|
||||||
"fetch_status": true,
|
"fetch_status": true,
|
||||||
"fetch_stash_count": true,
|
"fetch_stash_count": true,
|
||||||
"fetch_upstream_icon": true
|
"fetch_upstream_icon": true,
|
||||||
|
"untracked_modes": {
|
||||||
|
"/Users/user/Projects/oh-my-posh/": "no"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -62,6 +65,8 @@ You can set the following properties to `true` to enable fetching additional inf
|
||||||
- fetch_stash_count: `boolean` fetch stash count - defaults to `false`
|
- fetch_stash_count: `boolean` fetch stash count - defaults to `false`
|
||||||
- fetch_worktree_count: `boolean` fetch worktree count - defaults to `false`
|
- fetch_worktree_count: `boolean` fetch worktree count - defaults to `false`
|
||||||
- fetch_upstream_icon: `boolean` - fetch upstream icon - defaults to `false`
|
- fetch_upstream_icon: `boolean` - fetch upstream icon - defaults to `false`
|
||||||
|
- untracked_modes: `map[string]string` - map of repo's where to override the default untracked mode (`no` | `normal` | `all`). For example
|
||||||
|
`"untracked_modes": { "/Users/me/repos/repo1": "no" }` - defaults to `normal` for all repo's
|
||||||
|
|
||||||
### Icons
|
### Icons
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,8 @@ const (
|
||||||
GitlabIcon properties.Property = "gitlab_icon"
|
GitlabIcon properties.Property = "gitlab_icon"
|
||||||
// GitIcon shows when the upstream can't be identified
|
// GitIcon shows when the upstream can't be identified
|
||||||
GitIcon properties.Property = "git_icon"
|
GitIcon properties.Property = "git_icon"
|
||||||
|
// UntrackedModes list the optional untracked files mode per repo
|
||||||
|
UntrackedModes properties.Property = "untracked_modes"
|
||||||
|
|
||||||
DETACHED = "(detached)"
|
DETACHED = "(detached)"
|
||||||
BRANCHPREFIX = "ref: refs/heads/"
|
BRANCHPREFIX = "ref: refs/heads/"
|
||||||
|
@ -269,7 +271,8 @@ func (g *Git) setGitStatus() {
|
||||||
g.UpstreamGone = true
|
g.UpstreamGone = true
|
||||||
g.Working = &GitStatus{}
|
g.Working = &GitStatus{}
|
||||||
g.Staging = &GitStatus{}
|
g.Staging = &GitStatus{}
|
||||||
output := g.getGitCommandOutput("status", "-unormal", "--branch", "--porcelain=2")
|
untrackedMode := g.getUntrackedFilesMode()
|
||||||
|
output := g.getGitCommandOutput("status", untrackedMode, "--branch", "--porcelain=2")
|
||||||
for _, line := range strings.Split(output, "\n") {
|
for _, line := range strings.Split(output, "\n") {
|
||||||
if strings.HasPrefix(line, HASH) && len(line) >= len(HASH)+7 {
|
if strings.HasPrefix(line, HASH) && len(line) >= len(HASH)+7 {
|
||||||
g.Hash = line[len(HASH) : len(HASH)+7]
|
g.Hash = line[len(HASH) : len(HASH)+7]
|
||||||
|
@ -542,3 +545,12 @@ func (g *Git) convertToLinuxPath(path string) string {
|
||||||
}
|
}
|
||||||
return g.env.ConvertToLinuxPath(path)
|
return g.env.ConvertToLinuxPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Git) getUntrackedFilesMode() string {
|
||||||
|
mode := "normal"
|
||||||
|
repoModes := g.props.GetKeyValueMap(UntrackedModes, map[string]string{})
|
||||||
|
if val := repoModes[g.gitRealFolder]; len(val) != 0 {
|
||||||
|
mode = val
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("-u%s", mode)
|
||||||
|
}
|
||||||
|
|
|
@ -465,7 +465,8 @@ func TestSetGitStatus(t *testing.T) {
|
||||||
env.MockGitCommand("", strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2")
|
env.MockGitCommand("", strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2")
|
||||||
g := &Git{
|
g := &Git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties.Map{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if tc.ExpectedWorking == nil {
|
if tc.ExpectedWorking == nil {
|
||||||
|
@ -761,3 +762,44 @@ func TestGitTemplateString(t *testing.T) {
|
||||||
assert.Equal(t, tc.Expected, renderTemplate(env, tc.Template, tc.Git), tc.Case)
|
assert.Equal(t, tc.Expected, renderTemplate(env, tc.Template, tc.Git), tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitUntrackedMode(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
Expected string
|
||||||
|
UntrackedModes map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Case: "Default mode - no map",
|
||||||
|
Expected: "-unormal",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "Default mode - no match",
|
||||||
|
Expected: "-unormal",
|
||||||
|
UntrackedModes: map[string]string{
|
||||||
|
"bar": "no",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "No mode - match",
|
||||||
|
Expected: "-uno",
|
||||||
|
UntrackedModes: map[string]string{
|
||||||
|
"foo": "no",
|
||||||
|
"bar": "normal",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
g := &Git{
|
||||||
|
scm: scm{
|
||||||
|
props: properties.Map{
|
||||||
|
UntrackedModes: tc.UntrackedModes,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
gitRealFolder: "foo",
|
||||||
|
}
|
||||||
|
got := g.getUntrackedFilesMode()
|
||||||
|
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -615,6 +615,12 @@
|
||||||
"title": "Branch max length",
|
"title": "Branch max length",
|
||||||
"description": "the max length for the displayed branch name where 0 implies full length",
|
"description": "the max length for the displayed branch name where 0 implies full length",
|
||||||
"default": 0
|
"default": 0
|
||||||
|
},
|
||||||
|
"untracked_modes": {
|
||||||
|
"type": "object",
|
||||||
|
"title": "Untracked files mode",
|
||||||
|
"description": "Set the untracked files mode for a repository",
|
||||||
|
"default": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue