diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 22:45:56 +0100 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 22:45:56 +0100 |
commit | bdd31dd5e832126b2f22fccbe244a1106c241ab0 (patch) | |
tree | b08a2ad0fad57131563aa8c071221bea241128c1 /tests | |
parent | 277b7efe493887081ce1dafd91199d0ee9f676c9 (diff) | |
parent | e4c93a392763a006d11e1c1dd01c12f85498dad5 (diff) | |
download | libgit2-error-handling.tar.gz |
Merge branch 'development' into error-handlingerror-handling
The code in this branch has been modified so it works with the global
state introduced in development.
Diffstat (limited to 'tests')
27 files changed, 292 insertions, 95 deletions
diff --git a/tests/resources/status/.gitted/COMMIT_EDITMSG b/tests/resources/status/.gitted/COMMIT_EDITMSG index ff887ba13..1a25cd4a6 100644 --- a/tests/resources/status/.gitted/COMMIT_EDITMSG +++ b/tests/resources/status/.gitted/COMMIT_EDITMSG @@ -1 +1 @@ -add subdir +Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker diff --git a/tests/resources/status/.gitted/ORIG_HEAD b/tests/resources/status/.gitted/ORIG_HEAD index c2805f422..b46871fd6 100644 --- a/tests/resources/status/.gitted/ORIG_HEAD +++ b/tests/resources/status/.gitted/ORIG_HEAD @@ -1 +1 @@ -0017bd4ab1ec30440b17bae1680cff124ab5f1f6 +735b6a258cd196a8f7c9428419b02c1dca93fd75 diff --git a/tests/resources/status/.gitted/index b/tests/resources/status/.gitted/index Binary files differindex 5c4b18841..d793791c9 100644 --- a/tests/resources/status/.gitted/index +++ b/tests/resources/status/.gitted/index diff --git a/tests/resources/status/.gitted/logs/HEAD b/tests/resources/status/.gitted/logs/HEAD index e876bd80b..7b95b3cf1 100644 --- a/tests/resources/status/.gitted/logs/HEAD +++ b/tests/resources/status/.gitted/logs/HEAD @@ -1,2 +1,3 @@ 0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir +735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker diff --git a/tests/resources/status/.gitted/logs/refs/heads/master b/tests/resources/status/.gitted/logs/refs/heads/master index e876bd80b..7b95b3cf1 100644 --- a/tests/resources/status/.gitted/logs/refs/heads/master +++ b/tests/resources/status/.gitted/logs/refs/heads/master @@ -1,2 +1,3 @@ 0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir +735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker diff --git a/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f b/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f new file mode 100644 index 000000000..f7dddc4ff --- /dev/null +++ b/tests/resources/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f @@ -0,0 +1,2 @@ +xMn )V (̀BDLЍRȷވ@,9̜tNj6f`M6Z;h
Zp ڙY,37/;42x&<z
#^ +䮁ZQ0嫫pޙ`l?{@)1+=#ö6j#֧qP>gϟۉIm|j
\ No newline at end of file diff --git a/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0 b/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0 Binary files differnew file mode 100644 index 000000000..b75481b51 --- /dev/null +++ b/tests/resources/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0 diff --git a/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e b/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e Binary files differnew file mode 100644 index 000000000..cfc2413d5 --- /dev/null +++ b/tests/resources/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e diff --git a/tests/resources/status/.gitted/refs/heads/master b/tests/resources/status/.gitted/refs/heads/master index b46871fd6..3e2e2a07a 100644 --- a/tests/resources/status/.gitted/refs/heads/master +++ b/tests/resources/status/.gitted/refs/heads/master @@ -1 +1 @@ -735b6a258cd196a8f7c9428419b02c1dca93fd75 +26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f diff --git a/tests/resources/status/subdir.txt b/tests/resources/status/subdir.txt new file mode 100644 index 000000000..e8ee89e15 --- /dev/null +++ b/tests/resources/status/subdir.txt @@ -0,0 +1,2 @@ +Is it a bird? +Is it a plane? diff --git a/tests/t00-core.c b/tests/t00-core.c index 703504bf8..94824b438 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -99,8 +99,8 @@ BEGIN_TEST(vector2, "remove duplicates") must_be_true(x.length == 2); git_vector_free(&x); - free(ptrs[0]); - free(ptrs[1]); + git__free(ptrs[0]); + git__free(ptrs[1]); END_TEST @@ -112,7 +112,7 @@ BEGIN_TEST(path0, "get the dirname of a path") must_be_true(strcmp(dir, B) == 0); \ must_be_true((dir2 = git_path_dirname(A)) != NULL); \ must_be_true(strcmp(dir2, B) == 0); \ - free(dir2); \ + git__free(dir2); \ } DIRNAME_TEST(NULL, "."); @@ -141,7 +141,7 @@ BEGIN_TEST(path1, "get the base name of a path") must_be_true(strcmp(base, B) == 0); \ must_be_true((base2 = git_path_basename(A)) != NULL); \ must_be_true(strcmp(base2, B) == 0); \ - free(base2); \ + git__free(base2); \ } BASENAME_TEST(NULL, "."); @@ -250,21 +250,21 @@ static int setup(walk_data *d) { name_data *n; - if (p_mkdir(top_dir, 0755) < 0) + if (p_mkdir(top_dir, 0777) < 0) return error("can't mkdir(\"%s\")", top_dir); if (p_chdir(top_dir) < 0) return error("can't chdir(\"%s\")", top_dir); if (strcmp(d->sub, ".") != 0) - if (p_mkdir(d->sub, 0755) < 0) + if (p_mkdir(d->sub, 0777) < 0) return error("can't mkdir(\"%s\")", d->sub); strcpy(path_buffer, d->sub); state_loc = d; for (n = d->names; n->name; n++) { - git_file fd = p_creat(n->name, 0600); + git_file fd = p_creat(n->name, 0666); if (fd < 0) return GIT_ERROR; p_close(fd); @@ -479,14 +479,14 @@ BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") int fd; char test[] = "test"; - fd = p_creat(test, 0644); + fd = p_creat(test, 0666); must_pass(fd); must_pass(p_write(fd, "libgit2 rocks\n", 14)); must_pass(p_close(fd)); must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - must_pass(git_filebuf_commit(&file)); + must_pass(git_filebuf_commit(&file, 0666)); must_pass(p_unlink(test)); END_TEST @@ -499,7 +499,7 @@ BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly" memset(buf, 0xfe, sizeof(buf)); must_pass(git_filebuf_open(&file, test, 0)); must_pass(git_filebuf_write(&file, buf, sizeof(buf))); - must_pass(git_filebuf_commit(&file)); + must_pass(git_filebuf_commit(&file, 0666)); must_pass(p_unlink(test)); END_TEST @@ -510,27 +510,27 @@ static int setup_empty_tmp_dir(void) { char path[GIT_PATH_MAX]; - if (p_mkdir(empty_tmp_dir, 0755)) + if (p_mkdir(empty_tmp_dir, 0777)) return -1; git_path_join(path, empty_tmp_dir, "/one"); - if (p_mkdir(path, 0755)) + if (p_mkdir(path, 0777)) return -1; git_path_join(path, empty_tmp_dir, "/one/two_one"); - if (p_mkdir(path, 0755)) + if (p_mkdir(path, 0777)) return -1; git_path_join(path, empty_tmp_dir, "/one/two_two"); - if (p_mkdir(path, 0755)) + if (p_mkdir(path, 0777)) return -1; git_path_join(path, empty_tmp_dir, "/one/two_two/three"); - if (p_mkdir(path, 0755)) + if (p_mkdir(path, 0777)) return -1; git_path_join(path, empty_tmp_dir, "/two"); - if (p_mkdir(path, 0755)) + if (p_mkdir(path, 0777)) return -1; return 0; @@ -547,7 +547,7 @@ BEGIN_TEST(rmdir1, "make sure non-empty dir cannot be deleted recusively") must_pass(setup_empty_tmp_dir()); git_path_join(file, empty_tmp_dir, "/two/file.txt"); - fd = p_creat(file, 0755); + fd = p_creat(file, 0777); must_pass(fd); must_pass(p_close(fd)); must_fail(git_futils_rmdir_r(empty_tmp_dir, 0)); diff --git a/tests/t01-rawobj.c b/tests/t01-rawobj.c index 255208532..8b05f3394 100644 --- a/tests/t01-rawobj.c +++ b/tests/t01-rawobj.c @@ -217,7 +217,7 @@ BEGIN_TEST(oid12, "compare oids (allocate + format)") out = git_oid_allocfmt(&in); must_be_true(out); must_be_true(strcmp(exp, out) == 0); - free(out); + git__free(out); END_TEST BEGIN_TEST(oid13, "compare oids (path format)") @@ -390,7 +390,7 @@ BEGIN_TEST(oid17, "stress test for the git_oid_shorten object") /* cleanup */ for (i = 0; i < MAX_OIDS; ++i) - free(oids[i]); + git__free(oids[i]); git_oid_shorten_free(os); diff --git a/tests/t03-objwrite.c b/tests/t03-objwrite.c index 31f611a5c..7563d0e3a 100644 --- a/tests/t03-objwrite.c +++ b/tests/t03-objwrite.c @@ -31,7 +31,7 @@ static char *odb_dir = "test-objects"; static int make_odb_dir(void) { - if (p_mkdir(odb_dir, 0755) < 0) { + if (p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE) < 0) { int err = errno; fprintf(stderr, "can't make directory \"%s\"", odb_dir); if (err == EEXIST) diff --git a/tests/t04-commit.c b/tests/t04-commit.c index 3fb4d370c..d0bb1b583 100644 --- a/tests/t04-commit.c +++ b/tests/t04-commit.c @@ -162,7 +162,7 @@ BEGIN_TEST(parse1, "parse the signature line in a commit") must_be_true(strcmp(_email, person.email) == 0);\ must_be_true(_time == person.when.time);\ must_be_true(_offset == person.when.offset);\ - free(person.name); free(person.email);\ + git__free(person.name); git__free(person.email);\ } #define TEST_SIGNATURE_FAIL(_string, _header) { \ @@ -170,7 +170,7 @@ BEGIN_TEST(parse1, "parse the signature line in a commit") size_t len = strlen(_string);\ git_signature person = {NULL, NULL, {0, 0}}; \ must_fail(git_signature__parse(&person, &ptr, ptr + len, _header, '\n'));\ - free(person.name); free(person.email);\ + git__free(person.name); git__free(person.email);\ } TEST_SIGNATURE_PASS( @@ -690,6 +690,10 @@ BEGIN_TEST(write0, "write a new commit object from memory to disk") must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0); +#ifndef GIT_WIN32 + must_be_true((loose_object_mode(REPOSITORY_FOLDER, (git_object *)commit) & 0777) == GIT_OBJECT_FILE_MODE); +#endif + must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); git_commit_close(commit); @@ -759,9 +763,11 @@ BEGIN_TEST(root0, "create a root commit") must_pass(git_reference_set_target(head, head_old)); must_pass(git_reference_delete(branch)); must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); - free(head_old); + git__free(head_old); git_commit_close(commit); git_repository_free(repo); + + git_reference_free(head); END_TEST BEGIN_SUITE(commit) diff --git a/tests/t06-index.c b/tests/t06-index.c index 621e742b3..44562d004 100644 --- a/tests/t06-index.c +++ b/tests/t06-index.c @@ -176,10 +176,10 @@ BEGIN_TEST(add0, "add a new file to the index") must_pass(git_index_entrycount(index) == 0); /* Create a new file in the working directory */ - must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt")); + must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt", 0777)); must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0)); must_pass(git_filebuf_write(&file, "hey there\n", 10)); - must_pass(git_filebuf_commit(&file)); + must_pass(git_filebuf_commit(&file, 0666)); /* Store the expected hash of the file/blob * This has been generated by executing the following diff --git a/tests/t07-hashtable.c b/tests/t07-hashtable.c index c0e852259..41d52af19 100644 --- a/tests/t07-hashtable.c +++ b/tests/t07-hashtable.c @@ -103,7 +103,7 @@ BEGIN_TEST(table1, "fill the hashtable with random entries") } git_hashtable_free(table); - free(objects); + git__free(objects); END_TEST @@ -145,7 +145,7 @@ BEGIN_TEST(table2, "make sure the table resizes automatically") } git_hashtable_free(table); - free(objects); + git__free(objects); END_TEST @@ -179,7 +179,7 @@ BEGIN_TEST(tableit0, "iterate through all the contents of the table") must_be_true(objects[i].visited); git_hashtable_free(table); - free(objects); + git__free(objects); END_TEST diff --git a/tests/t08-tag.c b/tests/t08-tag.c index 216fb9dfc..44efb584d 100644 --- a/tests/t08-tag.c +++ b/tests/t08-tag.c @@ -189,12 +189,14 @@ BEGIN_TEST(write0, "write a tag to the repository and read it again") must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-tag")); must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0); must_pass(git_reference_delete(ref_tag)); +#ifndef GIT_WIN32 + must_be_true((loose_object_mode(REPOSITORY_FOLDER, (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE); +#endif must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag)); git_tag_close(tag); git_repository_free(repo); - END_TEST BEGIN_TEST(write2, "Attempt to write a tag bearing the same name than an already existing tag") @@ -263,6 +265,7 @@ BEGIN_TEST(write3, "Replace an already existing tag") close_temp_repo(repo); + git_reference_free(ref_tag); END_TEST BEGIN_TEST(write4, "write a lightweight tag to the repository and read it again") @@ -293,6 +296,8 @@ BEGIN_TEST(write4, "write a lightweight tag to the repository and read it again" must_pass(git_tag_delete(repo, "light-tag")); git_repository_free(repo); + + git_reference_free(ref_tag); END_TEST BEGIN_TEST(write5, "Attempt to write a lightweight tag bearing the same name than an already existing tag") @@ -331,6 +336,8 @@ BEGIN_TEST(delete0, "Delete an already existing tag") must_fail(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); close_temp_repo(repo); + + git_reference_free(ref_tag); END_TEST BEGIN_SUITE(tag) diff --git a/tests/t09-tree.c b/tests/t09-tree.c index 3af06ea67..2341a1ca4 100644 --- a/tests/t09-tree.c +++ b/tests/t09-tree.c @@ -200,6 +200,10 @@ BEGIN_TEST(write3, "write a hierarchical tree from a memory") // check data is correct must_pass(git_tree_lookup(&tree, repo, &id_hiearar)); must_be_true(2 == git_tree_entrycount(tree)); +#ifndef GIT_WIN32 + must_be_true((loose_object_dir_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_DIR_MODE); + must_be_true((loose_object_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_FILE_MODE); +#endif git_tree_close(tree); close_temp_repo(repo); diff --git a/tests/t10-refs.c b/tests/t10-refs.c index c7bfe4eea..e5e722992 100644 --- a/tests/t10-refs.c +++ b/tests/t10-refs.c @@ -42,8 +42,8 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference") must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(reference) & GIT_REF_OID); + must_be_true(git_reference_is_packed(reference) == 0); must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY)); @@ -56,6 +56,8 @@ BEGIN_TEST(readtag0, "lookup a loose tag reference") git_object_close(object); git_repository_free(repo); + + git_reference_free(reference); END_TEST BEGIN_TEST(readtag1, "lookup a loose tag reference that doesn't exist") @@ -66,6 +68,8 @@ BEGIN_TEST(readtag1, "lookup a loose tag reference that doesn't exist") must_fail(git_reference_lookup(&reference, repo, non_existing_tag_ref_name)); git_repository_free(repo); + + git_reference_free(reference); END_TEST static const char *head_tracker_sym_ref_name = "head-tracker"; @@ -81,12 +85,12 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference") must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE)); - must_be_true(reference->type & GIT_REF_SYMBOLIC); - must_be_true((reference->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(reference) & GIT_REF_SYMBOLIC); + must_be_true(git_reference_is_packed(reference) == 0); must_be_true(strcmp(reference->name, GIT_HEAD_FILE) == 0); must_pass(git_reference_resolve(&resolved_ref, reference)); - must_be_true(resolved_ref->type == GIT_REF_OID); + must_be_true(git_reference_type(resolved_ref) == GIT_REF_OID); must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY)); must_be_true(object != NULL); @@ -97,6 +101,9 @@ BEGIN_TEST(readsym0, "lookup a symbolic reference") git_object_close(object); git_repository_free(repo); + + git_reference_free(reference); + git_reference_free(resolved_ref); END_TEST BEGIN_TEST(readsym1, "lookup a nested symbolic reference") @@ -108,12 +115,12 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference") must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name)); - must_be_true(reference->type & GIT_REF_SYMBOLIC); - must_be_true((reference->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(reference) & GIT_REF_SYMBOLIC); + must_be_true(git_reference_is_packed(reference) == 0); must_be_true(strcmp(reference->name, head_tracker_sym_ref_name) == 0); must_pass(git_reference_resolve(&resolved_ref, reference)); - must_be_true(resolved_ref->type == GIT_REF_OID); + must_be_true(git_reference_type(resolved_ref) == GIT_REF_OID); must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY)); must_be_true(object != NULL); @@ -124,6 +131,9 @@ BEGIN_TEST(readsym1, "lookup a nested symbolic reference") git_object_close(object); git_repository_free(repo); + + git_reference_free(reference); + git_reference_free(resolved_ref); END_TEST BEGIN_TEST(readsym2, "lookup the HEAD and resolve the master branch") @@ -133,17 +143,22 @@ BEGIN_TEST(readsym2, "lookup the HEAD and resolve the master branch") must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name)); - must_pass(git_reference_resolve(&resolved_ref, reference)); - comp_base_ref = resolved_ref; + must_pass(git_reference_resolve(&comp_base_ref, reference)); + git_reference_free(reference); must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE)); must_pass(git_reference_resolve(&resolved_ref, reference)); must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref))); + git_reference_free(reference); + git_reference_free(resolved_ref); must_pass(git_reference_lookup(&reference, repo, current_head_target)); must_pass(git_reference_resolve(&resolved_ref, reference)); must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref))); + git_reference_free(reference); + git_reference_free(resolved_ref); + git_reference_free(comp_base_ref); git_repository_free(repo); END_TEST @@ -160,6 +175,10 @@ BEGIN_TEST(readsym3, "lookup the master branch and then the HEAD") must_pass(git_oid_cmp(git_reference_oid(master_ref), git_reference_oid(resolved_ref))); git_repository_free(repo); + + git_reference_free(reference); + git_reference_free(resolved_ref); + git_reference_free(master_ref); END_TEST static const char *packed_head_name = "refs/heads/packed"; @@ -173,8 +192,8 @@ BEGIN_TEST(readpacked0, "lookup a packed reference") must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, packed_head_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) != 0); + must_be_true(git_reference_type(reference) & GIT_REF_OID); + must_be_true(git_reference_is_packed(reference)); must_be_true(strcmp(reference->name, packed_head_name) == 0); must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY)); @@ -183,6 +202,8 @@ BEGIN_TEST(readpacked0, "lookup a packed reference") git_object_close(object); git_repository_free(repo); + + git_reference_free(reference); END_TEST BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a packed reference") @@ -192,11 +213,13 @@ BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a pac must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&reference, repo, packed_head_name)); must_pass(git_reference_lookup(&reference, repo, packed_test_head_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(reference) & GIT_REF_OID); + must_be_true(git_reference_is_packed(reference) == 0); must_be_true(strcmp(reference->name, packed_test_head_name) == 0); git_repository_free(repo); + + git_reference_free(reference); END_TEST BEGIN_TEST(create0, "create a new symbolic reference") @@ -219,13 +242,13 @@ BEGIN_TEST(create0, "create a new symbolic reference") /* Ensure the reference can be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); - must_be_true(looked_up_ref->type & GIT_REF_SYMBOLIC); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(looked_up_ref) & GIT_REF_SYMBOLIC); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); must_be_true(strcmp(looked_up_ref->name, new_head_tracker) == 0); /* ...peeled.. */ must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - must_be_true(resolved_ref->type == GIT_REF_OID); + must_be_true(git_reference_type(resolved_ref) == GIT_REF_OID); /* ...and that it points to the current master tip */ must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); @@ -240,6 +263,10 @@ BEGIN_TEST(create0, "create a new symbolic reference") must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); close_temp_repo(repo2); + + git_reference_free(new_reference); + git_reference_free(looked_up_ref); + git_reference_free(resolved_ref); END_TEST BEGIN_TEST(create1, "create a deep symbolic reference") @@ -261,6 +288,10 @@ BEGIN_TEST(create1, "create a deep symbolic reference") must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); close_temp_repo(repo); + + git_reference_free(new_reference); + git_reference_free(looked_up_ref); + git_reference_free(resolved_ref); END_TEST BEGIN_TEST(create2, "create a new OID reference") @@ -283,8 +314,8 @@ BEGIN_TEST(create2, "create a new OID reference") /* Ensure the reference can be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head)); - must_be_true(looked_up_ref->type & GIT_REF_OID); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_type(looked_up_ref) & GIT_REF_OID); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); must_be_true(strcmp(looked_up_ref->name, new_head) == 0); /* ...and that it points to the current master tip */ @@ -299,6 +330,9 @@ BEGIN_TEST(create2, "create a new OID reference") must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0); close_temp_repo(repo2); + + git_reference_free(new_reference); + git_reference_free(looked_up_ref); END_TEST BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unknown id") @@ -349,6 +383,9 @@ BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference") must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); close_temp_repo(repo); + + git_reference_free(ref); + git_reference_free(branch_ref); END_TEST BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") @@ -359,14 +396,14 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); /* Create it */ must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); must_pass(git_reference_lookup(&ref, repo, ref_test_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); /* Ensure we can't overwrite unless we force it */ @@ -378,6 +415,8 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") must_be_true(!git_oid_cmp(&id, git_reference_oid(ref))); close_temp_repo(repo); + + git_reference_free(ref); END_TEST BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symbolic one") @@ -388,7 +427,7 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); @@ -401,6 +440,8 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); close_temp_repo(repo); + + git_reference_free(ref); END_TEST BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object id one") @@ -411,7 +452,7 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); /* Create the symbolic ref */ @@ -426,17 +467,18 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object must_be_true(!git_oid_cmp(git_reference_oid(ref), &id)); close_temp_repo(repo); + + git_reference_free(ref); END_TEST BEGIN_TEST(pack0, "create a packfile for an empty folder") git_repository *repo; char temp_path[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"); - must_pass(git_futils_mkdir_r(temp_path, mode)); + must_pass(git_futils_mkdir_r(temp_path, GIT_REFS_DIR_MODE)); must_pass(git_reference_packall(repo)); @@ -452,7 +494,7 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") /* Ensure a known loose ref can be looked up */ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true((reference->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(reference) == 0); must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); /* @@ -468,7 +510,7 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") /* Ensure the known ref can still be looked up but is now packed */ must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true((reference->type & GIT_REF_PACKED) != 0); + must_be_true(git_reference_is_packed(reference)); must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); /* Ensure the known ref has been removed from the loose folder structure */ @@ -476,6 +518,8 @@ BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") must_pass(!git_futils_exists(temp_path)); close_temp_repo(repo); + + git_reference_free(reference); END_TEST BEGIN_TEST(rename0, "rename a loose reference") @@ -494,7 +538,7 @@ BEGIN_TEST(rename0, "rename a loose reference") must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name)); /* ... which is indeed loose */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); /* Now that the reference is renamed... */ must_pass(git_reference_rename(looked_up_ref, new_name, 0)); @@ -508,14 +552,17 @@ BEGIN_TEST(rename0, "rename a loose reference") must_be_true(!strcmp(another_looked_up_ref->name, new_name)); /* .. the ref is still loose... */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(another_looked_up_ref) == 0); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); /* ...and the ref can be found in the file system */ git_path_join(temp_path, repo->path_repository, new_name); must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); + git_reference_free(another_looked_up_ref); END_TEST BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") @@ -534,7 +581,7 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); /* .. and it's packed */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0); + must_be_true(git_reference_is_packed(looked_up_ref) != 0); /* Now that the reference is renamed... */ must_pass(git_reference_rename(looked_up_ref, brand_new_name, 0)); @@ -548,14 +595,17 @@ BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") must_be_true(!strcmp(another_looked_up_ref->name, brand_new_name)); /* .. the ref is no longer packed... */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(another_looked_up_ref) == 0); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); /* ...and the ref now happily lives in the file system */ git_path_join(temp_path, repo->path_repository, brand_new_name); must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); + git_reference_free(another_looked_up_ref); END_TEST BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference which happens to be in both loose and pack state") @@ -574,13 +624,13 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); /* Ensure it's loose */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(another_looked_up_ref) == 0); /* Lookup the reference to rename */ must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); /* Ensure it's packed */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0); + must_be_true(git_reference_is_packed(looked_up_ref) != 0); /* Now that the reference is renamed... */ must_pass(git_reference_rename(looked_up_ref, brand_new_name, 0)); @@ -589,12 +639,15 @@ BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); /* Ensure it's loose */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(another_looked_up_ref) == 0); /* Ensure the other ref still exists on the file system */ must_pass(git_futils_exists(temp_path)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); + git_reference_free(another_looked_up_ref); END_TEST BEGIN_TEST(rename3, "can not rename a reference with the name of an existing reference") @@ -614,6 +667,8 @@ BEGIN_TEST(rename3, "can not rename a reference with the name of an existing ref must_be_true(!strcmp(looked_up_ref->name, packed_head_name)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); END_TEST BEGIN_TEST(rename4, "can not rename a reference with an invalid name") @@ -636,6 +691,8 @@ BEGIN_TEST(rename4, "can not rename a reference with an invalid name") must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); END_TEST BEGIN_TEST(rename5, "can force-rename a packed reference with the name of an existing loose and packed reference") @@ -661,6 +718,8 @@ BEGIN_TEST(rename5, "can force-rename a packed reference with the name of an exi must_fail(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); close_temp_repo(repo); + + git_reference_free(looked_up_ref); END_TEST BEGIN_TEST(rename6, "can force-rename a loose reference with the name of an existing loose reference") @@ -686,6 +745,8 @@ BEGIN_TEST(rename6, "can force-rename a loose reference with the name of an exis must_fail(git_reference_lookup(&looked_up_ref, repo, "refs/heads/br2")); close_temp_repo(repo); + + git_reference_free(looked_up_ref); END_TEST static const char *ref_one_name = "refs/heads/one/branch"; @@ -700,7 +761,7 @@ BEGIN_TEST(rename7, "can not overwrite name of existing reference") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); @@ -718,6 +779,11 @@ BEGIN_TEST(rename7, "can not overwrite name of existing reference") must_fail(git_reference_lookup(&ref_one_new, repo, ref_one_name_new)); close_temp_repo(repo); + + git_reference_free(ref); + git_reference_free(ref_one); + git_reference_free(ref_one_new); + git_reference_free(ref_two); END_TEST static const char *ref_two_name_new = "refs/heads/two/two"; @@ -730,7 +796,7 @@ BEGIN_TEST(rename8, "can be renamed to a new name prefixed with the old name") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); @@ -749,6 +815,10 @@ BEGIN_TEST(rename8, "can be renamed to a new name prefixed with the old name") must_fail(git_reference_lookup(&looked_up_ref, repo, ref_two_name)); close_temp_repo(repo); + + git_reference_free(ref); + git_reference_free(ref_two); + git_reference_free(looked_up_ref); END_TEST BEGIN_TEST(rename9, "can move a reference to a upper reference hierarchy") @@ -759,7 +829,7 @@ BEGIN_TEST(rename9, "can move a reference to a upper reference hierarchy") must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); + must_be_true(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_oid(ref)); @@ -795,7 +865,7 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); /* Ensure it's the loose version that has been found */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); + must_be_true(git_reference_is_packed(looked_up_ref) == 0); /* Now that the reference is deleted... */ must_pass(git_reference_delete(looked_up_ref)); @@ -807,6 +877,42 @@ BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove must_pass(!git_futils_exists(temp_path)); close_temp_repo(repo); + + git_reference_free(another_looked_up_ref); +END_TEST + +BEGIN_TEST(delete1, "can delete a just packed reference") + git_reference *ref; + git_repository *repo; + git_oid id; + const char *new_ref = "refs/heads/new_ref"; + + git_oid_fromstr(&id, current_master_tip); + + must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); + + /* Create and write the new object id reference */ + must_pass(git_reference_create_oid(&ref, repo, new_ref, &id, 0)); + + /* Lookup the reference */ + must_pass(git_reference_lookup(&ref, repo, new_ref)); + + /* Ensure it's a loose reference */ + must_be_true(git_reference_is_packed(ref) == 0); + + /* Pack all existing references */ + must_pass(git_reference_packall(repo)); + + /* Reload the reference from disk */ + must_pass(git_reference_reload(ref)); + + /* Ensure it's a packed reference */ + must_be_true(git_reference_is_packed(ref) == 1); + + /* This should pass */ + must_pass(git_reference_delete(ref)); + + close_temp_repo(repo); END_TEST static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname) @@ -1102,6 +1208,9 @@ BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be r git_signature_free(committer); git_reflog_free(reflog); close_temp_repo(repo2); + + git_reference_free(ref); + git_reference_free(lookedup_ref); END_TEST BEGIN_TEST(reflog1, "avoid writing an obviously wrong reflog") @@ -1130,6 +1239,8 @@ BEGIN_TEST(reflog1, "avoid writing an obviously wrong reflog") git_signature_free(committer); close_temp_repo(repo); + + git_reference_free(ref); END_TEST BEGIN_SUITE(refs) @@ -1173,6 +1284,7 @@ BEGIN_SUITE(refs) ADD_TEST(rename9); ADD_TEST(delete0); + ADD_TEST(delete1); ADD_TEST(list0); ADD_TEST(list1); diff --git a/tests/t12-repo.c b/tests/t12-repo.c index de921f9ca..47dc852f3 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -173,7 +173,7 @@ END_TEST BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory") char path_repository[GIT_PATH_MAX]; char current_workdir[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0777; git_repository* repo; must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); @@ -232,7 +232,7 @@ BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of t char current_workdir[GIT_PATH_MAX]; char path_repository[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ + const mode_t mode = 0777; git_repository* repo; /* Setup the repository to open */ @@ -286,6 +286,8 @@ BEGIN_TEST(detached0, "test if HEAD is detached") must_be_true(git_repository_head_detached(repo) == 0); git_repository_free(repo); + + git_reference_free(ref); END_TEST BEGIN_TEST(orphan0, "test if HEAD is orphan") @@ -305,6 +307,8 @@ BEGIN_TEST(orphan0, "test if HEAD is orphan") must_be_true(git_repository_head_orphan(repo) == 0); git_repository_free(repo); + + git_reference_free(ref); END_TEST #define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git" @@ -351,7 +355,7 @@ static int write_file(const char *path, const char *content) return error; } - file = git_futils_creat_withpath(path, 0644); + file = git_futils_creat_withpath(path, 0777, 0666); if (file < GIT_SUCCESS) return file; @@ -384,7 +388,7 @@ BEGIN_TEST(discover0, "test discover") char repository_path[GIT_PATH_MAX]; char sub_repository_path[GIT_PATH_MAX]; char found_path[GIT_PATH_MAX]; - int mode = 0755; + const mode_t mode = 0777; git_futils_mkdir_r(DISCOVER_FOLDER, mode); must_pass(append_ceiling_dir(ceiling_dirs, TEMP_REPO_FOLDER)); diff --git a/tests/t15-config.c b/tests/t15-config.c index c4cb590f5..a97f82067 100644 --- a/tests/t15-config.c +++ b/tests/t15-config.c @@ -319,7 +319,7 @@ BEGIN_TEST(config16, "add a variable in a new section") /* As the section wasn't removed, owerwrite the file */ must_pass(git_filebuf_open(&buf, CONFIG_BASE "/config10", 0)); must_pass(git_filebuf_write(&buf, "[empty]\n", strlen("[empty]\n"))); - must_pass(git_filebuf_commit(&buf)); + must_pass(git_filebuf_commit(&buf, 0666)); END_TEST BEGIN_TEST(config17, "prefixes aren't broken") diff --git a/tests/t18-status.c b/tests/t18-status.c index ee9c5c668..3b75472ad 100644 --- a/tests/t18-status.c +++ b/tests/t18-status.c @@ -37,7 +37,7 @@ static int file_create(const char *filename, const char *content) { int fd; - fd = p_creat(filename, 0644); + fd = p_creat(filename, 0666); if (fd == 0) return GIT_ERROR; if (p_write(fd, content, strlen(content)) != 0) @@ -136,7 +136,7 @@ BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository") struct status_entry_counts counts; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); memset(&counts, 0x0, sizeof(struct status_entry_counts)); @@ -223,7 +223,7 @@ BEGIN_TEST(statuscb2, "test retrieving status for a purged worktree of an valid struct status_entry_counts counts; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); /* Purging the working */ @@ -309,12 +309,12 @@ BEGIN_TEST(statuscb3, "test retrieving status for a worktree where a file and a struct status_entry_counts counts; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "current_file", TEMP_REPO_FOLDER "swap")); - must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "subdir", TEMP_REPO_FOLDER "current_file")); - must_pass(git_futils_mv_atomic(TEMP_REPO_FOLDER "swap", TEMP_REPO_FOLDER "subdir")); + must_pass(p_rename(TEMP_REPO_FOLDER "current_file", TEMP_REPO_FOLDER "swap")); + must_pass(p_rename(TEMP_REPO_FOLDER "subdir", TEMP_REPO_FOLDER "current_file")); + must_pass(p_rename(TEMP_REPO_FOLDER "swap", TEMP_REPO_FOLDER "subdir")); must_pass(file_create(TEMP_REPO_FOLDER ".HEADER", "dummy")); must_pass(file_create(TEMP_REPO_FOLDER "42-is-not-prime.sigh", "dummy")); @@ -341,7 +341,7 @@ BEGIN_TEST(singlestatus0, "test retrieving status for single file") int i; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); for (i = 0; i < ENTRY_COUNT0; ++i) { @@ -360,7 +360,7 @@ BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file") int error; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); // "nonexistent" does not exist in HEAD, Index or the worktree @@ -400,7 +400,7 @@ BEGIN_TEST(singlestatus3, "test retrieving status for a new file in an empty rep must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); git_path_join(file_path, TEMP_REPO_FOLDER, filename); - fd = p_creat(file_path, 0644); + fd = p_creat(file_path, 0666); must_pass(fd); must_pass(p_write(fd, "new_file\n", 9)); must_pass(p_close(fd)); @@ -421,7 +421,7 @@ BEGIN_TEST(singlestatus4, "can't determine the status for a folder") int error; must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); + must_pass(p_rename(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); error = git_status_file(&status_flags, repo, "subdir"); diff --git a/tests/test_helpers.c b/tests/test_helpers.c index cb95607e1..31e38bf6a 100644 --- a/tests/test_helpers.c +++ b/tests/test_helpers.c @@ -42,7 +42,7 @@ int write_object_data(char *file, void *data, size_t len) int write_object_files(const char *odb_dir, object_data *d) { - if (p_mkdir(odb_dir, 0755) < 0) { + if (p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE) < 0) { int err = errno; fprintf(stderr, "can't make directory \"%s\"", odb_dir); if (err == EEXIST) @@ -51,7 +51,7 @@ int write_object_files(const char *odb_dir, object_data *d) return -1; } - if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) { + if ((p_mkdir(d->dir, GIT_OBJECT_DIR_MODE) < 0) && (errno != EEXIST)) { fprintf(stderr, "can't make object directory \"%s\"\n", d->dir); return -1; } @@ -82,7 +82,7 @@ int remove_object_files(const char *odb_dir, object_data *d) return 0; } -int remove_loose_object(const char *repository_folder, git_object *object) +void locate_loose_object(const char *repository_folder, git_object *object, char **out, char **out_folder) { static const char *objects_folder = "objects/"; @@ -104,6 +104,54 @@ int remove_loose_object(const char *repository_folder, git_object *object) ptr += GIT_OID_HEXSZ + 1; *ptr = 0; + *out = full_path; + + if (out_folder) + *out_folder = top_folder; +} + +int loose_object_mode(const char *repository_folder, git_object *object) +{ + char *object_path; + struct stat st; + + locate_loose_object(repository_folder, object, &object_path, NULL); + if (p_stat(object_path, &st) < 0) + return 0; + free(object_path); + + return st.st_mode; +} + +int loose_object_dir_mode(const char *repository_folder, git_object *object) +{ + char *object_path; + size_t pos; + struct stat st; + + locate_loose_object(repository_folder, object, &object_path, NULL); + + pos = strlen(object_path); + while (pos--) { + if (object_path[pos] == '/') { + object_path[pos] = 0; + break; + } + } + + if (p_stat(object_path, &st) < 0) + return 0; + free(object_path); + + return st.st_mode; +} + +int remove_loose_object(const char *repository_folder, git_object *object) +{ + char *full_path, *top_folder; + + locate_loose_object(repository_folder, object, &full_path, &top_folder); + if (p_unlink(full_path) < 0) { fprintf(stderr, "can't delete object file \"%s\"\n", full_path); return -1; @@ -116,7 +164,7 @@ int remove_loose_object(const char *repository_folder, git_object *object) return -1; } - free(full_path); + git__free(full_path); return GIT_SUCCESS; } @@ -141,7 +189,7 @@ int copy_file(const char *src, const char *dst) if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS) return GIT_ENOTFOUND; - dst_fd = git_futils_creat_withpath(dst, 0644); + dst_fd = git_futils_creat_withpath(dst, 0777, 0666); if (dst_fd < 0) goto cleanup; diff --git a/tests/test_helpers.h b/tests/test_helpers.h index 53361b7b1..16a3a2ced 100644 --- a/tests/test_helpers.h +++ b/tests/test_helpers.h @@ -63,6 +63,11 @@ extern int remove_object_files(const char *odb_dir, object_data *d); extern int cmp_objects(git_rawobj *o, object_data *d); +extern void locate_loose_object(const char *odb_dir, git_object *object, char **out, char **out_folder); + +extern int loose_object_mode(const char *odb_dir, git_object *object); +extern int loose_object_dir_mode(const char *odb_dir, git_object *object); + extern int remove_loose_object(const char *odb_dir, git_object *object); extern int cmp_files(const char *a, const char *b); diff --git a/tests/test_lib.c b/tests/test_lib.c index e67ad347a..9d3cba1a6 100755 --- a/tests/test_lib.c +++ b/tests/test_lib.c @@ -88,8 +88,8 @@ static void fail_test(git_test *tc, const char *file, int line, const char *mess tc->failed = 1; tc->message = strdup(message); tc->failed_pos = strdup(buf); - tc->error_stack = git_errno; - git_errno = NULL; + tc->error_stack = GIT_GLOBAL->git_errno; + GIT_GLOBAL->git_errno = NULL; if (last_error) tc->error_message = strdup(last_error); diff --git a/tests/test_lib.h b/tests/test_lib.h index 9d90e4847..7552ebf12 100755 --- a/tests/test_lib.h +++ b/tests/test_lib.h @@ -7,6 +7,7 @@ #include <string.h> #include "common.h" +#include "global.h" #include <git2.h> #define DECLARE_SUITE(SNAME) extern git_testsuite *libgit2_suite_##SNAME(void) diff --git a/tests/test_main.c b/tests/test_main.c index c9f8da3a4..9961ffd6b 100644 --- a/tests/test_main.c +++ b/tests/test_main.c @@ -26,6 +26,8 @@ #include <string.h> #include <git2.h> +#include "posix.h" + #include "test_lib.h" #include "test_helpers.h" @@ -81,6 +83,8 @@ main(int GIT_UNUSED(argc), char *GIT_UNUSED(argv[])) GIT_UNUSED_ARG(argc); GIT_UNUSED_ARG(argv); + p_umask(0); + failures = 0; for (i = 0; i < GIT_SUITE_COUNT; ++i) |