summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobert Coup <robert@coup.net.nz>2019-06-07 15:22:42 +0100
committerRobert Coup <robert@coup.net.nz>2019-06-10 11:22:02 +0100
commit21ddeabe6cb4a77899a6c7348493a2b45cc82a9c (patch)
tree1f6534490f016425a398d3450957abc4104af3d4 /tests
parent7b27b6cf716429080fbc968d8f573977996ee112 (diff)
downloadlibgit2-21ddeabe6cb4a77899a6c7348493a2b45cc82a9c.tar.gz
Review fixes:
- whitespace -> tabs - comment style - improve repo naming in merge/trees/analysis tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/merge/analysis.c170
-rw-r--r--tests/merge/trees/analysis.c46
-rw-r--r--tests/merge/workdir/analysis.c31
3 files changed, 129 insertions, 118 deletions
diff --git a/tests/merge/analysis.c b/tests/merge/analysis.c
index 21d7a8134..504e4927a 100644
--- a/tests/merge/analysis.c
+++ b/tests/merge/analysis.c
@@ -1,5 +1,7 @@
-// NOTE: this is the implementation for both merge/trees/analysis.c and merge/workdir/analysis.c
-// You probably want to make changes to both files.
+/*
+NOTE: this is the implementation for both merge/trees/analysis.c and merge/workdir/analysis.c
+You probably want to make changes to both files.
+*/
#include "clar_libgit2.h"
#include "git2/repository.h"
@@ -7,7 +9,7 @@
#include "git2/annotated_commit.h"
#include "git2/sys/index.h"
#include "merge.h"
-#include "./merge_helpers.h"
+#include "merge_helpers.h"
#include "refs.h"
#include "posix.h"
@@ -27,144 +29,144 @@ static git_index *repo_index;
/* Fixture setup and teardown */
void testimpl_merge_analysis__initialize(git_repository *t_repo, git_index *t_repo_index)
{
- repo = t_repo;
- repo_index = t_repo_index;
+ repo = t_repo;
+ repo_index = t_repo_index;
}
void testimpl_merge_analysis__cleanup(void)
{
- repo_index = NULL;
- repo = NULL;
+ repo_index = NULL;
+ repo = NULL;
}
static void analysis_from_branch(
- git_merge_analysis_t *merge_analysis,
- git_merge_preference_t *merge_pref,
- const char *our_branchname,
- const char *their_branchname)
+ git_merge_analysis_t *merge_analysis,
+ git_merge_preference_t *merge_pref,
+ const char *our_branchname,
+ const char *their_branchname)
{
- git_buf our_refname = GIT_BUF_INIT;
- git_buf their_refname = GIT_BUF_INIT;
- git_reference *our_ref;
- git_reference *their_ref;
- git_annotated_commit *their_head;
-
- if (our_branchname != NULL) {
- cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
- cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname)));
- } else {
- cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE));
- }
-
- cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
-
- cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname)));
- cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
-
- cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1));
-
- git_buf_dispose(&our_refname);
- git_buf_dispose(&their_refname);
- git_annotated_commit_free(their_head);
- git_reference_free(our_ref);
- git_reference_free(their_ref);
+ git_buf our_refname = GIT_BUF_INIT;
+ git_buf their_refname = GIT_BUF_INIT;
+ git_reference *our_ref;
+ git_reference *their_ref;
+ git_annotated_commit *their_head;
+
+ if (our_branchname != NULL) {
+ cl_git_pass(git_buf_printf(&our_refname, "%s%s", GIT_REFS_HEADS_DIR, our_branchname));
+ cl_git_pass(git_reference_lookup(&our_ref, repo, git_buf_cstr(&our_refname)));
+ } else {
+ cl_git_pass(git_reference_lookup(&our_ref, repo, GIT_HEAD_FILE));
+ }
+
+ cl_git_pass(git_buf_printf(&their_refname, "%s%s", GIT_REFS_HEADS_DIR, their_branchname));
+
+ cl_git_pass(git_reference_lookup(&their_ref, repo, git_buf_cstr(&their_refname)));
+ cl_git_pass(git_annotated_commit_from_ref(&their_head, repo, their_ref));
+
+ cl_git_pass(git_merge_analysis_for_ref(merge_analysis, merge_pref, repo, our_ref, (const git_annotated_commit **)&their_head, 1));
+
+ git_buf_dispose(&our_refname);
+ git_buf_dispose(&their_refname);
+ git_annotated_commit_free(their_head);
+ git_reference_free(our_ref);
+ git_reference_free(their_ref);
}
void testimpl_merge_analysis__fastforward(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
}
void testimpl_merge_analysis__no_fastforward(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
}
void testimpl_merge_analysis__uptodate(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, UPTODATE_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, UPTODATE_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void testimpl_merge_analysis__uptodate_merging_prev_commit(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, PREVIOUS_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, PREVIOUS_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void testimpl_merge_analysis__unborn(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
- git_buf master = GIT_BUF_INIT;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
+ git_buf master = GIT_BUF_INIT;
- git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master");
- p_unlink(git_buf_cstr(&master));
+ git_buf_joinpath(&master, git_repository_path(repo), "refs/heads/master");
+ p_unlink(git_buf_cstr(&master));
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_FASTFORWARD|GIT_MERGE_ANALYSIS_UNBORN, merge_analysis);
- git_buf_dispose(&master);
+ git_buf_dispose(&master);
}
void testimpl_merge_analysis__fastforward_with_config_noff(void)
{
- git_config *config;
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_config *config;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- git_repository_config(&config, repo);
- git_config_set_string(config, "merge.ff", "false");
+ git_repository_config(&config, repo);
+ git_config_set_string(config, "merge.ff", "false");
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL|GIT_MERGE_ANALYSIS_FASTFORWARD, merge_analysis);
- cl_assert_equal_i(GIT_MERGE_PREFERENCE_NO_FASTFORWARD, (merge_pref & GIT_MERGE_PREFERENCE_NO_FASTFORWARD));
+ cl_assert_equal_i(GIT_MERGE_PREFERENCE_NO_FASTFORWARD, (merge_pref & GIT_MERGE_PREFERENCE_NO_FASTFORWARD));
}
void testimpl_merge_analysis__no_fastforward_with_config_ffonly(void)
{
- git_config *config;
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_config *config;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- git_repository_config(&config, repo);
- git_config_set_string(config, "merge.ff", "only");
+ git_repository_config(&config, repo);
+ git_config_set_string(config, "merge.ff", "only");
- analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NULL, NOFASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
- cl_assert_equal_i(GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY, (merge_pref & GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY));
+ cl_assert_equal_i(GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY, (merge_pref & GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY));
}
void testimpl_merge_analysis__between_uptodate_refs(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, NOFASTFORWARD_BRANCH, PREVIOUS_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, NOFASTFORWARD_BRANCH, PREVIOUS_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_UP_TO_DATE, merge_analysis);
}
void testimpl_merge_analysis__between_noff_refs(void)
{
- git_merge_analysis_t merge_analysis;
- git_merge_preference_t merge_pref;
+ git_merge_analysis_t merge_analysis;
+ git_merge_preference_t merge_pref;
- analysis_from_branch(&merge_analysis, &merge_pref, "branch", FASTFORWARD_BRANCH);
- cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
+ analysis_from_branch(&merge_analysis, &merge_pref, "branch", FASTFORWARD_BRANCH);
+ cl_assert_equal_i(GIT_MERGE_ANALYSIS_NORMAL, merge_analysis);
}
diff --git a/tests/merge/trees/analysis.c b/tests/merge/trees/analysis.c
index a905e34ed..ce61085e3 100644
--- a/tests/merge/trees/analysis.c
+++ b/tests/merge/trees/analysis.c
@@ -1,12 +1,14 @@
-// NOTE: this is essentially duplicated from tests/merge/workdir/analysis.c
-// You probably want to make changes to both files.
+/*
+NOTE: this is essentially duplicated from tests/merge/workdir/analysis.c
+You probably want to make changes to both files.
+*/
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "../analysis.h"
-static git_repository *base_repo;
static git_repository *repo;
+static git_repository *bare_repo;
static git_index *repo_index;
#define TEST_REPO_PATH "merge-resolve"
@@ -16,68 +18,70 @@ static git_index *repo_index;
/* Fixture setup and teardown */
void test_merge_trees_analysis__initialize(void)
{
- base_repo = cl_git_sandbox_init(TEST_REPO_PATH);
+ repo = cl_git_sandbox_init(TEST_REPO_PATH);
- cl_git_pass(git_repository_open_ext(&repo, TEST_REPO_PATH "/.git", GIT_REPOSITORY_OPEN_BARE, NULL));
+ cl_git_pass(git_repository_open_ext(&bare_repo, TEST_REPO_PATH "/.git", GIT_REPOSITORY_OPEN_BARE, NULL));
- git_repository_index(&repo_index, repo);
+ git_repository_index(&repo_index, bare_repo);
- testimpl_merge_analysis__initialize(repo, repo_index);
+ testimpl_merge_analysis__initialize(bare_repo, repo_index);
}
void test_merge_trees_analysis__cleanup(void)
{
- testimpl_merge_analysis__cleanup();
+ testimpl_merge_analysis__cleanup();
- git_index_free(repo_index);
+ git_index_free(repo_index);
+ repo_index = NULL;
- git_repository_free(repo);
- repo = NULL;
+ git_repository_free(bare_repo);
+ bare_repo = NULL;
- cl_git_sandbox_cleanup();
+ cl_git_sandbox_cleanup();
+ repo = NULL;
}
void test_merge_trees_analysis__fastforward(void)
{
- testimpl_merge_analysis__fastforward();
+ testimpl_merge_analysis__fastforward();
}
void test_merge_trees_analysis__no_fastforward(void)
{
- testimpl_merge_analysis__no_fastforward();
+ testimpl_merge_analysis__no_fastforward();
}
void test_merge_trees_analysis__uptodate(void)
{
- testimpl_merge_analysis__uptodate();
+ testimpl_merge_analysis__uptodate();
}
void test_merge_trees_analysis__uptodate_merging_prev_commit(void)
{
- testimpl_merge_analysis__uptodate_merging_prev_commit();
+ testimpl_merge_analysis__uptodate_merging_prev_commit();
}
void test_merge_trees_analysis__unborn(void)
{
- testimpl_merge_analysis__unborn();
+ testimpl_merge_analysis__unborn();
}
void test_merge_trees_analysis__fastforward_with_config_noff(void)
{
- testimpl_merge_analysis__fastforward_with_config_noff();
+ testimpl_merge_analysis__fastforward_with_config_noff();
}
void test_merge_trees_analysis__no_fastforward_with_config_ffonly(void)
{
- testimpl_merge_analysis__no_fastforward_with_config_ffonly();
+ testimpl_merge_analysis__no_fastforward_with_config_ffonly();
}
void test_merge_trees_analysis__between_uptodate_refs(void)
{
- testimpl_merge_analysis__between_uptodate_refs();
+ testimpl_merge_analysis__between_uptodate_refs();
}
void test_merge_trees_analysis__between_noff_refs(void)
{
- testimpl_merge_analysis__between_noff_refs();
+ testimpl_merge_analysis__between_noff_refs();
}
diff --git a/tests/merge/workdir/analysis.c b/tests/merge/workdir/analysis.c
index 28fc39302..08158f8bd 100644
--- a/tests/merge/workdir/analysis.c
+++ b/tests/merge/workdir/analysis.c
@@ -1,5 +1,7 @@
-// NOTE: this is essentially duplicated with tests/merge/trees/analysis.c
-// You probably want to make changes to both files.
+/*
+NOTE: this is essentially duplicated with tests/merge/trees/analysis.c
+You probably want to make changes to both files.
+*/
#include "clar_libgit2.h"
#include "git2/repository.h"
@@ -18,58 +20,61 @@ void test_merge_workdir_analysis__initialize(void)
repo = cl_git_sandbox_init(TEST_REPO_PATH);
git_repository_index(&repo_index, repo);
- testimpl_merge_analysis__initialize(repo, repo_index);
+ testimpl_merge_analysis__initialize(repo, repo_index);
}
void test_merge_workdir_analysis__cleanup(void)
{
- testimpl_merge_analysis__cleanup();
+ testimpl_merge_analysis__cleanup();
git_index_free(repo_index);
+ repo_index = NULL;
+
cl_git_sandbox_cleanup();
+ repo = NULL;
}
void test_merge_workdir_analysis__fastforward(void)
{
- testimpl_merge_analysis__fastforward();
+ testimpl_merge_analysis__fastforward();
}
void test_merge_workdir_analysis__no_fastforward(void)
{
- testimpl_merge_analysis__no_fastforward();
+ testimpl_merge_analysis__no_fastforward();
}
void test_merge_workdir_analysis__uptodate(void)
{
- testimpl_merge_analysis__uptodate();
+ testimpl_merge_analysis__uptodate();
}
void test_merge_workdir_analysis__uptodate_merging_prev_commit(void)
{
- testimpl_merge_analysis__uptodate_merging_prev_commit();
+ testimpl_merge_analysis__uptodate_merging_prev_commit();
}
void test_merge_workdir_analysis__unborn(void)
{
- testimpl_merge_analysis__unborn();
+ testimpl_merge_analysis__unborn();
}
void test_merge_workdir_analysis__fastforward_with_config_noff(void)
{
- testimpl_merge_analysis__fastforward_with_config_noff();
+ testimpl_merge_analysis__fastforward_with_config_noff();
}
void test_merge_workdir_analysis__no_fastforward_with_config_ffonly(void)
{
- testimpl_merge_analysis__no_fastforward_with_config_ffonly();
+ testimpl_merge_analysis__no_fastforward_with_config_ffonly();
}
void test_merge_workdir_analysis__between_uptodate_refs(void)
{
- testimpl_merge_analysis__between_uptodate_refs();
+ testimpl_merge_analysis__between_uptodate_refs();
}
void test_merge_workdir_analysis__between_noff_refs(void)
{
- testimpl_merge_analysis__between_noff_refs();
+ testimpl_merge_analysis__between_noff_refs();
}