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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reset of match_ceiling_dir_or_error in apply_environment() #1191

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

kdarkhan
Copy link
Contributor

@kdarkhan kdarkhan commented Dec 18, 2023

In #721, this reset was added which makes using
ThreadSafeRepository::discover_with_environment_overrides_opts inconvenient.

If the old behaviour of match_ceiling_dir_or_error = false desired, then it can be achieved by
setting it on options just before calling apply_environment().

The inverse is not true, and ThreadSafeRepository::discover_with_environment_overrides_opts
cannot enable this flag because apply_environment overrides it.

I am not sure if this change is the best approach to accomplish what I need.
Let me know if you think it is better to change discover_with_environment_overrides_opts
so that options parameter is used as override instead of default.

In https://github.com/Byron/gitoxide/pull/721/files, this reset was
added which makes using
[ThreadSafeRepository::discover_with_environment_overrides_opts](
https://github.com/Byron/gitoxide/blob/f7adf97bc6aa2bf82f906c4463b1cbb3f9cddae3/gix/src/discover.rs#L67)
inconvenient. If the old behaviour of `match_ceiling_dir_or_error = false`
desired, then it can be achieved by setting it on `options` just
before calling `apply_environment()`.

The inverse is not true, and `ThreadSafeRepository::discover_with_environment_overrides_opts`
cannot enable this flag because `apply_environment` overrides it.
Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix of the fix :)! In hindsight I realise that hardcoding it there seems to be a mistake particularly since the value can be set by the user.

I have added a note in a separate commit that will be visible after merging, so here it is for posterity:

/// ### Note
///
/// Consider to set match_ceiling_dir_or_error = false
/// to allow discovery if an outside environment variable sets non-matching ceiling directories for greater
/// compatibility with Git.

@davidkna This change affects starship and I think the following patch can be applied right now to be safe when this trickles through with the next gix upgrade.

diff --git a/src/context.rs b/src/context.rs
index 56074469..57c6921a 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -319,7 +319,10 @@ impl<'a> Context<'a> {
                 let shared_repo =
                     match ThreadSafeRepository::discover_with_environment_overrides_opts(
                         &self.current_dir,
-                        Default::default(),
+                        gix::discover::upwards::Options {
+                            match_ceiling_dir_or_error: false,
+                            ..Default::default()
+                        },
                         git_open_opts_map,
                     ) {
                         Ok(repo) => repo,

Please do let me know if you think there were other reasons for hardcoding the value like this that aren't accounted for with this change - to me it seems sound.

@kdarkhan
Copy link
Contributor Author

Awesome, thanks.

Reason I arrived at this issue was from starship as well since I wanted the "error" behaviour.

@Byron
Copy link
Owner

Byron commented Dec 18, 2023

Oh, that's interesting! It seems then you will want to talk to @davidkna to see how it remains configurable instead of hardcoding the same in starship with the patch above. (But maybe I am misunderstanding something)

@kdarkhan
Copy link
Contributor Author

Right, I will reach out to him. I am planning to add a new config option in starship if they accept.

The reason I want to have the err case is because I want to prevent starship git discover logic execute on a slower network drive. When match_ceiling_dir_or_error = true, it will accomplish the behavior I need. I can make this behavior non-default to not break other people's workflows.

@Byron Byron merged commit 85499e4 into Byron:main Dec 18, 2023
18 checks passed
Byron added a commit that referenced this pull request Dec 18, 2023
This note should help to avoid to keep enforcing flags in places
where they can't be 'unenforced' anymore, even if it means that users
have to be aware of some necessary manual adjustments.
@kdarkhan kdarkhan deleted the match_ceiling_dir_or_error branch December 18, 2023 14:32
davidkna added a commit to davidkna/starship that referenced this pull request Dec 20, 2023
See: Byron/gitoxide#1191
Co-Authored-By: Sebastian Thiel <sebastian.thiel@icloud.com>
Byron added a commit to Byron/starship that referenced this pull request Dec 30, 2023
See: Byron/gitoxide#1191
Co-Authored-By: Sebastian Thiel <sebastian.thiel@icloud.com>
andytom pushed a commit to starship/starship that referenced this pull request Dec 31, 2023
* build(deps): update rust crate gix to 0.57.0

* chore(context): explicitly avoid erroring on no git-ceiling-dir-match

See: Byron/gitoxide#1191
Co-Authored-By: Sebastian Thiel <sebastian.thiel@icloud.com>

---------

Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
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.

None yet

2 participants