/* Adding an entry that represents a rename gets two files in conflict */
our_entry.path = "subdir/modified_file";
our_entry.mode = 0100644;
+ git_oid_fromstr(&our_entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
their_entry.path = "subdir/rename_conflict";
their_entry.mode = 0100644;
+ git_oid_fromstr(&their_entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_conflict_add(index, NULL, &our_entry, &their_entry));
cl_assert((iep = git_index_get_bypath(idx, "modified_file", 0)) != NULL);
memcpy(&ie, iep, sizeof(ie));
- ie.flags |= GIT_IDXENTRY_VALID;
+ ie.flags |= GIT_INDEX_ENTRY_VALID;
cl_git_pass(git_index_add(idx, &ie));
cl_assert((iep = git_index_get_bypath(idx, "file_deleted", 0)) != NULL);
memcpy(&ie, iep, sizeof(ie));
- ie.flags |= GIT_IDXENTRY_VALID;
+ ie.flags |= GIT_INDEX_ENTRY_VALID;
cl_git_pass(git_index_add(idx, &ie));
cl_git_pass(git_index_write(idx));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
memset(&exp, 0, sizeof(exp));
- cl_git_pass(git_diff_foreach(diff,
+ cl_git_pass(git_diff_foreach(diff,
diff_file_cb, diff_binary_cb, diff_hunk_cb, diff_line_cb, &exp));
cl_assert_equal_i(0, exp.files);
opts.version = 0;
cl_git_fail(git_diff_tree_to_workdir(&diff, g_repo, NULL, &opts));
- err = giterr_last();
- cl_assert_equal_i(GITERR_INVALID, err->klass);
+ err = git_error_last();
+ cl_assert_equal_i(GIT_ERROR_INVALID, err->klass);
- giterr_clear();
+ git_error_clear();
opts.version = 1024;
cl_git_fail(git_diff_tree_to_workdir(&diff, g_repo, NULL, &opts));
- err = giterr_last();
- cl_assert_equal_i(GITERR_INVALID, err->klass);
+ err = git_error_last();
+ cl_assert_equal_i(GIT_ERROR_INVALID, err->klass);
}
void test_diff_workdir__can_diff_empty_file(void)
cl_assert_equal_s(expected_patience, buf.ptr);
git_buf_clear(&buf);
- git_buf_free(&buf);
+ git_buf_dispose(&buf);
git_patch_free(patch);
git_diff_free(diff);
}
static int touch_file(void *payload, git_buf *path)
{
struct stat st;
- struct timeval times[2];
+ struct p_timeval times[2];
GIT_UNUSED(payload);
if (git_path_isdir(path->ptr))
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_buf_sets(&path, "status"));
cl_git_pass(git_path_direach(&path, 0, touch_file, NULL));
- git_buf_free(&path);
+ git_buf_dispose(&path);
}
opts.flags |= GIT_DIFF_INCLUDE_IGNORED | GIT_DIFF_INCLUDE_UNTRACKED;
git_buf b = GIT_BUF_INIT;
int i;
git_buf data[10] = {
- { "1234567890", 0, 0 }, /* 0 - all ascii text control */
- { "\xC3\x85\xC3\xBC\xE2\x80\xA0\x48\xC3\xB8\xCF\x80\xCE\xA9", 0, 0 }, /* 1 - UTF-8 multibyte text */
- { "\xEF\xBB\xBF\xC3\x9C\xE2\xA4\x92\xC6\x92\x38\xC2\xA3\xE2\x82\xAC", 0, 0 }, /* 2 - UTF-8 with BOM */
+ { "1234567890", 0, 10 }, /* 0 - all ascii text control */
+ { "\xC3\x85\xC3\xBC\xE2\x80\xA0\x48\xC3\xB8\xCF\x80\xCE\xA9", 0, 14 }, /* 1 - UTF-8 multibyte text */
+ { "\xEF\xBB\xBF\xC3\x9C\xE2\xA4\x92\xC6\x92\x38\xC2\xA3\xE2\x82\xAC", 0, 16 }, /* 2 - UTF-8 with BOM */
{ STR999Z, 0, 1000 }, /* 3 - ASCII with NUL at 1000 */
{ STR3999Z, 0, 4000 }, /* 4 - ASCII with NUL at 4000 */
{ STR4000 STR3999Z "x", 0, 8001 }, /* 5 - ASCII with NUL at 8000 */
cl_git_write2file(
b.ptr, data[i].ptr, data[i].size, O_WRONLY|O_TRUNC, 0664);
}
- git_index_write(idx);
+ cl_git_pass(git_index_write(idx));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
cl_git_write2file(b.ptr, "baseline\n", 9, O_WRONLY|O_TRUNC, 0664);
}
- git_index_write(idx);
+ cl_git_pass(git_index_write(idx));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, NULL));
git_diff_free(diff);
git_index_free(idx);
- git_buf_free(&b);
+ git_buf_dispose(&b);
}
void test_diff_workdir__to_index_conflicted(void) {
ancestor.path = ours.path = theirs.path = "_file";
ancestor.mode = ours.mode = theirs.mode = 0100644;
- git_oid_fromstr(&ancestor.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
- git_oid_fromstr(&ours.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
- git_oid_fromstr(&theirs.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
+ git_oid_fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46");
+ git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf");
+ git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863");
cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs));
cl_git_pass(git_diff_tree_to_index(&diff1, g_repo, a, index, NULL));
git_oid initial, first, second;
git_buf path = GIT_BUF_INIT;
struct stat st;
- struct timeval times[2];
+ struct p_timeval times[2];
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_UPDATE_INDEX;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_repository_head(&head, g_repo));
- cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT));
+ cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(g_repo, head_object, GIT_RESET_HARD, NULL));
git_oid_cpy(&second, git_index_checksum(index));
cl_assert(!git_oid_equal(&first, &second));
- git_buf_free(&path);
+ git_buf_dispose(&path);
git_object_free(head_object);
git_reference_free(head);
git_index_free(index);
git_vector_free(&pathlist);
}
+void test_diff_workdir__symlink_changed_on_non_symlink_platform(void)
+{
+ git_tree *tree;
+ git_diff *diff;
+ diff_expects exp = {0};
+ const git_diff_delta *delta;
+ const char *commit = "7fccd7";
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_vector pathlist = GIT_VECTOR_INIT;
+ int symlinks;
+
+ g_repo = cl_git_sandbox_init("unsymlinked.git");
+
+ cl_git_pass(git_repository__configmap_lookup(&symlinks, g_repo, GIT_CONFIGMAP_SYMLINKS));
+
+ if (symlinks)
+ cl_skip();
+
+ cl_git_pass(git_vector_insert(&pathlist, "include/Nu/Nu.h"));
+
+ opts.pathspec.strings = (char **)pathlist.contents;
+ opts.pathspec.count = pathlist.length;
+
+ cl_must_pass(p_mkdir("symlink", 0777));
+ cl_git_pass(git_repository_set_workdir(g_repo, "symlink", false));
+
+ cl_assert((tree = resolve_commit_oid_to_tree(g_repo, commit)) != NULL);
+
+ /* first, do the diff with the original contents */
+
+ cl_git_pass(git_futils_mkpath2file("symlink/include/Nu/Nu.h", 0755));
+ cl_git_mkfile("symlink/include/Nu/Nu.h", "../../objc/Nu.h");
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+ cl_assert_equal_i(0, git_diff_num_deltas(diff));
+ git_diff_free(diff);
+
+ /* now update the contents and expect a difference, but that the file
+ * mode has persisted as a symbolic link.
+ */
+
+ cl_git_rewritefile("symlink/include/Nu/Nu.h", "awesome content\n");
+
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+
+ cl_git_pass(git_diff_foreach(
+ diff, diff_file_cb, diff_binary_cb, diff_hunk_cb, diff_line_cb, &exp));
+ cl_assert_equal_i(1, exp.files);
+
+ cl_assert_equal_i(1, git_diff_num_deltas(diff));
+ delta = git_diff_get_delta(diff, 0);
+ cl_assert_equal_i(GIT_FILEMODE_LINK, delta->old_file.mode);
+ cl_assert_equal_i(GIT_FILEMODE_LINK, delta->new_file.mode);
+
+ git_diff_free(diff);
+
+ cl_git_pass(git_futils_rmdir_r("symlink", NULL, GIT_RMDIR_REMOVE_FILES));
+
+ git_tree_free(tree);
+ git_vector_free(&pathlist);
+}
+
+void test_diff_workdir__order(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_buf patch = GIT_BUF_INIT;
+ git_oid tree_oid, blob_oid;
+ git_treebuilder *builder;
+ git_tree *tree;
+ git_diff *diff;
+
+ g_repo = cl_git_sandbox_init("empty_standard_repo");
+
+ /* Build tree with a single file "abc.txt" */
+ cl_git_pass(git_blob_create_from_buffer(&blob_oid, g_repo, "foo\n", 4));
+ cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
+ cl_git_pass(git_treebuilder_insert(NULL, builder, "abc.txt", &blob_oid, GIT_FILEMODE_BLOB));
+ cl_git_pass(git_treebuilder_write(&tree_oid, builder));
+ cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
+
+ /* Create a directory that sorts before and one that sorts after "abc.txt" */
+ cl_git_mkfile("empty_standard_repo/abc.txt", "bar\n");
+ cl_must_pass(p_mkdir("empty_standard_repo/abb", 0777));
+ cl_must_pass(p_mkdir("empty_standard_repo/abd", 0777));
+
+ opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
+ cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts));
+
+ cl_assert_equal_i(1, git_diff_num_deltas(diff));
+ cl_git_pass(git_diff_to_buf(&patch, diff, GIT_DIFF_FORMAT_PATCH));
+ cl_assert_equal_s(patch.ptr,
+ "diff --git a/abc.txt b/abc.txt\n"
+ "index 257cc56..5716ca5 100644\n"
+ "--- a/abc.txt\n"
+ "+++ b/abc.txt\n"
+ "@@ -1 +1 @@\n"
+ "-foo\n"
+ "+bar\n");
+
+ git_treebuilder_free(builder);
+ git_buf_dispose(&patch);
+ git_diff_free(diff);
+ git_tree_free(tree);
+}