summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorRussell Belfer <arrbee@arrbee.com>2012-01-11 16:01:48 -0800
committerRussell Belfer <arrbee@arrbee.com>2012-01-11 16:01:48 -0800
commit6a67a812c224878483659c6f25ca21573d1c309b (patch)
tree700df7d116f14bae08e437379bd4dfd44aaba825 /src/fileops.c
parentfdaa924037b66ee898fab503836a3d67194efacc (diff)
downloadlibgit2-6a67a812c224878483659c6f25ca21573d1c309b.tar.gz
Allow ignores (and attribs) for nonexistent files
This fixes issue 532 that attributes (and gitignores) could not be checked for files that don't exist. It should be possible to query such things regardless of the existence of the file.
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/fileops.c b/src/fileops.c
index f481bb01d..1d991b36d 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -536,13 +536,25 @@ int git_futils_find_system_file(git_buf *path, const char *filename)
int git_futils_dir_for_path(git_buf *dir, const char *path, const char *base)
{
- if (git_path_prettify(dir, path, base) == GIT_SUCCESS) {
- /* call dirname if this is not a directory */
- if (git_futils_isdir(dir->ptr) != GIT_SUCCESS)
- git_path_dirname_r(dir, dir->ptr);
+ int error = GIT_SUCCESS;
+
+ if (base != NULL && git_path_root(path) < 0)
+ error = git_buf_joinpath(dir, base, path);
+ else
+ error = git_buf_sets(dir, path);
- git_path_to_dir(dir);
+ if (error == GIT_SUCCESS) {
+ char buf[GIT_PATH_MAX];
+ if (p_realpath(dir->ptr, buf) != NULL)
+ error = git_buf_sets(dir, buf);
}
- return git_buf_lasterror(dir);
+ /* call dirname if this is not a directory */
+ if (error == GIT_SUCCESS && git_futils_isdir(dir->ptr) != GIT_SUCCESS)
+ error = git_path_dirname_r(dir, dir->ptr);
+
+ if (error == GIT_SUCCESS)
+ error = git_path_to_dir(dir);
+
+ return error;
}