#include "git2/sys/repository.h"
#include "apply.h"
+#include "patch.h"
+#include "patch_parse.h"
#include "repository.h"
-#include "buf_text.h"
#include "../patch/patch_common.h"
unsigned int mode_expected)
{
git_patch *patch;
- git_buf result = GIT_BUF_INIT;
- git_buf patchbuf = GIT_BUF_INIT;
+ git_str result = GIT_STR_INIT;
+ git_str patchbuf = GIT_STR_INIT;
char *filename;
unsigned int mode;
int error;
- cl_git_pass(git_patch_from_patchfile(&patch, patchfile, strlen(patchfile), NULL));
+ cl_git_pass(git_patch_from_buffer(&patch, patchfile, strlen(patchfile), NULL));
- error = git_apply__patch(&result, &filename, &mode, old, old_len, patch);
+ error = git_apply__patch(&result, &filename, &mode, old, old_len, patch, NULL);
if (error == 0) {
cl_assert_equal_i(new_len, result.size);
- cl_assert(memcmp(new, result.ptr, new_len) == 0);
+ if (new_len)
+ cl_assert(memcmp(new, result.ptr, new_len) == 0);
cl_assert_equal_s(filename_expected, filename);
cl_assert_equal_i(mode_expected, mode);
}
git__free(filename);
- git_buf_free(&result);
- git_buf_free(&patchbuf);
+ git_str_dispose(&result);
+ git_str_dispose(&patchbuf);
git_patch_free(patch);
return error;
error = apply_patchfile(old, old_len, new, new_len, patchfile, filename_expected, mode_expected);
- git_buf_free(&validated);
+ git_buf_dispose(&validated);
git_patch_free(patch_fromdiff);
return error;
void test_apply_fromfile__fail_truncated_1(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_1,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_1,
strlen(PATCH_TRUNCATED_1), NULL));
}
void test_apply_fromfile__fail_truncated_2(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_2,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_2,
strlen(PATCH_TRUNCATED_2), NULL));
}
void test_apply_fromfile__fail_truncated_3(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_3,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_3,
strlen(PATCH_TRUNCATED_3), NULL));
}
void test_apply_fromfile__fail_corrupt_githeader(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_CORRUPT_GIT_HEADER,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_CORRUPT_GIT_HEADER,
strlen(PATCH_CORRUPT_GIT_HEADER), NULL));
}
void test_apply_fromfile__fail_missing_new_file(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_NEW_FILE,
strlen(PATCH_CORRUPT_MISSING_NEW_FILE), NULL));
}
void test_apply_fromfile__fail_missing_old_file(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_OLD_FILE,
strlen(PATCH_CORRUPT_MISSING_OLD_FILE), NULL));
}
void test_apply_fromfile__fail_no_changes(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_NO_CHANGES,
strlen(PATCH_CORRUPT_NO_CHANGES), NULL));
}
void test_apply_fromfile__fail_missing_hunk_header(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch,
+ cl_git_fail(git_patch_from_buffer(&patch,
PATCH_CORRUPT_MISSING_HUNK_HEADER,
strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL));
}
void test_apply_fromfile__fail_not_a_patch(void)
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, PATCH_NOT_A_PATCH,
+ cl_git_fail(git_patch_from_buffer(&patch, PATCH_NOT_A_PATCH,
strlen(PATCH_NOT_A_PATCH), NULL));
}
{
git_patch *patch;
- cl_git_fail(git_patch_from_patchfile(&patch, "", 0, NULL));
- cl_git_fail(git_patch_from_patchfile(&patch, NULL, 0, NULL));
+ cl_git_fail(git_patch_from_buffer(&patch, "", 0, NULL));
+ cl_git_fail(git_patch_from_buffer(&patch, NULL, 0, NULL));
}