diff --git a/docs/docs/segments/git.mdx b/docs/docs/segments/git.mdx index 361e7de8..f06d54cd 100644 --- a/docs/docs/segments/git.mdx +++ b/docs/docs/segments/git.mdx @@ -46,7 +46,10 @@ An alternative is to use the [Posh-Git segment][poshgit] "properties": { "fetch_status": 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_worktree_count: `boolean` fetch worktree count - 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 diff --git a/src/segments/git.go b/src/segments/git.go index 1f4c7b82..d4582c7c 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -103,6 +103,8 @@ const ( GitlabIcon properties.Property = "gitlab_icon" // GitIcon shows when the upstream can't be identified GitIcon properties.Property = "git_icon" + // UntrackedModes list the optional untracked files mode per repo + UntrackedModes properties.Property = "untracked_modes" DETACHED = "(detached)" BRANCHPREFIX = "ref: refs/heads/" @@ -269,7 +271,8 @@ func (g *Git) setGitStatus() { g.UpstreamGone = true g.Working = &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") { if strings.HasPrefix(line, HASH) && len(line) >= 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) } + +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) +} diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 26bdd99e..254430c1 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -465,7 +465,8 @@ func TestSetGitStatus(t *testing.T) { env.MockGitCommand("", strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2") g := &Git{ scm: scm{ - env: env, + env: env, + props: properties.Map{}, }, } 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) } } + +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) + } +} diff --git a/themes/schema.json b/themes/schema.json index 49a54309..c377a308 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -615,6 +615,12 @@ "title": "Branch max length", "description": "the max length for the displayed branch name where 0 implies full length", "default": 0 + }, + "untracked_modes": { + "type": "object", + "title": "Untracked files mode", + "description": "Set the untracked files mode for a repository", + "default": {} } } }