diff options
author | Vicent Martà <vicent@github.com> | 2012-10-19 14:43:09 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-10-19 14:43:09 -0700 |
commit | cf028856bcfca6d047d04856af9be38b1dd772bc (patch) | |
tree | 622287699b4a18a9b3e34e73bfc0473511a67620 /tests-clar | |
parent | 4fec465bd3c00eba39314ef40fdce04e2b6a7939 (diff) | |
parent | 8b05bea87042010c2d9c71d0be17f45bf5bea2a3 (diff) | |
download | libgit2-cf028856bcfca6d047d04856af9be38b1dd772bc.tar.gz |
Merge pull request #1000 from nulltoken/error/GIT_EORPHANEDHEAD
Add error GIT_EORPHANEDHEAD
Diffstat (limited to 'tests-clar')
-rw-r--r-- | tests-clar/checkout/head.c | 24 | ||||
-rw-r--r-- | tests-clar/refs/branches/delete.c | 19 | ||||
-rw-r--r-- | tests-clar/refs/branches/ishead.c | 24 | ||||
-rw-r--r-- | tests-clar/repo/head.c | 34 | ||||
-rw-r--r-- | tests-clar/status/worktree.c | 1 |
5 files changed, 92 insertions, 10 deletions
diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c new file mode 100644 index 000000000..f2f81e5e2 --- /dev/null +++ b/tests-clar/checkout/head.c @@ -0,0 +1,24 @@ +#include "clar_libgit2.h" +#include "refs.h" + +static git_repository *g_repo; + +void test_checkout_head__initialize(void) +{ + g_repo = cl_git_sandbox_init("testrepo"); +} + +void test_checkout_head__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_checkout_head__checking_out_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void) +{ + git_reference *head; + + cl_git_pass(git_reference_create_symbolic(&head, g_repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1)); + git_reference_free(head); + + cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL, NULL)); +} diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c index b261240cd..99af44ef4 100644 --- a/tests-clar/refs/branches/delete.c +++ b/tests-clar/refs/branches/delete.c @@ -38,17 +38,28 @@ void test_refs_branches_delete__can_not_delete_a_branch_pointed_at_by_HEAD(void) git_reference_free(branch); } -void test_refs_branches_delete__can_not_delete_a_branch_if_HEAD_is_missing(void) +void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void) { git_reference *head; - git_reference *branch = NULL; + git_reference *branch; cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); git_reference_delete(head); cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); - cl_git_fail(git_branch_delete(branch)); - git_reference_free(branch); + cl_git_pass(git_branch_delete(branch)); +} + +void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void) +{ + git_reference *head; + git_reference *branch; + + cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1)); + git_reference_free(head); + + cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); + cl_git_pass(git_branch_delete(branch)); } void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void) diff --git a/tests-clar/refs/branches/ishead.c b/tests-clar/refs/branches/ishead.c index c40a43189..0d57f00a3 100644 --- a/tests-clar/refs/branches/ishead.c +++ b/tests-clar/refs/branches/ishead.c @@ -22,6 +22,30 @@ void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void) cl_assert_equal_i(true, git_branch_is_head(branch)); } +static void make_head_orphaned(void) +{ + git_reference *head; + + cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1)); + git_reference_free(head); +} + +void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void) +{ + git_repository_free(repo); + + repo = cl_git_sandbox_init("testrepo.git"); + + make_head_orphaned(); + + cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master")); + + cl_assert_equal_i(false, git_branch_is_head(branch)); + + cl_git_sandbox_cleanup(); + repo = NULL; +} + void test_refs_branches_ishead__can_tell_if_a_branch_is_not_pointed_at_by_HEAD(void) { cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/br2")); diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c index 64dec69dd..4113289f0 100644 --- a/tests-clar/repo/head.c +++ b/tests-clar/repo/head.c @@ -33,18 +33,26 @@ void test_repo_head__head_detached(void) git_reference_free(ref); } +static void make_head_orphaned(void) +{ + git_reference *head; + + cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/heads/hide/and/seek", 1)); + git_reference_free(head); +} + void test_repo_head__head_orphan(void) { git_reference *ref; cl_assert(git_repository_head_orphan(repo) == 0); - /* orphan HEAD */ - cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1)); + make_head_orphaned(); + cl_assert(git_repository_head_orphan(repo) == 1); - git_reference_free(ref); - /* take the reop back to it's original state */ + + /* take the repo back to it's original state */ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); cl_assert(git_repository_head_orphan(repo) == 0); @@ -59,7 +67,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_ cl_assert_equal_i(false, git_repository_head_detached(repo)); - cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo)); + cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo)); } void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void) @@ -163,3 +171,19 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void git_reference_free(head); } + +void test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void) +{ + make_head_orphaned(); + + cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_detach_head(repo)); +} + +void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void) +{ + git_reference *head; + + make_head_orphaned(); + + cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo)); +} diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index fae43a102..908d34510 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -414,7 +414,6 @@ void test_status_worktree__issue_592_ignored_dirs_with_tracked_content(void) void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void) { git_repository *repo; - int error; unsigned int status = 0; cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); |