mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
dc851fcf53
commit
718ce22682
|
@ -98,6 +98,8 @@ const (
|
||||||
GitIcon properties.Property = "git_icon"
|
GitIcon properties.Property = "git_icon"
|
||||||
// UntrackedModes list the optional untracked files mode per repo
|
// UntrackedModes list the optional untracked files mode per repo
|
||||||
UntrackedModes properties.Property = "untracked_modes"
|
UntrackedModes properties.Property = "untracked_modes"
|
||||||
|
// IgnoreSubmodules list the optional ignore-submodules mode per repo
|
||||||
|
IgnoreSubmodules properties.Property = "ignore_submodules"
|
||||||
|
|
||||||
DETACHED = "(detached)"
|
DETACHED = "(detached)"
|
||||||
BRANCHPREFIX = "ref: refs/heads/"
|
BRANCHPREFIX = "ref: refs/heads/"
|
||||||
|
@ -266,7 +268,12 @@ func (g *Git) setGitStatus() {
|
||||||
g.Working = &GitStatus{}
|
g.Working = &GitStatus{}
|
||||||
g.Staging = &GitStatus{}
|
g.Staging = &GitStatus{}
|
||||||
untrackedMode := g.getUntrackedFilesMode()
|
untrackedMode := g.getUntrackedFilesMode()
|
||||||
output := g.getGitCommandOutput("status", untrackedMode, "--branch", "--porcelain=2")
|
args := []string{"status", untrackedMode, "--branch", "--porcelain=2"}
|
||||||
|
ignoreSubmodulesMode := g.getIgnoreSubmodulesMode()
|
||||||
|
if len(ignoreSubmodulesMode) > 0 {
|
||||||
|
args = append(args, ignoreSubmodulesMode)
|
||||||
|
}
|
||||||
|
output := g.getGitCommandOutput(args...)
|
||||||
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]
|
||||||
|
@ -516,8 +523,15 @@ func (g *Git) getOriginURL(upstream string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Git) getUntrackedFilesMode() string {
|
func (g *Git) getUntrackedFilesMode() string {
|
||||||
mode := "normal"
|
return g.getSwitchMode(UntrackedModes, "-u", "normal")
|
||||||
repoModes := g.props.GetKeyValueMap(UntrackedModes, map[string]string{})
|
}
|
||||||
|
|
||||||
|
func (g *Git) getIgnoreSubmodulesMode() string {
|
||||||
|
return g.getSwitchMode(IgnoreSubmodules, "--ignore-submodules=", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Git) getSwitchMode(property properties.Property, gitSwitch, mode string) string {
|
||||||
|
repoModes := g.props.GetKeyValueMap(property, map[string]string{})
|
||||||
// make use of a wildcard for all repo's
|
// make use of a wildcard for all repo's
|
||||||
if val := repoModes["*"]; len(val) != 0 {
|
if val := repoModes["*"]; len(val) != 0 {
|
||||||
mode = val
|
mode = val
|
||||||
|
@ -526,5 +540,8 @@ func (g *Git) getUntrackedFilesMode() string {
|
||||||
if val := repoModes[g.realFolder]; len(val) != 0 {
|
if val := repoModes[g.realFolder]; len(val) != 0 {
|
||||||
mode = val
|
mode = val
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("-u%s", mode)
|
if len(mode) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s", gitSwitch, mode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -810,3 +810,45 @@ func TestGitUntrackedMode(t *testing.T) {
|
||||||
assert.Equal(t, tc.Expected, got, tc.Case)
|
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitIgnoreSubmodules(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
Case string
|
||||||
|
Expected string
|
||||||
|
IgnoreSubmodules map[string]string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Case: "Overide",
|
||||||
|
Expected: "--ignore-submodules=all",
|
||||||
|
IgnoreSubmodules: map[string]string{
|
||||||
|
"foo": "all",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "Default mode - empty",
|
||||||
|
IgnoreSubmodules: map[string]string{
|
||||||
|
"bar": "no",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Case: "Global mode",
|
||||||
|
Expected: "--ignore-submodules=dirty",
|
||||||
|
IgnoreSubmodules: map[string]string{
|
||||||
|
"*": "dirty",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
g := &Git{
|
||||||
|
scm: scm{
|
||||||
|
props: properties.Map{
|
||||||
|
IgnoreSubmodules: tc.IgnoreSubmodules,
|
||||||
|
},
|
||||||
|
realFolder: "foo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
got := g.getIgnoreSubmodulesMode()
|
||||||
|
assert.Equal(t, tc.Expected, got, tc.Case)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -786,6 +786,12 @@
|
||||||
"title": "Untracked files mode",
|
"title": "Untracked files mode",
|
||||||
"description": "Set the untracked files mode for a repository",
|
"description": "Set the untracked files mode for a repository",
|
||||||
"default": {}
|
"default": {}
|
||||||
|
},
|
||||||
|
"ignore_submodules": {
|
||||||
|
"type": "object",
|
||||||
|
"title": "Ignore submodules",
|
||||||
|
"description": "Ignore changes to submodules when looking for changes",
|
||||||
|
"default": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,9 +66,12 @@ 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: `map[string]string` - map of repo's where to override the default [untracked files mode][untracked] (`no` | `normal` | `all`). 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
|
`"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.
|
`*` to set the mode instead of the repo path.
|
||||||
|
- ignore_submodules: `map[string]string` - map of repo's where to change the [--ignore-submodules][submodules] flag (`none`, `untracked`, `dirty` or `all`).
|
||||||
|
For example `"ignore_submodules": { "/Users/me/repos/repo1": "all" }`. If you want to override for all repo's, use `*` to set the mode
|
||||||
|
instead of the repo path.
|
||||||
|
|
||||||
### Icons
|
### Icons
|
||||||
|
|
||||||
|
@ -138,3 +141,5 @@ You can set the following properties to `true` to enable fetching additional inf
|
||||||
[poshgit]: /docs/segments/poshgit
|
[poshgit]: /docs/segments/poshgit
|
||||||
[templates]: /docs/configuration/templates
|
[templates]: /docs/configuration/templates
|
||||||
[hyperlinks]: /docs/configuration/templates#helper-functions
|
[hyperlinks]: /docs/configuration/templates#helper-functions
|
||||||
|
[untracked]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---untracked-filesltmodegt
|
||||||
|
[submodules]: https://git-scm.com/docs/git-status#Documentation/git-status.txt---ignore-submodulesltwhengt
|
||||||
|
|
Loading…
Reference in a new issue