From 99a09f7f18f321c2a37e483bcd8aeb6dff781abc Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 22 Oct 2015 09:29:40 -0400 Subject: [PATCH] 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. --- tests/index/nsec.c | 78 ++++++++++++++++++ tests/resources/nsecs/.gitted/HEAD | Bin 0 -> 23 bytes tests/resources/nsecs/.gitted/config | Bin 0 -> 157 bytes tests/resources/nsecs/.gitted/index | Bin 0 -> 281 bytes .../03/1986a8372d1442cfe9e3b54906a9aadc524a7e | Bin 0 -> 155 bytes .../03/9afd91c98f82c14e425bb6796d8ca98e9c8cac | Bin 0 -> 102 bytes .../6d/8b18077cc99abd8dda05a6062c646406abb2d4 | Bin 0 -> 22 bytes .../c5/12b6c64656b87ea8caf37a32bc5a562d797745 | Bin 0 -> 22 bytes .../df/78d3d51c369e1d2f1eadb73464aadd931d56b4 | Bin 0 -> 22 bytes .../resources/nsecs/.gitted/refs/heads/master | Bin 0 -> 41 bytes tests/resources/nsecs/a.txt | Bin 0 -> 8 bytes tests/resources/nsecs/b.txt | Bin 0 -> 8 bytes tests/resources/nsecs/c.txt | Bin 0 -> 8 bytes 13 files changed, 78 insertions(+) create mode 100644 tests/index/nsec.c create mode 100644 tests/resources/nsecs/.gitted/HEAD create mode 100644 tests/resources/nsecs/.gitted/config create mode 100644 tests/resources/nsecs/.gitted/index create mode 100644 tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e create mode 100644 tests/resources/nsecs/.gitted/objects/03/9afd91c98f82c14e425bb6796d8ca98e9c8cac create mode 100644 tests/resources/nsecs/.gitted/objects/6d/8b18077cc99abd8dda05a6062c646406abb2d4 create mode 100644 tests/resources/nsecs/.gitted/objects/c5/12b6c64656b87ea8caf37a32bc5a562d797745 create mode 100644 tests/resources/nsecs/.gitted/objects/df/78d3d51c369e1d2f1eadb73464aadd931d56b4 create mode 100644 tests/resources/nsecs/.gitted/refs/heads/master create mode 100644 tests/resources/nsecs/a.txt create mode 100644 tests/resources/nsecs/b.txt create mode 100644 tests/resources/nsecs/c.txt diff --git a/tests/index/nsec.c b/tests/index/nsec.c new file mode 100644 index 000000000..5004339f0 --- /dev/null +++ b/tests/index/nsec.c @@ -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); +} diff --git a/tests/resources/nsecs/.gitted/HEAD b/tests/resources/nsecs/.gitted/HEAD new file mode 100644 index 0000000000000000000000000000000000000000..cb089cd89a7d7686d284d8761201649346b5aa1c GIT binary patch literal 23 ecmXR)O|w!cN=+-)&qz&7Db~+TEG|hc;sO9;xClW2 literal 0 HcmV?d00001 diff --git a/tests/resources/nsecs/.gitted/config b/tests/resources/nsecs/.gitted/config new file mode 100644 index 0000000000000000000000000000000000000000..78387c50b472d8c0cdaeca4b56bf23c5b7f791df GIT binary patch literal 157 zcmYj~F%H5o3`OVU6g@&Oz=mM#0T6>}oMPd`mF*(s_9TLV@qN9ge_KWI9)sd8MlRa2 zXaRqt8cCf_(;P!4#v%zjWnjY?9-x23vH`PVKK2BT);-swYt{-=eU0H4(pLN73O4eu U^rVDm@k>7$ViLcSFO^&T0N7wQ1ONa4 literal 0 HcmV?d00001 diff --git a/tests/resources/nsecs/.gitted/index b/tests/resources/nsecs/.gitted/index new file mode 100644 index 0000000000000000000000000000000000000000..9233f1b11e8179f0f9655631bd9064d4e4229fe0 GIT binary patch literal 281 zcmZ?q402{*U|<4b<}eMjgR(2EG=TJB_Mr0bI!T~d62^l|LnLd9wO)Yqy)Ethzf{Hf#$6YckxN zkRVrApk_%1V+8{)=2?Fyp6qWr=;su@tunV~W#62hH5rSxp7WY#$)m^phWFf~Ww-2J HvG4-`s})W= literal 0 HcmV?d00001 diff --git a/tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e b/tests/resources/nsecs/.gitted/objects/03/1986a8372d1442cfe9e3b54906a9aadc524a7e new file mode 100644 index 0000000000000000000000000000000000000000..a813b74244dbf0c6c18a967cc5930ea2c1b2e75d GIT binary patch literal 155 zcmV;M0A&Ao0i}&W3c@fHL|x|;{{l)H(=;DM6zSGYbuH=7FYO{m(n#_4M)3x&X66md zPz+(ppp;tW#0+waZtz$U+QBNSG;3A&y=l;ROAaj~6(!-Gd5j5KzqsV#GR82+JM6g7 zk2~h^t2bSN zDo6q=I4ZR5m|NJ6x)rBBR~hYz3e&ADcZDiQ1}nHdYP=+cFBy literal 0 HcmV?d00001 diff --git a/tests/resources/nsecs/a.txt b/tests/resources/nsecs/a.txt new file mode 100644 index 0000000000000000000000000000000000000000..be4c1ee68016c22d2a2069fceef064e8638d23b1 GIT binary patch literal 8 PcmZ?E%t=*n