feat(git_branch): add ignore_bare_repo flag (#6936)

This commit is contained in:
Victor Campello
2025-10-21 19:10:17 +01:00
committed by GitHub
parent 5db4ea7878
commit 87b7ac342f
4 changed files with 33 additions and 1 deletions
+5
View File
@@ -574,6 +574,7 @@
"only_attached": false,
"always_show_remote": false,
"ignore_branches": [],
"ignore_bare_repo": false,
"disabled": false
}
},
@@ -3221,6 +3222,10 @@
},
"default": []
},
"ignore_bare_repo": {
"type": "boolean",
"default": false
},
"disabled": {
"type": "boolean",
"default": false
+1
View File
@@ -1847,6 +1847,7 @@ The `git_branch` module shows the active branch of the repo in your current dire
| `truncation_symbol` | `'…'` | The symbol used to indicate a branch name was truncated. You can use `''` for no symbol. |
| `only_attached` | `false` | Only show the branch name when not in a detached `HEAD` state. |
| `ignore_branches` | `[]` | A list of names to avoid displaying. Useful for 'master' or 'main'. |
| `ignore_bare_repo` | `false` | Do not show when in a bare repo. |
| `disabled` | `false` | Disables the `git_branch` module. |
### Variables
+2
View File
@@ -16,6 +16,7 @@ pub struct GitBranchConfig<'a> {
pub only_attached: bool,
pub always_show_remote: bool,
pub ignore_branches: Vec<&'a str>,
pub ignore_bare_repo: bool,
pub disabled: bool,
}
@@ -30,6 +31,7 @@ impl Default for GitBranchConfig<'_> {
only_attached: false,
always_show_remote: false,
ignore_branches: vec![],
ignore_bare_repo: false,
disabled: false,
}
}
+25 -1
View File
@@ -26,7 +26,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let repo = context.get_repo().ok()?;
if config.only_attached && repo.open().head().ok()?.is_detached() {
let gix_repo = repo.open();
if config.ignore_bare_repo && gix_repo.is_bare() {
return None;
}
if config.only_attached && gix_repo.head().ok()?.is_detached() {
return None;
}
@@ -392,6 +397,25 @@ mod tests {
repo_dir.close()
}
#[test]
fn test_ignore_bare_repo() -> io::Result<()> {
let repo_dir = fixture_repo(FixtureProvider::GitBare)?;
let actual = ModuleRenderer::new("git_branch")
.config(toml::toml! {
[git_branch]
ignore_bare_repo = true
})
.path(repo_dir.path())
.collect();
let expected = None;
assert_eq!(expected, actual);
repo_dir.close()
}
#[test]
fn test_remote() -> io::Result<()> {
let remote_dir = fixture_repo(FixtureProvider::Git)?;