Skip to content

Use os.UserHomeDir() instead of homedir.Dir() - #2429

Closed
linzhengen wants to merge 1 commit into
cli:trunkfrom
linzhengen:use_os_userhomedir_func
Closed

linzhengen wants to merge 1 commit into
cli:trunkfrom
linzhengen:use_os_userhomedir_func

Conversation

@linzhengen

Copy link
Copy Markdown

No description provided.

@vilmibm

vilmibm commented Nov 18, 2020

Copy link
Copy Markdown
Contributor

Hi,

As per our contributing docs we don't accept PRs that don't correspond to an existing issue. Without that or even a PR description, it's impossible to discern the intent or context of this PR. Closing, but can reopen if it's updated.

@vilmibm vilmibm closed this Nov 18, 2020
Comment thread git/ssh_config.go
"/etc/ssh/ssh_config",
}
if homedir, err := homedir.Dir(); err == nil {
if homedir, err := os.UserHomeDir(); err == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We usually prefer to use stdlib over adding dependencies. In this case, though, we used go-homedir in production for almost a year now, and if we're going to change it now, we have to consider potential implications to backwards-compatibility.

The first thing I would ask is: are homedir.Dir() and os.UserHomeDir() functionality equivalent for the purposes of our users? To answer that, sometimes it's best to view the source code:

As we can see, their implementations are vastly different: homedir falls back to HOMEDRIVE + HOMEPATH on Windows #1948 (comment), to dscl -q . -read /Users/"$(whoami)" NFSHomeDirectory on Darwin, to getent passwd on Linux, and to sh -c "cd && pwd" when all else fails.

If we switch now, we have to be conscious that gh will appear broken—more precisely, it will lose the user's existing config & authentication credentials—for anyone who currently relies on these fallbacks. Unfortunately, we have no ability to tell who will be affected in advance.

Personally, now that I look at it, I think that mitchellh/go-homedir is doing too much, and I'd be happy to move away from it. We inherited its use from a codebase that was written before os.UserHomeDir() was added to Go.

Maybe it would be worth to risk it and handle user reports if they come in telling them that they must set %userprofile% on Windows or HOME on other platforms. But we'd have to discuss first. For now, I agree with @vilmibm's call to close this until there is more discussion/context around the proposed change. Tip for the future: PRs are more likely to get accepted if they have a description arguing for why the change might be valuable to the project. 🙇

@mislav mislav mentioned this pull request Nov 24, 2020
5 of 8 tasks
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.

4 participants