Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(git_status): avoid running in bare repos #5581

Merged
merged 3 commits into from Nov 29, 2023

Conversation

wjhoward
Copy link
Contributor

@wjhoward wjhoward commented Nov 17, 2023

Description

This change adjusts the git_status module to no longer attempt to generate git_status for a bare repository as this is not possible when a repository does not have a work tree.

Motivation and Context

Currently entering a bare repository throws an error, as described in the associated issue.
Closes #5544

Screenshots (if appropriate):

When entering a bare repository the error is no longer visible:
image

How Has This Been Tested?

Locally by entering a bare repository as per the above screenshot.
You can also see the correct behaviour from the unit test output (I believe I've used the fixture correctly although not familiar with the setup):

cargo test --package starship --lib -- modules::git_status::tests::doesnt_generate_git_status_for_bare_repo --exact --nocapture
    Finished test [unoptimized + debuginfo] target(s) in 0.69s
     Running unittests src/lib.rs (target/debug/deps/starship-49403b2d84e0acbb)

running 1 test
[TRACE] - (starship::utils): Trying to read from "/Users/will/.config/starship.toml"
[TRACE] - (starship::utils): File read successfully
[TRACE] - (starship::config): Config file content: "
# ~/.config/starship.toml

[status]
style = 'bg:blue'
symbol = '馃敶 '
success_symbol = '馃煝 SUCCESS'
format = '[\[$symbol$common_meaning$signal_name$maybe_int\]]($style) '
map_symbol = true
disabled = false

"
[DEBUG] - (starship::config): Config parsed: {"status": Table({"style": String("bg:blue"), "symbol": String("馃敶 "), "success_symbol": String("馃煝 SUCCESS"), "format": String("[\\[$symbol$common_meaning$signal_name$maybe_int\\]]($style) "), "map_symbol": Boolean(true), "disabled": Boolean(false)})}
[TRACE] - (starship::context): Received completed pipestatus of None
[TRACE] - (starship::context): Found git repo: Repository { kind: Bare, git_dir: "/var/folders/zk/ctx002wn22l7tg0_rk4m_dyh0000gn/T/.tmp9ehSuN", work_dir: None }, (trust: Full)
[DEBUG] - (starship::modules::git_status): This is a bare repository, git_status is not applicable
[TRACE] - (starship::modules): Took 2.212191ms to compute module "git_status"
test modules::git_status::tests::doesnt_generate_git_status_for_bare_repo ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 1043 filtered out; finished in 0.07s
  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows

Checklist:

  • I have updated the documentation accordingly.
  • I have updated the tests accordingly.

@wjhoward wjhoward changed the title fix: git_status bare repo handling fix(git_status): bare repo handling Nov 17, 2023
src/test/mod.rs Outdated Show resolved Hide resolved
src/modules/git_status.rs Outdated Show resolved Hide resolved
@davidkna davidkna changed the title fix(git_status): bare repo handling perf(git_status): avoid running in bare repos Nov 24, 2023
@andytom andytom merged commit ac4a839 into starship:master Nov 29, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git_status throw error when not in work tree
3 participants