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>
This commit is contained in:
parent
395de250d9
commit
df2a79f422
@ -380,9 +380,9 @@ Common unit suffixes of 'k', 'm', or 'g' are supported.
|
|||||||
core.excludesfile::
|
core.excludesfile::
|
||||||
In addition to '.gitignore' (per-directory) and
|
In addition to '.gitignore' (per-directory) and
|
||||||
'.git/info/exclude', git looks into this file for patterns
|
'.git/info/exclude', git looks into this file for patterns
|
||||||
of files which are not meant to be tracked. "~/" and "~user/"
|
of files which are not meant to be tracked. "~/" is expanded
|
||||||
are expanded to the specified user's home directory. See
|
to the value of `$HOME` and "~user/" to the specified user's
|
||||||
linkgit:gitignore[5].
|
home directory. See linkgit:gitignore[5].
|
||||||
|
|
||||||
core.editor::
|
core.editor::
|
||||||
Commands such as `commit` and `tag` that lets you edit
|
Commands such as `commit` and `tag` that lets you edit
|
||||||
@ -667,7 +667,8 @@ color.ui::
|
|||||||
|
|
||||||
commit.template::
|
commit.template::
|
||||||
Specify a file to use as the template for new commit messages.
|
Specify a file to use as the template for new commit messages.
|
||||||
"~/" and "~user/" are expanded to the specified user's home directory.
|
"~/" is expanded to the value of `$HOME` and "~user/" to the
|
||||||
|
specified user's home directory.
|
||||||
|
|
||||||
diff.autorefreshindex::
|
diff.autorefreshindex::
|
||||||
When using 'git-diff' to compare with work tree
|
When using 'git-diff' to compare with work tree
|
||||||
|
13
path.c
13
path.c
@ -235,10 +235,15 @@ char *expand_user_path(const char *path)
|
|||||||
if (path[0] == '~') {
|
if (path[0] == '~') {
|
||||||
const char *username = path + 1;
|
const char *username = path + 1;
|
||||||
size_t username_len = first_slash - username;
|
size_t username_len = first_slash - username;
|
||||||
struct passwd *pw = getpw_str(username, username_len);
|
if (username_len == 0) {
|
||||||
if (!pw)
|
const char *home = getenv("HOME");
|
||||||
goto return_null;
|
strbuf_add(&user_path, home, strlen(home));
|
||||||
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
|
} 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;
|
to_copy = first_slash;
|
||||||
}
|
}
|
||||||
strbuf_add(&user_path, to_copy, strlen(to_copy));
|
strbuf_add(&user_path, to_copy, strlen(to_copy));
|
||||||
|
Loading…
Reference in New Issue
Block a user