Skip to content

store gh config in %APPDATA% on windows os#2080

Closed
RozzaysRed wants to merge 5 commits intocli:trunkfrom
RozzaysRed:appdata_configPath
Closed

store gh config in %APPDATA% on windows os#2080
RozzaysRed wants to merge 5 commits intocli:trunkfrom
RozzaysRed:appdata_configPath

Conversation

@RozzaysRed
Copy link
Contributor

Instead of storing gh config in the Home path. The gh config will now be stored in "%APPDATA%\Local\Github CLI" for Windows OS

Address #1944

@RozzaysRed RozzaysRed changed the title store gh config in %APPDATA% on windows os [WIP] store gh config in %APPDATA% on windows os Oct 4, 2020
@RozzaysRed RozzaysRed changed the title [WIP] store gh config in %APPDATA% on windows os store gh config in %APPDATA% on windows os Oct 4, 2020
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 fully in support of using the user's AppData folder on Windows to store configuration and authentication credentials.

However, we cannot merge something like this without also putting in some migration code in place that would ensure that for existing users, the config from under ~/.config/gh/ will still be respected and migrated to a new location. Otherwise, when we ship this in a future update, existing Windows users will be forced to re-authenticate and will have lost their previous configuration.

I'm not asking you to necessarily add the migration code to this PR, but if you could just address the line comments for start, that would be great. Thank you!


func userHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intentionally avoid using homedir.Dir() here?

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 didn't intentional avoid using homedir.Dir. I have since removed this in the latest commit

dirPath := userHomeDir()

if runtime.GOOS == "windows" {
dirPath += "\\AppData\\Local\\Github Cli"
Copy link
Contributor

Choose a reason for hiding this comment

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

Protip: you can use filepath.Join() here

filepath.Join(dirPath, "AppData", "Local", "GitHub CLI")

However:

  1. Shouldn't we be reading from the %AppData% environment variable for this?
  2. Should we consider using Roaming instead of Local so that the user's gh config gets synced between their computers?
  3. CLI should be spelled uppercase.

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.

@RozzaysRed Thank you for the updates!

This looks good. We'll take it over from here 🙇

dir, _ := homedir.Expand("~/.config/gh")
dirPath := ""
if runtime.GOOS == "windows" {
dirPath = filepath.Join(os.Getenv("APPDATA"), "Github CLI")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
dirPath = filepath.Join(os.Getenv("APPDATA"), "Github CLI")
dirPath = filepath.Join(os.Getenv("APPDATA"), "GitHub CLI")

@vilmibm vilmibm self-assigned this Jan 19, 2021
@vilmibm
Copy link
Contributor

vilmibm commented Jan 20, 2021

I'll be taking this over with a goal of adding migration code for existing Windows users.

@samcoe
Copy link
Contributor

samcoe commented May 20, 2021

Going to close this in favor of #3671

@samcoe samcoe closed this May 20, 2021
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.

7 participants