mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-04 20:37:56 +00:00
fix: implement fallback branch_name for bare git repos (#1035)
closes #686
This commit is contained in:
parent
b905743364
commit
8d90baf0eb
@ -30,7 +30,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let repo = context.get_repo().ok()?;
|
let repo = context.get_repo().ok()?;
|
||||||
let branch_name = repo.branch.as_ref()?;
|
// bare repos don't have a branch name, so `repo.branch.as_ref` would return None,
|
||||||
|
// but git treats "master" as the default branch name
|
||||||
|
let default_branch = String::from("master");
|
||||||
|
let branch_name = repo.branch.as_ref().unwrap_or(&default_branch);
|
||||||
let truncated_graphemes = get_graphemes(&branch_name, len);
|
let truncated_graphemes = get_graphemes(&branch_name, len);
|
||||||
// The truncation symbol should only be added if we truncated
|
// The truncation symbol should only be added if we truncated
|
||||||
let truncated_and_symbol = if len < graphemes_len(&branch_name) {
|
let truncated_and_symbol = if len < graphemes_len(&branch_name) {
|
||||||
|
@ -23,7 +23,10 @@ use std::collections::HashMap;
|
|||||||
/// - `✘` — A file's deletion has been added to the staging area
|
/// - `✘` — A file's deletion has been added to the staging area
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
let repo = context.get_repo().ok()?;
|
let repo = context.get_repo().ok()?;
|
||||||
let branch_name = repo.branch.as_ref()?;
|
// bare repos don't have a branch name, so `repo.branch.as_ref` would return None,
|
||||||
|
// but git treats "master" as the default branch name
|
||||||
|
let default_branch = String::from("master");
|
||||||
|
let branch_name = repo.branch.as_ref().unwrap_or(&default_branch);
|
||||||
let repo_root = repo.root.as_ref()?;
|
let repo_root = repo.root.as_ref()?;
|
||||||
let mut repository = Repository::open(repo_root).ok()?;
|
let mut repository = Repository::open(repo_root).ok()?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user