mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
index: test that we round-trip nsecs
Test that nanoseconds are round-tripped correctly when we read an index file that contains them. We should, however, ignore them because we don't understand them, and any new entries in the index should contain a `0` nsecs field, while existing preserving entries.
This commit is contained in:
78
tests/index/nsec.c
Normal file
78
tests/index/nsec.c
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "index.h"
|
||||
#include "git2/sys/index.h"
|
||||
#include "git2/repository.h"
|
||||
#include "../reset/reset_helpers.h"
|
||||
|
||||
static git_repository *repo;
|
||||
static git_index *repo_index;
|
||||
|
||||
#define TEST_REPO_PATH "nsecs"
|
||||
|
||||
// Fixture setup and teardown
|
||||
void test_index_nsec__initialize(void)
|
||||
{
|
||||
repo = cl_git_sandbox_init("nsecs");
|
||||
git_repository_index(&repo_index, repo);
|
||||
}
|
||||
|
||||
void test_index_nsec__cleanup(void)
|
||||
{
|
||||
git_index_free(repo_index);
|
||||
repo_index = NULL;
|
||||
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
static bool has_nsecs(void)
|
||||
{
|
||||
const git_index_entry *entry;
|
||||
size_t i;
|
||||
bool has_nsecs = false;
|
||||
|
||||
for (i = 0; i < git_index_entrycount(repo_index); i++) {
|
||||
entry = git_index_get_byindex(repo_index, i);
|
||||
|
||||
if (entry->ctime.nanoseconds || entry->mtime.nanoseconds) {
|
||||
has_nsecs = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return has_nsecs;
|
||||
}
|
||||
|
||||
void test_index_nsec__has_nanos(void)
|
||||
{
|
||||
cl_assert_equal_b(true, has_nsecs());
|
||||
}
|
||||
|
||||
void test_index_nsec__staging_maintains_other_nanos(void)
|
||||
{
|
||||
const git_index_entry *entry;
|
||||
|
||||
cl_git_rewritefile("nsecs/a.txt", "This is file A");
|
||||
cl_git_pass(git_index_add_bypath(repo_index, "a.txt"));
|
||||
cl_git_pass(git_index_write(repo_index));
|
||||
|
||||
cl_git_pass(git_index_write(repo_index));
|
||||
|
||||
git_index_read(repo_index, 1);
|
||||
cl_assert_equal_b(true, has_nsecs());
|
||||
|
||||
cl_assert((entry = git_index_get_bypath(repo_index, "a.txt", 0)));
|
||||
cl_assert_equal_i(0, entry->ctime.nanoseconds);
|
||||
cl_assert_equal_i(0, entry->mtime.nanoseconds);
|
||||
}
|
||||
|
||||
void test_index_nsec__status_doesnt_clear_nsecs(void)
|
||||
{
|
||||
git_status_list *statuslist;
|
||||
|
||||
cl_git_pass(git_status_list_new(&statuslist, repo, NULL));
|
||||
|
||||
git_index_read(repo_index, 1);
|
||||
cl_assert_equal_b(true, has_nsecs());
|
||||
|
||||
git_status_list_free(statuslist);
|
||||
}
|
||||
1
tests/resources/nsecs/.gitted/HEAD
Normal file
1
tests/resources/nsecs/.gitted/HEAD
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
8
tests/resources/nsecs/.gitted/config
Normal file
8
tests/resources/nsecs/.gitted/config
Normal file
@@ -0,0 +1,8 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = false
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
symlinks = false
|
||||
ignorecase = true
|
||||
hideDotFiles = dotGitOnly
|
||||
BIN
tests/resources/nsecs/.gitted/index
Normal file
BIN
tests/resources/nsecs/.gitted/index
Normal file
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
x¥<>A
|
||||
Â0D]çÿJÓ4DéÖMu-éÏ/í"FÒHñöFñ®fæ
ÌPaÊ ”ZåÄr‹nðXÚÁ*ª4kU÷½iÐxK-#%ážyŒ Z¿¸äá2Æ0Ç;ì¸Ð<C2B8>;ð·ø¥
ۇJëZ7F¢<46>µÔRŠBËyæ?gÄ?â<å˜^@‰]fË”G¸vííܵ§N¼UOKv
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1
tests/resources/nsecs/.gitted/refs/heads/master
Normal file
1
tests/resources/nsecs/.gitted/refs/heads/master
Normal file
@@ -0,0 +1 @@
|
||||
031986a8372d1442cfe9e3b54906a9aadc524a7e
|
||||
1
tests/resources/nsecs/a.txt
Normal file
1
tests/resources/nsecs/a.txt
Normal file
@@ -0,0 +1 @@
|
||||
File A
|
||||
1
tests/resources/nsecs/b.txt
Normal file
1
tests/resources/nsecs/b.txt
Normal file
@@ -0,0 +1 @@
|
||||
File B
|
||||
1
tests/resources/nsecs/c.txt
Normal file
1
tests/resources/nsecs/c.txt
Normal file
@@ -0,0 +1 @@
|
||||
File C
|
||||
Reference in New Issue
Block a user