summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-02-14 13:26:30 +0100
committerPatrick Steinhardt <ps@pks.im>2019-02-14 14:01:27 +0100
commita0f87e161b000558ed4aba70bfeb88ddf3329583 (patch)
tree47f4758312a9b9b1a3689cfda1ed4afb21143da1
parent698eae1392e0b9ec8d7f3e47b0a7206e8c5fc14d (diff)
downloadlibgit2-a0f87e161b000558ed4aba70bfeb88ddf3329583.tar.gz
branches: add tests for `git_branch_is_checked_out`
We currently do not have any tests at all for the `git_branch_is_checked_out` function. Add some basic ones.
-rw-r--r--tests/refs/branches/checkedout.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/refs/branches/checkedout.c b/tests/refs/branches/checkedout.c
new file mode 100644
index 000000000..2ec665aab
--- /dev/null
+++ b/tests/refs/branches/checkedout.c
@@ -0,0 +1,39 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+#include "worktree/worktree_helpers.h"
+
+static git_repository *repo;
+
+static void assert_checked_out(git_repository *repo, const char *branch, int checked_out)
+{
+ git_reference *ref;
+
+ cl_git_pass(git_reference_lookup(&ref, repo, branch));
+ cl_assert(git_branch_is_checked_out(ref) == checked_out);
+
+ git_reference_free(ref);
+}
+
+void test_refs_branches_checkedout__simple_repo(void)
+{
+ repo = cl_git_sandbox_init("testrepo");
+ assert_checked_out(repo, "refs/heads/master", 1);
+ assert_checked_out(repo, "refs/heads/executable", 0);
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_branches_checkedout__worktree(void)
+{
+ static worktree_fixture fixture =
+ WORKTREE_FIXTURE_INIT("testrepo", "testrepo-worktree");
+
+ setup_fixture_worktree(&fixture);
+
+ assert_checked_out(fixture.repo, "refs/heads/master", 1);
+ assert_checked_out(fixture.repo, "refs/heads/testrepo-worktree", 1);
+
+ assert_checked_out(fixture.worktree, "refs/heads/master", 1);
+ assert_checked_out(fixture.worktree, "refs/heads/testrepo-worktree", 1);
+
+ cleanup_fixture_worktree(&fixture);
+}