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

Add support for XDG_CONFIG_HOME and AppData on Windows #3671

Merged
merged 1 commit into from
May 24, 2021
Merged

Conversation

samcoe
Copy link
Contributor

@samcoe samcoe commented May 19, 2021

This PR adds support for storing gh config files in XDG_CONFIG_HOME as well as AppData on Windows.

cc #2470
closes #1944
closes #554
supersedes #2080

@samcoe samcoe self-assigned this May 19, 2021
@samcoe samcoe force-pushed the xdg-config branch 2 times, most recently from c000bf6 to 6461354 Compare May 20, 2021 12:59
@samcoe samcoe marked this pull request as ready for review May 20, 2021 13:03
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI May 20, 2021
The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 May 20, 2021
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

This is heading in a great direction. Thanks for working on this!

Left some comments about tightening up the migration logic and ensuring that it's entirely exercised in tests.

Note that if we advertise support for XDG spec, then we have to adhere to it as much as we can. That means avoiding storing non-config files under XDG_CONFIG_HOME. Currently, our only non-config file is state.yml, so that one should be migrated to XDG_STATE_HOME accordingly. #554 (comment)

internal/config/config_file.go Show resolved Hide resolved
internal/config/config_file.go Outdated Show resolved Hide resolved
internal/config/config_file.go Outdated Show resolved Hide resolved
internal/config/config_file.go Outdated Show resolved Hide resolved
internal/config/config_file.go Show resolved Hide resolved
internal/config/config_file.go Outdated Show resolved Hide resolved
The GitHub CLI automation moved this from Needs to be merged 🎉 to Needs review 🤔 May 21, 2021
@samcoe samcoe requested a review from mislav May 21, 2021 18:02
@samcoe
Copy link
Contributor Author

samcoe commented May 21, 2021

@mislav thanks for the thorough review. I addressed your comments. Regarding, XDG_STATE_HOME I was planning on addressing that next, in a separate PR.

Copy link

@angryTOASTpac angryTOASTpac left a comment

Choose a reason for hiding this comment

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

I'm fired up about this!

@samcoe samcoe force-pushed the xdg-config branch 2 times, most recently from f34727f to 99a31ff Compare May 21, 2021 20:09
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I'm fired up about this!

internal/config/config_file.go Outdated Show resolved Hide resolved
internal/config/config_file.go Outdated Show resolved Hide resolved
return false
}

var migrateConfigDir = func(oldPath, newPath string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish that this wouldn't be an overridable function anymore, but I understand that other pieces of our codebase are coupled to ConfigDir in tests and that they could inadvertently cause changes to the user's home directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, unfortunately that is the case now. Hopefully in the future we can clean that up. I did add tests for this directly though so it isn't stubbed out in all tests.

internal/config/config_file_test.go Show resolved Hide resolved
}

_ = os.MkdirAll(filepath.Dir(newPath), 0755)
_ = os.Rename(oldPath, newPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also remove the orphaned ~/.config directory after the migration of ~/.config/gh to the new location?

We could simply try to os.Remove the parent. If it errors out, we ignore it.

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 don't think this is a good idea since it could remove files users want to keep. I actually have git, kitty, and nvim configuration files in ~/.config.

Copy link
Contributor

Choose a reason for hiding this comment

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

os.Remove, like the rm command, is only able to remove empty directories. It would error out otherwise.

internal/config/config_file_test.go Outdated Show resolved Hide resolved
internal/config/config_file_test.go Outdated Show resolved Hide resolved
The GitHub CLI automation moved this from Needs review 🤔 to Needs to be merged 🎉 May 24, 2021
@samcoe samcoe force-pushed the xdg-config branch 3 times, most recently from b002d4c to 6d8c6c0 Compare May 24, 2021 20:09
@samcoe samcoe merged commit 045089c into trunk May 24, 2021
The GitHub CLI automation moved this from Needs to be merged 🎉 to Pending Release 🥚 May 24, 2021
@samcoe samcoe deleted the xdg-config branch May 24, 2021 20:22
@jasonkarns
Copy link

🎉 thanks @samcoe !!

@github-actions github-actions bot moved this from Pending Release 🥚 to Done 💤 in The GitHub CLI Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
The GitHub CLI
  
Done 💤
Development

Successfully merging this pull request may close these issues.

Store gh config in %APPDATA% on windows Improved XDG basedir spec compliance
5 participants