mirror of
https://github.com/git/git
synced 2024-10-06 00:29:28 +00:00
Add a Windows-specific fallback to getenv("HOME");
This fixes msysGit issue 482 properly. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
parent
9fa0780c54
commit
eb8fa8ca2c
|
@ -158,7 +158,7 @@ static int get_value(const char *key_, const char *regex_)
|
|||
|
||||
local = config_exclusive_filename;
|
||||
if (!local) {
|
||||
const char *home = getenv("HOME");
|
||||
const char *home = get_home_directory();
|
||||
local = repo_config = git_pathdup("config");
|
||||
if (home)
|
||||
global = xstrdup(mkpath("%s/.gitconfig", home));
|
||||
|
@ -357,7 +357,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
|
|||
}
|
||||
|
||||
if (use_global_config) {
|
||||
char *home = getenv("HOME");
|
||||
char *home = get_home_directory();
|
||||
if (home) {
|
||||
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
|
||||
config_exclusive_filename = user_config;
|
||||
|
|
|
@ -1821,3 +1821,21 @@ pid_t waitpid(pid_t pid, int *status, unsigned options)
|
|||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *get_windows_home_directory()
|
||||
{
|
||||
static const char *home_directory = NULL;
|
||||
struct strbuf buf = STRBUF_INIT;
|
||||
|
||||
if (home_directory)
|
||||
return home_directory;
|
||||
|
||||
home_directory = getenv("HOME");
|
||||
if (home_directory && *home_directory)
|
||||
return home_directory;
|
||||
|
||||
strbuf_addf(&buf, "%s/%s", getenv("HOMEDRIVE"), getenv("HOMEPATH"));
|
||||
home_directory = strbuf_detach(&buf, NULL);
|
||||
|
||||
return home_directory;
|
||||
}
|
||||
|
|
|
@ -352,3 +352,6 @@ static int mingw_main(c,v)
|
|||
* Used by Pthread API implementation for Windows
|
||||
*/
|
||||
extern int err_win_to_posix(DWORD winerr);
|
||||
|
||||
extern const char *get_windows_home_directory();
|
||||
#define get_home_directory() get_windows_home_directory()
|
||||
|
|
2
config.c
2
config.c
|
@ -869,7 +869,7 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
|
|||
found += 1;
|
||||
}
|
||||
|
||||
home = getenv("HOME");
|
||||
home = get_home_directory();
|
||||
if (home) {
|
||||
char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
|
||||
if (!access(user_config, R_OK)) {
|
||||
|
|
|
@ -579,4 +579,8 @@ int remove_or_warn(unsigned int mode, const char *path);
|
|||
#define mark_as_git_dir(x) /* noop */
|
||||
#endif
|
||||
|
||||
#ifndef get_home_directory
|
||||
#define get_home_directory() getenv("HOME")
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
2
path.c
2
path.c
|
@ -240,7 +240,7 @@ char *expand_user_path(const char *path)
|
|||
const char *username = path + 1;
|
||||
size_t username_len = first_slash - username;
|
||||
if (username_len == 0) {
|
||||
const char *home = getenv("HOME");
|
||||
const char *home = get_home_directory();
|
||||
if (!home)
|
||||
goto return_null;
|
||||
strbuf_add(&user_path, home, strlen(home));
|
||||
|
|
Loading…
Reference in a new issue