diff options
author | Matthieu Moy <Matthieu.Moy@imag.fr> | 2009-11-19 16:21:15 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2009-11-19 10:01:12 -0800 |
commit | df2a79f4225b7216dce010ebfe41f8ad0de34b24 (patch) | |
tree | b3ceaa28cfbc8a42c4894e308c08a0d724a5fab6 /path.c | |
parent | 395de250d9d9762b8ac1ce98b297d60d0b5bd643 (diff) | |
download | git-df2a79f4225b7216dce010ebfe41f8ad0de34b24.tar.gz |
expand_user_path: expand ~ to $HOME, not to the actual homedir.
In 395de250d (Expand ~ and ~user in core.excludesfile, commit.template),
we introduced the mechanism. But expanding ~ using getpw is not what
people overriding $HOME would usually expect. In particular, git looks
for the user's .gitconfig using $HOME, so it's better to be consistent.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -235,10 +235,15 @@ char *expand_user_path(const char *path) if (path[0] == '~') { const char *username = path + 1; size_t username_len = first_slash - username; - struct passwd *pw = getpw_str(username, username_len); - if (!pw) - goto return_null; - strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir)); + if (username_len == 0) { + const char *home = getenv("HOME"); + strbuf_add(&user_path, home, strlen(home)); + } else { + struct passwd *pw = getpw_str(username, username_len); + if (!pw) + goto return_null; + strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir)); + } to_copy = first_slash; } strbuf_add(&user_path, to_copy, strlen(to_copy)); |