From e0b28bd2c456001cd12a53fc402459e64e415bea Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 12 Oct 2022 20:08:45 +0200 Subject: [PATCH] feat(git): disable bare repo's by default relates to #2913 --- src/segments/git.go | 5 +++++ src/segments/git_test.go | 6 ++++-- themes/schema.json | 6 ++++++ website/docs/segments/git.mdx | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/segments/git.go b/src/segments/git.go index 0a24154e..1a2abd20 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -44,6 +44,8 @@ const ( FetchWorktreeCount properties.Property = "fetch_worktree_count" // FetchUpstreamIcon fetches the upstream icon FetchUpstreamIcon properties.Property = "fetch_upstream_icon" + // FetchBareInfo fetches the bare repo status + FetchBareInfo properties.Property = "fetch_bare_info" // BranchIcon the icon to use as branch indicator BranchIcon properties.Property = "branch_icon" @@ -182,6 +184,9 @@ func (g *Git) shouldDisplay() bool { gitdir, err := g.env.HasParentFilePath(".git") if err != nil { + if !g.props.GetBool(FetchBareInfo, false) { + return false + } g.realDir = g.env.Pwd() bare := g.getGitCommandOutput("rev-parse", "--is-bare-repository") if bare == "true" { diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 5d00bab6..ca26fd4d 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -177,8 +177,10 @@ func TestEnabledInBareRepo(t *testing.T) { env.On("FileContent", "/home/user/bare.git/HEAD").Return(tc.HEAD) g := &Git{ scm: scm{ - env: env, - props: properties.Map{}, + env: env, + props: properties.Map{ + FetchBareInfo: true, + }, }, } assert.Equal(t, g.Enabled(), tc.ExpectedEnabled, tc.Case) diff --git a/themes/schema.json b/themes/schema.json index 4ba053cf..32b96691 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -799,6 +799,12 @@ "description": "Display upstream icon or not", "default": false }, + "fetch_bare_info": { + "type": "boolean", + "title": "Fetch info when in a bare repo", + "description": "Fetch info when in a bare repo or not", + "default": false + }, "branch_icon": { "type": "string", "title": "Branch Icon", diff --git a/website/docs/segments/git.mdx b/website/docs/segments/git.mdx index d6ca03fe..e30d893c 100644 --- a/website/docs/segments/git.mdx +++ b/website/docs/segments/git.mdx @@ -73,6 +73,7 @@ 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` | +| `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]: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 | | `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 | | `native_fallback` | `boolean` | when set to `true` and `git.exe` is not available when inside a WSL2 shared Windows drive, we will fallback to the native git executable to fetch data. Not all information can be displayed in this case. Defaults to `false` | @@ -142,7 +143,7 @@ You can set the following properties to `true` to enable fetching additional inf | `.StashCount` | `int` | the stash count | | `.WorktreeCount` | `int` | the worktree count | | `.IsWorkTree` | `boolean` | if in a worktree repo or not | -| `.IsBare` | `boolean` | if in a bare repo or not | +| `.IsBare` | `boolean` | if in a bare repo or not, only set when `fetch_bare_info` is set to `true` | | `.Dir` | `string` | the repository's root directory | | `.Kraken` | `string` | a link to the current HEAD in [GitKraken][kraken-ref] for use in [hyperlinks][hyperlinks] in templates `{{ url .HEAD .Kraken }}` |