mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-21 15:07:23 +00:00
Test that commit attributes are set correctly.
This commit is contained in:
parent
a8bfce69dc
commit
f24fa0880c
@ -1,6 +1,7 @@
|
|||||||
#include "test_lib.h"
|
#include "test_lib.h"
|
||||||
#include "test_helpers.h"
|
#include "test_helpers.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
|
#include "person.h"
|
||||||
|
|
||||||
#include <git/odb.h>
|
#include <git/odb.h>
|
||||||
#include <git/commit.h>
|
#include <git/commit.h>
|
||||||
@ -18,12 +19,15 @@ static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
|
|||||||
|
|
||||||
#define COMMITTER_NAME "Vicent Marti"
|
#define COMMITTER_NAME "Vicent Marti"
|
||||||
#define COMMITTER_EMAIL "vicent@github.com"
|
#define COMMITTER_EMAIL "vicent@github.com"
|
||||||
|
#define COMMIT_MESSAGE "This commit has been created in memory\n\
|
||||||
|
This is a commit created in memory and it will be written back to disk\n"
|
||||||
|
|
||||||
BEGIN_TEST(writenew_test)
|
BEGIN_TEST(writenew_test)
|
||||||
git_repository *repo;
|
git_repository *repo;
|
||||||
git_commit *commit, *parent;
|
git_commit *commit, *parent;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
git_oid id;
|
git_oid id;
|
||||||
|
const git_person *author, *committer;
|
||||||
/* char hex_oid[41]; */
|
/* char hex_oid[41]; */
|
||||||
|
|
||||||
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
|
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
|
||||||
@ -40,10 +44,23 @@ BEGIN_TEST(writenew_test)
|
|||||||
/* Set other attributes */
|
/* Set other attributes */
|
||||||
git_commit_set_committer(commit, COMMITTER_NAME, COMMITTER_EMAIL, 123456789);
|
git_commit_set_committer(commit, COMMITTER_NAME, COMMITTER_EMAIL, 123456789);
|
||||||
git_commit_set_author(commit, COMMITTER_NAME, COMMITTER_EMAIL, 987654321);
|
git_commit_set_author(commit, COMMITTER_NAME, COMMITTER_EMAIL, 987654321);
|
||||||
git_commit_set_message(commit,
|
git_commit_set_message(commit, COMMIT_MESSAGE);
|
||||||
"This commit has been created in memory\n\
|
|
||||||
This is a commit created in memory and it will be written back to disk\n");
|
/* Check attributes were set correctly */
|
||||||
|
author = git_commit_author(commit);
|
||||||
|
must_be_true(author != NULL);
|
||||||
|
must_be_true(strcmp(author->name, COMMITTER_NAME) == 0);
|
||||||
|
must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0);
|
||||||
|
must_be_true(author->time == 987654321);
|
||||||
|
|
||||||
|
committer = git_commit_committer(commit);
|
||||||
|
must_be_true(committer != NULL);
|
||||||
|
must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0);
|
||||||
|
must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0);
|
||||||
|
must_be_true(committer->time == 123456789);
|
||||||
|
|
||||||
|
must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0);
|
||||||
|
|
||||||
/* add new tree */
|
/* add new tree */
|
||||||
git_oid_mkstr(&id, tree_oid);
|
git_oid_mkstr(&id, tree_oid);
|
||||||
must_pass(git_tree_lookup(&tree, repo, &id));
|
must_pass(git_tree_lookup(&tree, repo, &id));
|
||||||
|
Loading…
Reference in New Issue
Block a user