Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1778908

Browse files
carlosmnEdward Thomson
authored and
Edward Thomson
committed
ignore: don't use realpath to canonicalize path
If we're looking for a symlink, realpath will give us the resolved path, which is not what we're after, but a canonicalized version of the path the user asked for.
1 parent 21d8832 commit 1778908

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/ignore.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,18 @@ int git_ignore__for_path(
263263
goto cleanup;
264264

265265
/* given a unrooted path in a non-bare repo, resolve it */
266-
if (workdir && git_path_root(path) < 0)
267-
error = git_path_find_dir(&ignores->dir, path, workdir);
268-
else
266+
if (workdir && git_path_root(path) < 0) {
267+
git_buf local = GIT_BUF_INIT;
268+
269+
if ((error = git_path_dirname_r(&local, path)) < 0 ||
270+
(error = git_path_resolve_relative(&local, 0)) < 0 ||
271+
(error = git_path_to_dir(&local)) < 0 ||
272+
(error = git_buf_joinpath(&ignores->dir, workdir, local.ptr)) < 0)
273+
{;} /* Nothing, we just want to stop on the first error */
274+
git_buf_free(&local);
275+
} else {
269276
error = git_buf_joinpath(&ignores->dir, path, "");
277+
}
270278
if (error < 0)
271279
goto cleanup;
272280

tests/attr/ignore.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,16 @@ void test_attr_ignore__dont_ignore_files_for_folder(void)
252252
if (cl_repo_get_bool(g_repo, "core.ignorecase"))
253253
assert_is_ignored(false, "dir/TeSt");
254254
}
255+
256+
void test_attr_ignore__symlink_to_outside(void)
257+
{
258+
#ifdef GIT_WIN32
259+
cl_skip();
260+
#endif
261+
262+
cl_git_rewritefile("attr/.gitignore", "symlink\n");
263+
cl_git_mkfile("target", "target");
264+
cl_git_pass(p_symlink("../target", "attr/symlink"));
265+
assert_is_ignored(true, "symlink");
266+
assert_is_ignored(true, "lala/../symlink");
267+
}

0 commit comments

Comments
 (0)