Skip to content

Commit

Permalink
Support repositories with the worktreeConfig extension
Browse files Browse the repository at this point in the history
Allows the use of git worktrees together with sparse-checkout.
In order for git2 to open such repositories, we need to tell it
that we support the worktreeConfig extension.

Fixes starship#3245

This commit requires rust-lang/git2-rs#791
  • Loading branch information
knutwalker committed Mar 30, 2022
1 parent 8bacde7 commit 46d9513
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ impl<'a> Context<'a> {
/// Will lazily get repo root and branch when a module requests it.
pub fn get_repo(&self) -> Result<&Repo, git2::Error> {
self.repo.get_or_try_init(|| -> Result<Repo, git2::Error> {
// git2 matches the extensions in normalized lowercase versions
// In order to support `worktreeConfig` we must provide `worktreeconfig`
// SAFETY: OnceCell makes sure that this is called only once and never in parallel
unsafe { git2::opts::set_extensions(&["worktreeconfig"]) }?;
let repository = if env::var("GIT_DIR").is_ok() {
Repository::open_from_env()
} else {
Expand Down

0 comments on commit 46d9513

Please sign in to comment.