summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-05-20 13:41:39 -0700
committerRussell Belfer <rb@github.com>2013-05-20 13:41:39 -0700
commit4742148d54334629495eeaf0382e6c9da8786f17 (patch)
tree9fe01ef4d5b558c028432d4648f4b03c6fb5946c /src/fileops.c
parent9be5be47fb1d9bc08e25b30c05dbf48739710062 (diff)
downloadlibgit2-4742148d54334629495eeaf0382e6c9da8786f17.tar.gz
Add more diff rename detection tests
This adds a bunch more rename detection tests including checks vs the working directory, the new exact match options, some more whitespace variants, etc. This also adds a git_futils_writebuffer helper function and uses it in checkout. This is mainly added because I wanted an easy way to write out a git_buf to disk inside my test code.
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 98ab8efe3..a3e43214f 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -202,6 +202,32 @@ int git_futils_readbuffer(git_buf *buf, const char *path)
return git_futils_readbuffer_updated(buf, path, NULL, NULL, NULL);
}
+int git_futils_writebuffer(
+ const git_buf *buf, const char *path, int flags, mode_t mode)
+{
+ int fd, error = 0;
+
+ if (flags <= 0)
+ flags = O_CREAT | O_TRUNC | O_WRONLY;
+ if (!mode)
+ mode = GIT_FILEMODE_BLOB;
+
+ if ((fd = p_open(path, flags, mode)) < 0) {
+ giterr_set(GITERR_OS, "Could not open '%s' for writing", path);
+ return fd;
+ }
+
+ if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
+ giterr_set(GITERR_OS, "Could not write to '%s'", path);
+ (void)p_close(fd);
+ }
+
+ if ((error = p_close(fd)) < 0)
+ giterr_set(GITERR_OS, "Error while closing '%s'", path);
+
+ return error;
+}
+
int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode)
{
if (git_futils_mkpath2file(to, dirmode) < 0)