feat(git): allow to exclude repo's from status fetching

This commit is contained in:
Jan De Dobbeleer 2023-01-26 15:56:47 +01:00 committed by Jan De Dobbeleer
parent 4033c6f591
commit 51fd45dc60
5 changed files with 111 additions and 29 deletions

View file

@ -777,6 +777,10 @@ func (env *Shell) DirMatchesOneOf(dir string, regexes []string) (match bool) {
}
func dirMatchesOneOf(dir, home, goos string, regexes []string) bool {
if len(regexes) == 0 {
return false
}
if goos == WINDOWS {
dir = strings.ReplaceAll(dir, "\\", "/")
home = strings.ReplaceAll(home, "\\", "/")

View file

@ -53,6 +53,8 @@ func (s *GitStatus) add(code string) {
const (
// FetchStatus fetches the status of the repository
FetchStatus properties.Property = "fetch_status"
// IgnoreStatus allows to ignore certain repo's for status information
IgnoreStatus properties.Property = "ignore_status"
// FetchStashCount fetches the stash count
FetchStashCount properties.Property = "fetch_stash_count"
// FetchWorktreeCount fetches the worktree count
@ -161,6 +163,9 @@ func (g *Git) Enabled() bool {
}
displayStatus := g.props.GetBool(FetchStatus, false)
if g.shouldIgnoreStatus() {
displayStatus = false
}
if displayStatus {
g.setGitStatus()
g.setGitHEADContext()
@ -357,6 +362,11 @@ func (g *Git) hasWorktree(gitdir *platform.FileInfo) bool {
return false
}
func (g *Git) shouldIgnoreStatus() bool {
list := g.props.GetStringArray(IgnoreStatus, []string{})
return g.env.DirMatchesOneOf(g.realDir, list)
}
func (g *Git) setBranchStatus() {
getBranchStatus := func() string {
if g.Ahead > 0 && g.Behind > 0 {

View file

@ -14,6 +14,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/stretchr/testify/assert"
mock2 "github.com/stretchr/testify/mock"
)
const (
@ -52,6 +53,7 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
env.On("PathSeparator").Return("/")
env.On("Home").Return("/Users/posh")
env.On("Getenv", poshGitEnv).Return("")
env.On("DirMatchesOneOf", mock2.Anything, mock2.Anything).Return(false)
g := &Git{
scm: scm{
env: env,

View file

@ -82,7 +82,12 @@
"type": "string",
"title": "Display Mode",
"description": "Determines whether the segment is displayed always or only if a file matching the extensions are present in the current folder",
"enum": ["always", "files", "environment", "context"],
"enum": [
"always",
"files",
"environment",
"context"
],
"default": "context"
},
"missing_command_text": {
@ -134,7 +139,11 @@
}
},
"then": {
"required": ["type", "alignment", "segments"],
"required": [
"type",
"alignment",
"segments"
],
"title": "Prompt definition, contains 1 or more segments to render"
}
},
@ -147,7 +156,10 @@
}
},
"then": {
"required": ["type", "segments"],
"required": [
"type",
"segments"
],
"title": "RPrompt definition, contains 1 or more segments to render to the right of the cursor"
}
},
@ -168,7 +180,10 @@
"type": "string",
"title": "Block overflow",
"description": "https://ohmyposh.dev/docs/configuration/block#overflow",
"enum": ["break", "hide"],
"enum": [
"break",
"hide"
],
"default": ""
}
}
@ -180,14 +195,20 @@
"type": "string",
"title": "Block type",
"description": "https://ohmyposh.dev/docs/configuration/block#type",
"enum": ["prompt", "rprompt"],
"enum": [
"prompt",
"rprompt"
],
"default": "prompt"
},
"alignment": {
"type": "string",
"title": "Block alignment",
"description": "https://ohmyposh.dev/docs/configuration/block#alignment",
"enum": ["left", "right"],
"enum": [
"left",
"right"
],
"default": "left"
},
"newline": {
@ -212,7 +233,10 @@
"title": "A segment",
"description": "https://ohmyposh.dev/docs/configuration/segment",
"default": {},
"required": ["type", "style"],
"required": [
"type",
"style"
],
"properties": {
"type": {
"type": "string",
@ -288,7 +312,12 @@
"description": "https://ohmyposh.dev/docs/configuration/segment#style",
"anyOf": [
{
"enum": ["plain", "powerline", "diamond", "accordion"]
"enum": [
"plain",
"powerline",
"diamond",
"accordion"
]
},
{
"type": "string"
@ -323,20 +352,23 @@
"type": "string",
"title": "Templates Logic",
"description": "https://ohmyposh.dev/docs/configuration/segment#templates",
"enum": ["first_match", "join"]
"enum": [
"first_match",
"join"
]
},
"max_cols": {
"type": "integer",
"title": "if the terminal width exceeds this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#max_cols",
"default": 0
},
"min_cols": {
"type": "integer",
"title": "if the terminal width is inferior than this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#min_cols",
"default": 0
},
"max_cols": {
"type": "integer",
"title": "if the terminal width exceeds this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#max_cols",
"default": 0
},
"min_cols": {
"type": "integer",
"title": "if the terminal width is inferior than this value, the segment will be hidden",
"description": "https://ohmyposh.dev/docs/configuration/segment#min_cols",
"default": 0
},
"properties": {
"type": "object",
"title": "Segment Properties, used to change behavior/displaying",
@ -503,7 +535,11 @@
"title": "Source",
"description": "https://ohmyposh.dev/docs/az#properties",
"default": "first_match",
"enum": ["first_match", "cli", "pwsh"]
"enum": [
"first_match",
"cli",
"pwsh"
]
}
}
}
@ -945,6 +981,15 @@
"title": "Ignore submodules",
"description": "Ignore changes to submodules when looking for changes",
"default": {}
},
"ignore_status": {
"type": "array",
"title": "Ignore fetching status in these repo's",
"description": "Ignore fetching status for certain repo's, uses the same logic as the exclude_folders property",
"default": [],
"items": {
"type": "string"
}
}
}
}
@ -2016,7 +2061,11 @@
"title": "units",
"description": "Units of measurement. Available values are standard (kelvin), metric (celsius), and imperial (fahrenheit). Default is standard",
"default": "standard",
"enum": ["standard", "metric", "imperial"]
"enum": [
"standard",
"metric",
"imperial"
]
},
"http_timeout": {
"$ref": "#/definitions/http_timeout"
@ -2631,7 +2680,11 @@
"type": "string",
"title": "Use Stack GHC",
"description": "Get the GHC version used by Stack. Will decrease performance. Boolean indicating whether stack ghc was used available in template as .StackGhc",
"enum": ["always", "package", "never"],
"enum": [
"always",
"package",
"never"
],
"default": "never"
}
}
@ -2818,7 +2871,10 @@
"type": "string",
"title": "Preferred Executable",
"description": "The preferred executable to use when fetching the version.",
"enum": ["lua", "luajit"],
"enum": [
"lua",
"luajit"
],
"default": "lua"
}
}
@ -2941,7 +2997,9 @@
{
"if": {
"properties": {
"type": { "const": "gitversion" }
"type": {
"const": "gitversion"
}
}
},
"then": {
@ -2952,7 +3010,9 @@
{
"if": {
"properties": {
"type": { "const": "mercurial" }
"type": {
"const": "mercurial"
}
}
},
"then": {
@ -2975,7 +3035,9 @@
]
}
},
"required": ["blocks"],
"required": [
"blocks"
],
"properties": {
"final_space": {
"type": "boolean",
@ -3027,7 +3089,9 @@
}
}
},
"required": ["tips"]
"required": [
"tips"
]
}
},
"transient_prompt": {

View file

@ -70,6 +70,7 @@ You can set the following properties to `true` to enable fetching additional inf
| Name | Type | Description |
| --------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `fetch_status` | `boolean` | fetch the local changes - defaults to `false` |
| `ignore_status` | `[]string` | do not fetch status for these repo's. Uses the repo's root folder and same logic as the [exclude_folders][exclude_folders] property |
| `fetch_upstream_icon` | `boolean` | fetch upstream icon - defaults to `false` |
| `fetch_bare_info` | `boolean` | fetch bare repo info - defaults to `false` |
| `untracked_modes` | `map[string]string` | map of repo's where to override the default [untracked files mode][untracked]:<ul><li>`no`</li><li>`normal`</li><li>`all`</li></ul>For example `"untracked_modes": { "/Users/me/repos/repo1": "no" }` - defaults to `normal` for all repo's. If you want to override for all repo's, use `*` to set the mode instead of the repo path |
@ -191,3 +192,4 @@ Local changes use the following syntax:
[submodules]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---ignore-submodulesltwhengt
[kraken-ref]: https://www.gitkraken.com/invite/nQmDPR9D
[text]: text.mdx
[exclude_folders]: /docs/configuration/segment#include--exclude-folders