Merge branch 'nd/conditional-config-include'

$GIT_DIR may in some cases be normalized with all symlinks resolved
while "gitdir" path expansion in the pattern does not receive the
same treatment, leading to incorrect mismatch.  This has been fixed.

* nd/conditional-config-include:
  config: resolve symlinks in conditional include's patterns
  path.c: and an option to call real_path() in expand_user_path()
This commit is contained in:
Junio C Hamano
2017-04-23 22:07:46 -07:00
8 changed files with 73 additions and 14 deletions

11
path.c
View File

@ -617,8 +617,10 @@ static struct passwd *getpw_str(const char *username, size_t len)
* Return a string with ~ and ~user expanded via getpw*. If buf != NULL,
* then it is a newly allocated string. Returns NULL on getpw failure or
* if path is NULL.
*
* If real_home is true, real_path($HOME) is used in the expansion.
*/
char *expand_user_path(const char *path)
char *expand_user_path(const char *path, int real_home)
{
struct strbuf user_path = STRBUF_INIT;
const char *to_copy = path;
@ -633,7 +635,10 @@ char *expand_user_path(const char *path)
const char *home = getenv("HOME");
if (!home)
goto return_null;
strbuf_addstr(&user_path, home);
if (real_home)
strbuf_addstr(&user_path, real_path(home));
else
strbuf_addstr(&user_path, home);
#ifdef GIT_WINDOWS_NATIVE
convert_slashes(user_path.buf);
#endif
@ -702,7 +707,7 @@ const char *enter_repo(const char *path, int strict)
strbuf_add(&validated_path, path, len);
if (used_path.buf[0] == '~') {
char *newpath = expand_user_path(used_path.buf);
char *newpath = expand_user_path(used_path.buf, 0);
if (!newpath)
return NULL;
strbuf_attach(&used_path, newpath, strlen(newpath),