From 2fbce0bfaca90dd71a2cc10a7fa82088150e04b7 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 2 Feb 2015 22:18:38 -0500 Subject: [PATCH] checkout test: ensure .gitattributes lifecycle The .gitattributes cache should not reload .gitattributes in the middle of checking out, only between checkout operations. Otherwise, we'll spend all our time stat'ing and read'ing the gitattributes. --- tests/checkout/tree.c | 50 ++++++++++++++++++ .../6f/d5c7dd2ab27b48c493023f794be09861e9045f | Bin 0 -> 180 bytes .../c3/6d8ea75da8cb510fcb0c408c1d7e53f9a99dbe | Bin 0 -> 192 bytes .../e3/6900c3224db4adf4c7f7a09d4ac80247978a13 | Bin 0 -> 59 bytes .../testrepo/.gitted/refs/heads/ident | Bin 0 -> 41 bytes 5 files changed, 50 insertions(+) create mode 100644 tests/resources/testrepo/.gitted/objects/6f/d5c7dd2ab27b48c493023f794be09861e9045f create mode 100644 tests/resources/testrepo/.gitted/objects/c3/6d8ea75da8cb510fcb0c408c1d7e53f9a99dbe create mode 100644 tests/resources/testrepo/.gitted/objects/e3/6900c3224db4adf4c7f7a09d4ac80247978a13 create mode 100644 tests/resources/testrepo/.gitted/refs/heads/ident diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index f37e6d359..42f32a8d9 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -1130,3 +1130,53 @@ void test_checkout_tree__can_collect_perfdata(void) git_object_free(obj); } + +void update_attr_callback( + const char *path, + size_t completed_steps, + size_t total_steps, + void *payload) +{ + if (path && strcmp(path, "ident1.txt") == 0) + cl_git_write2file("testrepo/.gitattributes", + "*.txt ident\n", 12, O_RDWR|O_CREAT, 0666); +} + +void test_checkout_tree__caches_attributes_during_checkout(void) +{ + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + git_oid oid; + git_object *obj = NULL; + git_buf ident1 = GIT_BUF_INIT, ident2 = GIT_BUF_INIT; + char *ident_paths[] = { "ident1.txt", "ident2.txt" }; + + opts.progress_cb = update_attr_callback; + + assert_on_branch(g_repo, "master"); + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + opts.paths.strings = ident_paths; + opts.paths.count = 2; + + cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/ident")); + cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); + + cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); + + cl_git_pass(git_futils_readbuffer(&ident1, "testrepo/ident1.txt")); + cl_git_pass(git_futils_readbuffer(&ident2, "testrepo/ident2.txt")); + + cl_assert_equal_strn(ident1.ptr, "# $Id$", 6); + cl_assert_equal_strn(ident2.ptr, "# $Id$", 6); + + cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); + + cl_git_pass(git_futils_readbuffer(&ident1, "testrepo/ident1.txt")); + cl_git_pass(git_futils_readbuffer(&ident2, "testrepo/ident2.txt")); + + cl_assert_equal_strn(ident1.ptr, "# $Id: ", 7); + cl_assert_equal_strn(ident2.ptr, "# $Id: ", 7); + + git_buf_free(&ident1); + git_buf_free(&ident2); + git_object_free(obj); +} diff --git a/tests/resources/testrepo/.gitted/objects/6f/d5c7dd2ab27b48c493023f794be09861e9045f b/tests/resources/testrepo/.gitted/objects/6f/d5c7dd2ab27b48c493023f794be09861e9045f new file mode 100644 index 0000000000000000000000000000000000000000..7f0c6fe4e5a08884660d13a7bca05fd95ae572dc GIT binary patch literal 180 zcmV;l089UP0i};YsskYqM6>o3eSri=5He@g~FfcPQQ3!H%bn$g%SfOmF@NI2De~WFK%%kl}eMcVO zI|fyeRFs&PoDrXvnUktlQc=QSHvO9SOUI?QUN62aDtz+zSJ(!nGf<_ODXDoShG12X zGZ_vm`EFVJ<@omnbG=S5xlivBMpk8nTa}Rk5Gdqi=4Hp13Wl&a7@k~+SQsz=t2+7DSR!GatNmVG%%*jzmN>#{ANzE$( R36-Q4rKad{0RV?s56uB&8Eyao literal 0 HcmV?d00001 diff --git a/tests/resources/testrepo/.gitted/refs/heads/ident b/tests/resources/testrepo/.gitted/refs/heads/ident new file mode 100644 index 0000000000000000000000000000000000000000..2cfd880a3d44e0e6e90f472eb63614df8c466d5a GIT binary patch literal 41 tcmV~$M*#pJ2mrvpX^>4ES^Xn;r`uB2jW5xXy*LPv)`D{&T<-+1?D_J03fuqy literal 0 HcmV?d00001