From 4ae8367b4e6eb009dac9d2d0df4b6a72bf9137a3 Mon Sep 17 00:00:00 2001 From: Yelninei Date: Mon, 15 Dec 2025 15:14:15 +0000 Subject: [PATCH 1/3] tests: Fix stat tests on 32bit systems. On 32bit systems the git_fs_path_lstat from libgit2 by default uses 32bit stat structs while the tests are being compiled with struct stat64 via _FILE_OFFSET_BITS=64. This discrepancy causes the "flaky" stat failures in tests. The solution is to use the same _FILE_OFFSET_BITS as the library by setting _FILE_OFFSET_BITS globally Co-authored-by: Edward Thomson --- CMakeLists.txt | 8 ++++++++ tests/libgit2/CMakeLists.txt | 1 - tests/util/CMakeLists.txt | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 406d8e441..22fdc4316 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,14 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) endif() +# +# Common settings across all projects, dependencies, etc. Always support +# 64 bit file operations, even 32 bit platforms. +# + +add_definitions(-D_FILE_OFFSET_BITS=64) + + # Modules include(FeatureSummary) diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt index a05e93d71..0e44c30d0 100644 --- a/tests/libgit2/CMakeLists.txt +++ b/tests/libgit2/CMakeLists.txt @@ -19,7 +19,6 @@ add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\") add_definitions(-DCLAR_WIN32_LONGPATHS) add_definitions(-DCLAR_HAS_REALPATH) -add_definitions(-D_FILE_OFFSET_BITS=64) # Ensure that we do not use deprecated functions internally add_definitions(-DGIT_DEPRECATE_HARD) diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index d2c5bf268..befeabb1d 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -19,7 +19,6 @@ add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\") add_definitions(-DCLAR_WIN32_LONGPATHS) add_definitions(-DCLAR_HAS_REALPATH) -add_definitions(-D_FILE_OFFSET_BITS=64) # Ensure that we do not use deprecated functions internally add_definitions(-DGIT_DEPRECATE_HARD) From 84806965a09eb2a6a66427d53de329185642b6e5 Mon Sep 17 00:00:00 2001 From: Yelninei Date: Mon, 15 Dec 2025 15:16:26 +0000 Subject: [PATCH 2/3] tests: Remove GITTEST_FLAKY_STAT environment variable. This was caused by the tests being compiled with -D_FILE_OFFSET_BITS=64 which causes incompatibilities if libgit2 itself is not. As this has been resolved the environment variable is no longer necessary and can be removed. --- .github/actions/run-build/action.yml | 1 - .github/workflows/nightly.yml | 1 - tests/libgit2/diff/workdir.c | 3 +-- tests/util/copy.c | 9 +++------ 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/actions/run-build/action.yml b/.github/actions/run-build/action.yml index 4077fe00c..22d81fb0a 100644 --- a/.github/actions/run-build/action.yml +++ b/.github/actions/run-build/action.yml @@ -42,7 +42,6 @@ runs: -e CMAKE_OPTIONS \ -e CMAKE_GLOBAL_OPTIONS \ -e GITTEST_NEGOTIATE_PASSWORD \ - -e GITTEST_FLAKY_STAT \ -e PKG_CONFIG_PATH \ -e SKIP_NEGOTIATE_TESTS \ -e SKIP_SSH_TESTS \ diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index d7a6c64c9..d2059cd35 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -282,7 +282,6 @@ jobs: RUN_INVASIVE_TESTS: true SKIP_PROXY_TESTS: true SKIP_PUSHOPTIONS_TESTS: true - GITTEST_FLAKY_STAT: true os: ubuntu-latest - name: "Linux (arm64, Bionic, GCC, OpenSSL)" id: bionic-arm64-gcc-openssl diff --git a/tests/libgit2/diff/workdir.c b/tests/libgit2/diff/workdir.c index 602460908..36eb9a9d3 100644 --- a/tests/libgit2/diff/workdir.c +++ b/tests/libgit2/diff/workdir.c @@ -1291,8 +1291,7 @@ void test_diff_workdir__can_diff_empty_file(void) cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st)); - if (!cl_is_env_set("GITTEST_FLAKY_STAT")) - cl_assert_equal_sz(0, st.st_size); + cl_assert_equal_sz(0, st.st_size); cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts)); cl_assert_equal_i(3, (int)git_diff_num_deltas(diff)); diff --git a/tests/util/copy.c b/tests/util/copy.c index 2613730ba..7ea5d6a39 100644 --- a/tests/util/copy.c +++ b/tests/util/copy.c @@ -14,8 +14,7 @@ void test_copy__file(void) cl_git_pass(git_fs_path_lstat("copy_me_two", &st)); cl_assert(S_ISREG(st.st_mode)); - if (!cl_is_env_set("GITTEST_FLAKY_STAT")) - cl_assert_equal_sz(strlen(content), (size_t)st.st_size); + cl_assert_equal_sz(strlen(content), (size_t)st.st_size); cl_git_pass(p_unlink("copy_me_two")); cl_git_pass(p_unlink("copy_me")); @@ -41,8 +40,7 @@ void test_copy__file_in_dir(void) cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st)); cl_assert(S_ISREG(st.st_mode)); - if (!cl_is_env_set("GITTEST_FLAKY_STAT")) - cl_assert_equal_sz(strlen(content), (size_t)st.st_size); + cl_assert_equal_sz(strlen(content), (size_t)st.st_size); cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES)); cl_assert(!git_fs_path_isdir("an_dir")); @@ -105,8 +103,7 @@ void test_copy__tree(void) cl_git_pass(git_fs_path_lstat("t1/c/f3", &st)); cl_assert(S_ISREG(st.st_mode)); - if (!cl_is_env_set("GITTEST_FLAKY_STAT")) - cl_assert_equal_sz(strlen(content), (size_t)st.st_size); + cl_assert_equal_sz(strlen(content), (size_t)st.st_size); #ifndef GIT_WIN32 memset(&st, 0, sizeof(struct stat)); From 77234526806a043ee057126709426e4756cea0af Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 25 May 2026 21:38:17 +0100 Subject: [PATCH 3/3] build: only set _FILE_OFFSET_BITS on non-Windows mingw is confused - https://github.com/msys2/MINGW-packages/issues/10591 --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22fdc4316..41dae831e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,12 +82,12 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) endif() -# # Common settings across all projects, dependencies, etc. Always support -# 64 bit file operations, even 32 bit platforms. -# +# 64 bit file operations, even on 32 bit platforms. -add_definitions(-D_FILE_OFFSET_BITS=64) +if(NOT WIN32) + add_definitions(-D_FILE_OFFSET_BITS=64) +endif() # Modules