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

Added ability to include directories as an extension of the config file #421

Merged
merged 20 commits into from May 25, 2023

Conversation

PolpOnline
Copy link
Contributor

Standards checklist:

  • The PR title is descriptive.
  • The code compiles (cargo build)
  • The code passes rustfmt (cargo fmt)
  • The code passes clippy (cargo clippy)
  • The code passes tests (cargo test)
  • Optional: I have tested the code myself
    • I also tested that Topgrade skips the step where needed

I have tested it by myself, but I am not sure if I set all the merge behaviours correctly.
@openjck you may want to test this.

closes #405

Copy link

@Dreaming-Codes Dreaming-Codes left a comment

Choose a reason for hiding this comment

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

Overall, this is a generally good PR, but I would recommend a few minor improvements.

src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
config.example.toml Outdated Show resolved Hide resolved
@PolpOnline
Copy link
Contributor Author

PolpOnline commented May 4, 2023

Blocking this from getting merged because the commands, pre_commands and post_commands fields don't have a merge strategy yet, will surely implement it later.

@PolpOnline PolpOnline marked this pull request as draft May 4, 2023 22:57
@PolpOnline PolpOnline marked this pull request as ready for review May 5, 2023 20:12
@@ -1,3 +1,8 @@
# Include any additional configuration file(s)
# Note that this config file overrides the includes
# and includes that are on the left override the ones on the right in this array
Copy link
Contributor

@openjck openjck May 6, 2023

Choose a reason for hiding this comment

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

Thanks for your interest in this issue.

This part caught my attention. If consistency with other tools is important, it might be good to look at how other tools handle this. It's my understanding that Git, Vim, Bash, and others don't have the main configuration file take precedence. Instead, settings at the bottom of those configuration files take precedence over settings at the tops of those files, and included files are treated as though their contents are inlined.

For example, with the following setup, the effective email address would be included@example.com:

// .gitconfig
[user]
  email = main@example.com

[include]
  path = .gitconfig.included
// .gitconfig.included
[user]
  email = included@example.com

However, if the include is moved up, the effective email address would be main@example.com:

// .gitconfig
[include]
  path = .gitconfig.included

[user]
  email = main@example.com
// .gitconfig.included
[user]
  email = included@example.com

As far as I know, the same principle is true for Bash, Vim, and others. Settings at the bottom override settings at the top, and included files are treated as if their contents exist at the location of the include.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can't be done, not without a breaking change in the way the misc config entries are handled.
This is because as of now these entries are handled in the global scope, and adding an [include] section in between these breaks the following ones, because there is currently no way to specify a return to global scope in TOML files.

The simplest way to fix this is to add a section named [misc] and move all the currently-in-global-scope entries to it.
The problem with this approach is that it breaks all the previously-created config files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DottoDev since you are the maintainer of this repository, I'm asking you to tell me how to proceed.

If we are going to migrate all currently-in-global-scope entries to the new [misc] section, I'm available to adapt topgrade to auto migrate the config file.

Copy link
Member

Choose a reason for hiding this comment

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

If config files can be auto migrated it would be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just pushed a commit to resolve this. I've already tested it myself, but you might want to check it out too @openjck.

@PolpOnline PolpOnline requested review from s34m and openjck May 24, 2023 19:24
Copy link
Member

@s34m s34m left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@s34m s34m left a comment

Choose a reason for hiding this comment

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

Cargo fmt and clippy checks need to passbefore a merge can occure.

@PolpOnline PolpOnline requested a review from s34m May 25, 2023 10:03
@s34m s34m merged commit cb7adc8 into topgrade-rs:master May 25, 2023
7 checks passed
@s34m
Copy link
Member

s34m commented May 25, 2023

Thanks for the work

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.

Include directive in topgrade.toml
4 participants