Commit 845eed80 by Vicent Martí

Merge pull request #1962 from libgit2/rename-tests

Rename tests directory
parents 7b947bf5 83e1efbf

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

/tests-clar/clar.suite
/tests-clar/clar.suite.rule
/tests-clar/.clarcache
/tests/clar.suite
/tests/clar.suite.rule
/tests/.clarcache
/apidocs
/trash-*.exe
/libgit2.pc
......
......@@ -97,7 +97,7 @@ ENDFUNCTION()
# explorer does. This is esp. useful with the libgit2_clar project, were
# usually 2 or more files share the same name. Sadly, this file grouping
# is a per-directory option in cmake and not per-target, resulting in
# empty virtual folders "tests-clar" for the git2.dll
# empty virtual folders "tests" for the git2.dll
FUNCTION(MSVC_SPLIT_SOURCES target)
IF(MSVC_IDE)
GET_TARGET_PROPERTY(sources ${target} SOURCES)
......@@ -393,9 +393,9 @@ INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} )
IF (BUILD_CLAR)
FIND_PACKAGE(PythonInterp REQUIRED)
SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests-clar/resources/")
SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests-clar")
SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests-clar/resources" CACHE PATH "Path to test resources.")
SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/")
SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests")
SET(CLAR_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.")
ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
ADD_DEFINITIONS(-DCLAR_RESOURCES=\"${TEST_RESOURCES}\")
......
......@@ -66,7 +66,7 @@ int main (int argc, char** argv)
// simplest. There are also [methods][me] for specifying the index file
// and work tree locations, here we assume they are in the normal places.
//
// (Try running this program against tests-clar/resources/testrepo.git.)
// (Try running this program against tests/resources/testrepo.git.)
//
// [me]: http://libgit2.github.com/libgit2/#HEAD/group/repository
int error;
......
......@@ -4,7 +4,7 @@ THIS_FILE="$(readlink -f "$0")"
ROOT="$(dirname "$(dirname "$(dirname "$THIS_FILE")")")"
PROGRAM="$ROOT"/examples/rev-list
LIBDIR="$ROOT"/build
REPO="$ROOT"/tests-clar/resources/testrepo.git
REPO="$ROOT"/tests/resources/testrepo.git
cd "$REPO"
......
......@@ -38,7 +38,7 @@
* `git_packbuilder_set_threads` can be used to adjust the number of
* threads used for the process.
*
* See tests-clar/pack/packbuilder.c for an example.
* See tests/pack/packbuilder.c for an example.
*
* @ingroup Git
* @{
......
int reference_is_packed(git_reference *ref);
#include "clar_libgit2.h"
#include "buffer.h"
static git_repository *_repo;
void test_repo_hashfile__initialize(void)
{
_repo = cl_git_sandbox_init("status");
}
void test_repo_hashfile__cleanup(void)
{
cl_git_sandbox_cleanup();
_repo = NULL;
}
void test_repo_hashfile__simple(void)
{
git_oid a, b;
git_buf full = GIT_BUF_INIT;
/* hash with repo relative path */
cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJ_BLOB, NULL));
cl_assert(git_oid_equal(&a, &b));
cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
/* hash with full path */
cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_BLOB, NULL));
cl_assert(git_oid_equal(&a, &b));
/* hash with invalid type */
cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJ_ANY));
cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJ_OFS_DELTA, NULL));
git_buf_free(&full);
}
void test_repo_hashfile__filtered(void)
{
git_oid a, b;
cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
/* create some sample content with CRLF in it */
cl_git_mkfile("status/testfile.txt", "content\r\n");
cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
/* not equal hashes because of filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, NULL));
cl_assert(git_oid_cmp(&a, &b));
/* equal hashes because filter is binary */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, NULL));
cl_assert(git_oid_equal(&a, &b));
/* equal hashes when 'as_file' points to binary filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, "foo.bin"));
cl_assert(git_oid_equal(&a, &b));
/* not equal hashes when 'as_file' points to text filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, "foo.txt"));
cl_assert(git_oid_cmp(&a, &b));
/* equal hashes when 'as_file' is empty and turns off filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_BLOB, ""));
cl_assert(git_oid_equal(&a, &b));
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJ_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJ_BLOB, ""));
cl_assert(git_oid_equal(&a, &b));
/* some hash type failures */
cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJ_ANY, NULL));
}
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"
static git_repository *repo;
void test_repo_head__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_head__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_head__head_detached(void)
{
git_reference *ref;
cl_git_pass(git_repository_head_detached(repo));
cl_git_pass(git_repository_detach_head(repo));
cl_assert_equal_i(true, git_repository_head_detached(repo));
/* take the reop back to it's original state */
cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1));
git_reference_free(ref);
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
void test_repo_head__unborn_head(void)
{
git_reference *ref;
cl_git_pass(git_repository_head_detached(repo));
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert(git_repository_head_unborn(repo) == 1);
/* take the repo back to it's original state */
cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1));
cl_assert(git_repository_head_unborn(repo) == 0);
git_reference_free(ref);
}
void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_doesnt_exist(void)
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet"));
}
void test_repo_head__set_head_Fails_when_the_reference_points_to_a_non_commitish(void)
{
cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob"));
}
void test_repo_head__set_head_Attaches_HEAD_when_the_reference_points_to_a_branch(void)
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/br2"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_head(&head, repo));
cl_assert_equal_s("refs/heads/br2", git_reference_name(head));
git_reference_free(head);
}
static void assert_head_is_correctly_detached(void)
{
git_reference *head;
git_object *commit;
cl_assert_equal_i(true, git_repository_head_detached(repo));
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_object_lookup(&commit, repo, git_reference_target(head), GIT_OBJ_COMMIT));
git_object_free(commit);
git_reference_free(head);
}
void test_repo_head__set_head_Detaches_HEAD_when_the_reference_doesnt_point_to_a_branch(void)
{
cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
cl_assert_equal_i(true, git_repository_head_detached(repo));
assert_head_is_correctly_detached();
}
void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_exist(void)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid));
}
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
{
git_object *blob;
cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));
cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));
git_object_free(blob);
}
void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
{
git_object *tag;
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
assert_head_is_correctly_detached();
git_object_free(tag);
}
void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_detach_head(repo));
assert_head_is_correctly_detached();
}
void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void)
{
git_reference *head;
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1));
cl_git_fail(git_repository_detach_head(repo));
git_reference_free(head);
}
void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo));
}
void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
git_reference *head;
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
{
git_reference *head;
delete_head(repo);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo));
}
void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "buffer.h"
#include "posix.h"
#include "util.h"
#include "path.h"
#include "fileops.h"
static git_repository *repo;
void test_repo_setters__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_must_pass(p_mkdir("new_workdir", 0777));
}
void test_repo_setters__cleanup(void)
{
git_repository_free(repo);
repo = NULL;
cl_fixture_cleanup("testrepo.git");
cl_fixture_cleanup("new_workdir");
}
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
{
cl_assert(git_repository_is_bare(repo) == 1);
cl_assert(git_repository_workdir(repo) == NULL);
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git_repository_is_bare(repo) == 0);
}
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
{
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git__suffixcmp(git_repository_workdir(repo), "new_workdir/") == 0);
}
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
const char *val;
git_buf content = GIT_BUF_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
cl_assert(git_path_isfile("./new_workdir/.git"));
cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
git_buf_free(&content);
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_get_string(&val, cfg, "core.worktree"));
cl_assert(git__suffixcmp(val, "new_workdir/") == 0);
git_config_free(cfg);
}
void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void)
{
git_index *new_index;
cl_git_pass(git_index_open(&new_index, "./my-index"));
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_repository_set_index(repo, new_index);
cl_assert(((git_refcount *)new_index)->refcount.val == 2);
git_repository_free(repo);
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_index_free(new_index);
/*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
}
void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_properly_honors_the_refcount(void)
{
git_odb *new_odb;
cl_git_pass(git_odb_open(&new_odb, "./testrepo.git/objects"));
cl_assert(((git_refcount *)new_odb)->refcount.val == 1);
git_repository_set_odb(repo, new_odb);
cl_assert(((git_refcount *)new_odb)->refcount.val == 2);
git_repository_free(repo);
cl_assert(((git_refcount *)new_odb)->refcount.val == 1);
git_odb_free(new_odb);
/*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
}
#include "clar_libgit2.h"
#include "buffer.h"
#include "refs.h"
#include "posix.h"
#include "fileops.h"
static git_repository *_repo;
static git_buf _path;
void test_repo_state__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_state__cleanup(void)
{
cl_git_sandbox_cleanup();
git_buf_free(&_path);
}
static void setup_simple_state(const char *filename)
{
cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
cl_git_mkfile(git_buf_cstr(&_path), "dummy");
}
static void assert_repo_state(git_repository_state_t state)
{
cl_assert_equal_i(state, git_repository_state(_repo));
}
void test_repo_state__none_with_HEAD_attached(void)
{
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__none_with_HEAD_detached(void)
{
cl_git_pass(git_repository_detach_head(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__merge(void)
{
setup_simple_state(GIT_MERGE_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_MERGE);
}
void test_repo_state__revert(void)
{
setup_simple_state(GIT_REVERT_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REVERT);
}
void test_repo_state__cherry_pick(void)
{
setup_simple_state(GIT_CHERRY_PICK_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_CHERRY_PICK);
}
void test_repo_state__bisect(void)
{
setup_simple_state(GIT_BISECT_LOG_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_BISECT);
}
void test_repo_state__rebase_interactive(void)
{
setup_simple_state(GIT_REBASE_MERGE_INTERACTIVE_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_INTERACTIVE);
}
void test_repo_state__rebase_merge(void)
{
setup_simple_state(GIT_REBASE_MERGE_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_MERGE);
}
void test_repo_state__rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_REBASING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE);
}
void test_repo_state__apply_mailbox(void)
{
setup_simple_state(GIT_REBASE_APPLY_APPLYING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX);
}
void test_repo_state__apply_mailbox_or_rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE);
}
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
static git_repository *_repo;
static git_object *_target;
static git_strarray _pathspecs;
static git_index *_index;
static void initialize(const char *repo_name)
{
_repo = cl_git_sandbox_init(repo_name);
cl_git_pass(git_repository_index(&_index, _repo));
_target = NULL;
_pathspecs.strings = NULL;
_pathspecs.count = 0;
}
void test_reset_default__initialize(void)
{
initialize("status");
}
void test_reset_default__cleanup(void)
{
git_object_free(_target);
_target = NULL;
git_index_free(_index);
_index = NULL;
cl_git_sandbox_cleanup();
}
static void assert_content_in_index(
git_strarray *pathspecs,
bool should_exist,
git_strarray *expected_shas)
{
size_t i, pos;
int error;
for (i = 0; i < pathspecs->count; i++) {
error = git_index_find(&pos, _index, pathspecs->strings[i]);
if (should_exist) {
const git_index_entry *entry;
cl_assert(error != GIT_ENOTFOUND);
entry = git_index_get_byindex(_index, pos);
cl_assert(entry != NULL);
if (!expected_shas)
continue;
cl_git_pass(git_oid_streq(&entry->oid, expected_shas->strings[i]));
} else
cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND);
}
}
void test_reset_default__resetting_filepaths_against_a_null_target_removes_them_from_the_index(void)
{
char *paths[] = { "staged_changes", "staged_new_file" };
_pathspecs.strings = paths;
_pathspecs.count = 2;
assert_content_in_index(&_pathspecs, true, NULL);
cl_git_pass(git_reset_default(_repo, NULL, &_pathspecs));
assert_content_in_index(&_pathspecs, false, NULL);
}
/*
* $ git ls-files --cached -s --abbrev=7 -- "staged*"
* 100644 55d316c 0 staged_changes
* 100644 a6be623 0 staged_changes_file_deleted
* ...
*
* $ git reset 0017bd4 -- staged_changes staged_changes_file_deleted
* Unstaged changes after reset:
* ...
*
* $ git ls-files --cached -s --abbrev=7 -- "staged*"
* 100644 32504b7 0 staged_changes
* 100644 061d42a 0 staged_changes_file_deleted
* ...
*/
void test_reset_default__resetting_filepaths_replaces_their_corresponding_index_entries(void)
{
git_strarray before, after;
char *paths[] = { "staged_changes", "staged_changes_file_deleted" };
char *before_shas[] = { "55d316c9ba708999f1918e9677d01dfcae69c6b9",
"a6be623522ce87a1d862128ac42672604f7b468b" };
char *after_shas[] = { "32504b727382542f9f089e24fddac5e78533e96c",
"061d42a44cacde5726057b67558821d95db96f19" };
_pathspecs.strings = paths;
_pathspecs.count = 2;
before.strings = before_shas;
before.count = 2;
after.strings = after_shas;
after.count = 2;
cl_git_pass(git_revparse_single(&_target, _repo, "0017bd4"));
assert_content_in_index(&_pathspecs, true, &before);
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, true, &after);
}
/*
* $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
* 100644 1f85ca5 1 conflicts-one.txt
* 100644 6aea5f2 2 conflicts-one.txt
* 100644 516bd85 3 conflicts-one.txt
*
* $ git reset 9a05ccb -- conflicts-one.txt
* Unstaged changes after reset:
* ...
*
* $ git ls-files --cached -s --abbrev=7 -- conflicts-one.txt
* 100644 1f85ca5 0 conflicts-one.txt
*
*/
void test_reset_default__resetting_filepaths_clears_previous_conflicts(void)
{
const git_index_entry *conflict_entry[3];
git_strarray after;
char *paths[] = { "conflicts-one.txt" };
char *after_shas[] = { "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81" };
test_reset_default__cleanup();
initialize("mergedrepo");
_pathspecs.strings = paths;
_pathspecs.count = 1;
after.strings = after_shas;
after.count = 1;
cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
&conflict_entry[2], _index, "conflicts-one.txt"));
cl_git_pass(git_revparse_single(&_target, _repo, "9a05ccb"));
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, true, &after);
cl_assert_equal_i(GIT_ENOTFOUND, git_index_conflict_get(&conflict_entry[0],
&conflict_entry[1], &conflict_entry[2], _index, "conflicts-one.txt"));
}
/*
$ git reset HEAD -- "I_am_not_there.txt" "me_neither.txt"
Unstaged changes after reset:
...
*/
void test_reset_default__resetting_unknown_filepaths_does_not_fail(void)
{
char *paths[] = { "I_am_not_there.txt", "me_neither.txt" };
_pathspecs.strings = paths;
_pathspecs.count = 2;
assert_content_in_index(&_pathspecs, false, NULL);
cl_git_pass(git_revparse_single(&_target, _repo, "HEAD"));
cl_git_pass(git_reset_default(_repo, _target, &_pathspecs));
assert_content_in_index(&_pathspecs, false, NULL);
}
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
#include "fileops.h"
static git_repository *repo;
static git_object *target;
void test_reset_hard__initialize(void)
{
repo = cl_git_sandbox_init("status");
target = NULL;
}
void test_reset_hard__cleanup(void)
{
if (target != NULL) {
git_object_free(target);
target = NULL;
}
cl_git_sandbox_cleanup();
}
static int strequal_ignore_eol(const char *exp, const char *str)
{
while (*exp && *str) {
if (*exp != *str) {
while (*exp == '\r' || *exp == '\n') ++exp;
while (*str == '\r' || *str == '\n') ++str;
if (*exp != *str)
return false;
} else {
exp++; str++;
}
}
return (!*exp && !*str);
}
void test_reset_hard__resetting_reverts_modified_files(void)
{
git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT;
int i;
static const char *files[4] = {
"current_file",
"modified_file",
"staged_new_file",
"staged_changes_modified_file" };
static const char *before[4] = {
"current_file\n",
"modified_file\nmodified_file\n",
"staged_new_file\n",
"staged_changes_modified_file\nstaged_changes_modified_file\nstaged_changes_modified_file\n"
};
static const char *after[4] = {
"current_file\n",
"modified_file\n",
NULL,
"staged_changes_modified_file\n"
};
const char *wd = git_repository_workdir(repo);
cl_assert(wd);
for (i = 0; i < 4; ++i) {
cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert_equal_s(before[i], content.ptr);
}
retrieve_target_from_oid(
&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
for (i = 0; i < 4; ++i) {
cl_git_pass(git_buf_joinpath(&path, wd, files[i]));
if (after[i]) {
cl_git_pass(git_futils_readbuffer(&content, path.ptr));
cl_assert(strequal_ignore_eol(after[i], content.ptr));
} else {
cl_assert(!git_path_exists(path.ptr));
}
}
git_buf_free(&content);
git_buf_free(&path);
}
void test_reset_hard__cannot_reset_in_a_bare_repository(void)
{
git_repository *bare;
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD));
git_repository_free(bare);
}
static void index_entry_init(git_index *index, int side, git_oid *oid)
{
git_index_entry entry;
memset(&entry, 0x0, sizeof(git_index_entry));
entry.path = "conflicting_file";
entry.flags = (side << GIT_IDXENTRY_STAGESHIFT);
entry.mode = 0100644;
git_oid_cpy(&entry.oid, oid);
cl_git_pass(git_index_add(index, &entry));
}
static void unmerged_index_init(git_index *index, int entries)
{
int write_ancestor = 1;
int write_ours = 2;
int write_theirs = 4;
git_oid ancestor, ours, theirs;
git_oid_fromstr(&ancestor, "6bb0d9f700543ba3d318ba7075fc3bd696b4287b");
git_oid_fromstr(&ours, "b19a1e93bec1317dc6097229e12afaffbfa74dc2");
git_oid_fromstr(&theirs, "950b81b7eee953d050aa05a641f8e056c85dd1bd");
cl_git_rewritefile("status/conflicting_file", "conflicting file\n");
if (entries & write_ancestor)
index_entry_init(index, 1, &ancestor);
if (entries & write_ours)
index_entry_init(index, 2, &ours);
if (entries & write_theirs)
index_entry_init(index, 3, &theirs);
}
void test_reset_hard__resetting_reverts_unmerged(void)
{
git_index *index;
int entries;
/* Ensure every permutation of non-zero stage entries results in the
* path being cleaned up. */
for (entries = 1; entries < 8; entries++) {
cl_git_pass(git_repository_index(&index, repo));
unmerged_index_init(index, entries);
cl_git_pass(git_index_write(index));
retrieve_target_from_oid(&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
cl_assert(git_path_exists("status/conflicting_file") == 0);
git_object_free(target);
target = NULL;
git_index_free(index);
}
}
void test_reset_hard__cleans_up_merge(void)
{
git_buf merge_head_path = GIT_BUF_INIT,
merge_msg_path = GIT_BUF_INIT,
merge_mode_path = GIT_BUF_INIT,
orig_head_path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
cl_git_pass(git_buf_joinpath(&merge_msg_path, git_repository_path(repo), "MERGE_MSG"));
cl_git_mkfile(git_buf_cstr(&merge_msg_path), "Merge commit 0017bd4ab1ec30440b17bae1680cff124ab5f1f6\n");
cl_git_pass(git_buf_joinpath(&merge_mode_path, git_repository_path(repo), "MERGE_MODE"));
cl_git_mkfile(git_buf_cstr(&merge_mode_path), "");
cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
retrieve_target_from_oid(&target, repo, "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
cl_assert(!git_path_exists(git_buf_cstr(&merge_msg_path)));
cl_assert(!git_path_exists(git_buf_cstr(&merge_mode_path)));
cl_assert(git_path_exists(git_buf_cstr(&orig_head_path)));
cl_git_pass(p_unlink(git_buf_cstr(&orig_head_path)));
git_buf_free(&merge_head_path);
git_buf_free(&merge_msg_path);
git_buf_free(&merge_mode_path);
git_buf_free(&orig_head_path);
}
#include "clar_libgit2.h"
#include "posix.h"
#include "reset_helpers.h"
#include "path.h"
#include "repo/repo_helpers.h"
static git_repository *repo;
static git_object *target;
void test_reset_soft__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
}
void test_reset_soft__cleanup(void)
{
git_object_free(target);
target = NULL;
cl_git_sandbox_cleanup();
}
static void assert_reset_soft(bool should_be_detached)
{
git_oid oid;
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
cl_assert(git_repository_head_detached(repo) == should_be_detached);
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
cl_assert(git_repository_head_detached(repo) == should_be_detached);
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
}
void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(void)
{
assert_reset_soft(false);
}
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
git_repository_detach_head(repo);
assert_reset_soft(true);
}
void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void)
{
git_oid oid;
char raw_head_oid[GIT_OID_HEXSZ + 1];
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
git_oid_fmt(raw_head_oid, &oid);
raw_head_oid[GIT_OID_HEXSZ] = '\0';
retrieve_target_from_oid(&target, repo, raw_head_oid);
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, raw_head_oid));
}
void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void)
{
git_oid oid;
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
cl_assert(git_repository_head_detached(repo) == false);
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
}
void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
{
/* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
}
void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_longer_unborn(void)
{
git_reference *head;
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(true, git_repository_head_unborn(repo));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
cl_assert_equal_i(false, git_repository_head_unborn(repo));
cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD));
cl_assert_equal_i(0, git_oid_streq(git_reference_target(head), KNOWN_COMMIT_IN_BARE_REPO));
git_reference_free(head);
}
void test_reset_soft__fails_when_merging(void)
{
git_buf merge_head_path = GIT_BUF_INIT;
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
git_buf_free(&merge_head_path);
}
void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE_HEAD_file_existence(void)
{
git_index *index;
git_reference *head;
git_buf merge_head_path = GIT_BUF_INIT;
cl_git_sandbox_cleanup();
repo = cl_git_sandbox_init("mergedrepo");
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
git_buf_free(&merge_head_path);
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_i(true, git_index_has_conflicts(index));
git_index_free(index);
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel(&target, head, GIT_OBJ_COMMIT));
git_reference_free(head);
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT));
}
Unnamed repository; edit this file 'description' to name the repository.
* repoattr
a* foo !bar -baz
sub/*.txt reposub
sub/sub/*.txt reposubsub
0000000000000000000000000000000000000000 6bab5c79cd5140d0f800917f550eb2a3dc32b0da Russell Belfer <arrbee@arrbee.com> 1324416995 -0800 commit (initial): initial test data
6bab5c79cd5140d0f800917f550eb2a3dc32b0da 605812ab7fe421fdd325a935d35cb06a9234a7d7 Russell Belfer <arrbee@arrbee.com> 1325143098 -0800 commit: latest test updates
605812ab7fe421fdd325a935d35cb06a9234a7d7 a5d76cad53f66f1312bd995909a5bab3c0820770 Russell Belfer <arrbee@arrbee.com> 1325281762 -0800 commit: more macro tests
a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a Russell Belfer <arrbee@arrbee.com> 1327611749 -0800 commit: Updating files so we can do diffs
370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a f5b0af1fb4f5c0cd7aad880711d368a07333c307 Russell Belfer <arrbee@arrbee.com> 1327621027 -0800 commit: Updating test data
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
0000000000000000000000000000000000000000 6bab5c79cd5140d0f800917f550eb2a3dc32b0da Russell Belfer <arrbee@arrbee.com> 1324416995 -0800 commit (initial): initial test data
6bab5c79cd5140d0f800917f550eb2a3dc32b0da 605812ab7fe421fdd325a935d35cb06a9234a7d7 Russell Belfer <arrbee@arrbee.com> 1325143098 -0800 commit: latest test updates
605812ab7fe421fdd325a935d35cb06a9234a7d7 a5d76cad53f66f1312bd995909a5bab3c0820770 Russell Belfer <arrbee@arrbee.com> 1325281762 -0800 commit: more macro tests
a5d76cad53f66f1312bd995909a5bab3c0820770 370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a Russell Belfer <arrbee@arrbee.com> 1327611749 -0800 commit: Updating files so we can do diffs
370fe9ec224ce33e71f9e5ec2bd1142ce9937a6a f5b0af1fb4f5c0cd7aad880711d368a07333c307 Russell Belfer <arrbee@arrbee.com> 1327621027 -0800 commit: Updating test data
f5b0af1fb4f5c0cd7aad880711d368a07333c307 a97cc019851d401a4f1d091cb91a15890a0dd1ba Russell Belfer <arrbee@arrbee.com> 1328653313 -0800 commit: Some whitespace only changes for testing purposes
a97cc019851d401a4f1d091cb91a15890a0dd1ba 217878ab49e1314388ea2e32dc6fdb58a1b969e0 Russell Belfer <arrbee@arrbee.com> 1332734901 -0700 commit: added files in sub/sub
217878ab49e1314388ea2e32dc6fdb58a1b969e0 24fa9a9fc4e202313e24b648087495441dab432b Russell Belfer <arrbee@arrbee.com> 1332735555 -0700 commit: adding more files in sub for tree status
24fa9a9fc4e202313e24b648087495441dab432b 8d0b9df9bd30be7910ddda60548d485bc302b911 yorah <yoram.harmelin@gmail.com> 1341230701 +0200 commit: Updating test data so we can test inter-hunk-context
# variations on assignments
pat0 simple
pat1 -neg
* notundef
pat2 !notundef
pat3 assigned=test-value
pat4 rule-with-more-chars=value-with-more-chars
pat5 empty=
pat6 -negempty=
pat7 multiple -single values=1 also=a-really-long-value/* happy=yes!
# the next line has trailing spaces
pat8 again= another=12321
patbad0 # empty assignment does not count
# next line will be another simple empty assign that should not count
patbad1
# BTW I think there are 11 valid rules and two "invalid" empty ones
pat9 -at-eof
\ No newline at end of file
123
\ No newline at end of file
* rootattr
root_test2 -rootattr
root_test3 !rootattr
binfile binary
abc foo bar baz
does-not-exist foo=yes
root_test2 multiattr
root_test3 multi2=foo
root_test3 multiattr=1 multiattr=2 multiattr=3 multi2=abc !multi2
root_test2 multiattr=string -multiattr
[attr]mymacro positive -negative !rootattr
macro* mymacro another=77
[attr]macro2 multi2 -multi2 multi3 !multi3 multi3=answer
macro* macro2 macro2 macro2
# let's try some malicious macro defs
[attr]firstmacro -thirdmacro -secondmacro
[attr]secondmacro firstmacro -firstmacro
[attr]thirdmacro secondmacro=hahaha
macro_bad firstmacro secondmacro thirdmacro
# another test that Peff found was failing
[attr]notest !test
Hello from the root
Some additional lines
Down here below
# Test file from gitattributes(5) example:
If you have these three gitattributes file:
(in $GIT_DIR/info/attributes)
a* foo !bar -baz
(in .gitattributes)
abc foo bar baz
(in t/.gitattributes)
ab* merge=filfre
abc -foo -bar
*.c frotz
the attributes given to path t/abc are computed as follows:
1. By examining t/.gitattributes (which is in the same directory as the path
in question), git finds that the first line matches. merge attribute is
set. It also finds that the second line matches, and attributes foo and
bar are unset.
2. Then it examines .gitattributes (which is in the parent directory), and
finds that the first line matches, but t/.gitattributes file already
decided how merge, foo and bar attributes should be given to this path,
so it leaves foo and bar unset. Attribute baz is set.
3. Finally it examines $GIT_DIR/info/attributes. This file is used to
override the in-tree settings. The first line is a match, and foo is set,
bar is reverted to unspecified state, and baz is unset.
As the result, the attributes assignment to t/abc becomes:
foo set to true
bar unspecified
baz set to false
merge set to string value "filfre"
frotz unspecified
Unnamed repository; edit this file 'description' to name the repository.
58f7cf825b553ef7c26e5b9f8a23599c1a9ca296 refs/heads/master
0000000000000000000000000000000000000000 67c1640e91ccbaf0793591be09bf572cf40c9a53 Russell Belfer <rb@github.com> 1335817070 -0700 commit (initial): Initial commit
67c1640e91ccbaf0793591be09bf572cf40c9a53 d441d7d88f52c28c2b23940ce4c33756748425f9 Russell Belfer <rb@github.com> 1335817296 -0700 commit: Adding some files in subtrees
d441d7d88f52c28c2b23940ce4c33756748425f9 67c1640e91ccbaf0793591be09bf572cf40c9a53 Russell Belfer <rb@github.com> 1335817353 -0700 HEAD^: updating HEAD
67c1640e91ccbaf0793591be09bf572cf40c9a53 58f7cf825b553ef7c26e5b9f8a23599c1a9ca296 Russell Belfer <rb@github.com> 1335817372 -0700 commit: Adding subtree data
0000000000000000000000000000000000000000 67c1640e91ccbaf0793591be09bf572cf40c9a53 Russell Belfer <rb@github.com> 1335817070 -0700 commit (initial): Initial commit
67c1640e91ccbaf0793591be09bf572cf40c9a53 d441d7d88f52c28c2b23940ce4c33756748425f9 Russell Belfer <rb@github.com> 1335817296 -0700 commit: Adding some files in subtrees
d441d7d88f52c28c2b23940ce4c33756748425f9 67c1640e91ccbaf0793591be09bf572cf40c9a53 Russell Belfer <rb@github.com> 1335817353 -0700 HEAD^: updating HEAD
67c1640e91ccbaf0793591be09bf572cf40c9a53 58f7cf825b553ef7c26e5b9f8a23599c1a9ca296 Russell Belfer <rb@github.com> 1335817372 -0700 commit: Adding subtree data
P pack-4e6438607204ce78827e3885594b2c0bb4f13895.pack
# pack-refs with: peeled
58f7cf825b553ef7c26e5b9f8a23599c1a9ca296 refs/heads/master
This is contains tests for when the index and work dir differ
This contains files for testing when the index and the workdir differ
* bar
*.txt -foo beep=10
*.md blargh=goop -bar
Unnamed repository; edit this file 'description' to name the repository.
P pack-c5bfca875b4995d7aba6e5abf36241f3c397327d.pack
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment