X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=setup.c;h=b6e6b5ae272b3ecae7dfa2cb446aef97e826884a;hb=bd9a2688454c09431101869e75c5a47f08c05b1a;hp=03cd84f2fcbf9cdbc25116308a9c2c9407af8e71;hpb=1de0746d849c64e1f4d160f9915d87d39c0794ea;p=git.git diff --git a/setup.c b/setup.c index 03cd84f2f..b6e6b5ae2 100644 --- a/setup.c +++ b/setup.c @@ -325,6 +325,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv, const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); const char *worktree; char *gitfile; + int offset; if (PATH_MAX - 40 < strlen(gitdirenv)) die("'$%s' too big", GIT_DIR_ENVIRONMENT); @@ -390,15 +391,15 @@ static const char *setup_explicit_git_dir(const char *gitdirenv, return NULL; } - if (!prefixcmp(cwd, worktree) && - cwd[strlen(worktree)] == '/') { /* cwd inside worktree */ + offset = dir_inside_of(cwd, worktree); + if (offset >= 0) { /* cwd inside worktree? */ set_git_dir(real_path(gitdirenv)); if (chdir(worktree)) die_errno("Could not chdir to '%s'", worktree); cwd[len++] = '/'; cwd[len] = '\0'; free(gitfile); - return cwd + strlen(worktree) + 1; + return cwd + offset; } /* cwd outside worktree */