mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: git branch: read from HEAD on newly initialized repo (#1336)
* Git branch: read from HEAD on newly init repo On a newly initialized git repo, there are no branches created until a commit is made. Previously, starship handled this by having a default branch "master" for when branch `head` could not be read. However, if a user wants to set a different default branch name, that name won't appear on starship until a commit is made to the branch. If git2 provides a way to read the default branch name, we can use that, but at the moment it's not obvious how. For the moment, we can directly read `.git/HEAD`, which contains the name of the default branch head reference. This commit implements this strategy. Closes #1327 * update git_branch test from unborn master to unborn default * cargo fmt
This commit is contained in:
@@ -100,7 +100,7 @@ fn test_japanese_truncation() -> io::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_works_with_unborn_master() -> io::Result<()> {
|
||||
fn test_works_with_unborn_default_branch() -> io::Result<()> {
|
||||
let repo_dir = tempfile::tempdir()?.into_path();
|
||||
|
||||
Command::new("git")
|
||||
@@ -108,6 +108,11 @@ fn test_works_with_unborn_master() -> io::Result<()> {
|
||||
.current_dir(&repo_dir)
|
||||
.output()?;
|
||||
|
||||
Command::new("git")
|
||||
.args(&["symbolic-ref", "HEAD", "refs/heads/main"])
|
||||
.current_dir(&repo_dir)
|
||||
.output()?;
|
||||
|
||||
let output = common::render_module("git_branch")
|
||||
.arg("--path")
|
||||
.arg(&repo_dir)
|
||||
@@ -117,7 +122,7 @@ fn test_works_with_unborn_master() -> io::Result<()> {
|
||||
|
||||
let expected = format!(
|
||||
"on {} ",
|
||||
Color::Purple.bold().paint(format!("\u{e0a0} {}", "master")),
|
||||
Color::Purple.bold().paint(format!("\u{e0a0} {}", "main")),
|
||||
);
|
||||
assert_eq!(expected, actual);
|
||||
remove_dir_all(repo_dir)
|
||||
|
||||
Reference in New Issue
Block a user