From e8b81c698c52a7197c0842b6503e8b980d773c74 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 22 Jan 2014 13:24:32 -0500 Subject: [PATCH] Preserve tree filemode in index during checkout Don't try to determine whether the system supports file modes when putting the tree data in the index during checkout. The tree's mode is canonical and did not come from stat(2) in the first place. --- src/checkout.c | 3 +-- tests/checkout/tree.c | 23 ++++++++++++++++++ .../1d/d0968be3ff95fcaecb6fa4245662db9fdc4568 | Bin 0 -> 73 bytes .../af/e4393b2b2a965f06acf2ca9658eaa01e0cd6b6 | Bin 0 -> 171 bytes .../ce/054d4c5e3c83522aed8bc061987b46b7ede3be | Bin 0 -> 194 bytes 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 tests/resources/testrepo/.gitted/objects/1d/d0968be3ff95fcaecb6fa4245662db9fdc4568 create mode 100644 tests/resources/testrepo/.gitted/objects/af/e4393b2b2a965f06acf2ca9658eaa01e0cd6b6 create mode 100644 tests/resources/testrepo/.gitted/objects/ce/054d4c5e3c83522aed8bc061987b46b7ede3be diff --git a/src/checkout.c b/src/checkout.c index cfb0e72ab..962929075 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -1217,8 +1217,7 @@ static int checkout_update_index( memset(&entry, 0, sizeof(entry)); entry.path = (char *)file->path; /* cast to prevent warning */ - git_index_entry__init_from_stat( - &entry, st, !(git_index_caps(data->index) & GIT_INDEXCAP_NO_FILEMODE)); + git_index_entry__init_from_stat(&entry, st, true); git_oid_cpy(&entry.oid, &file->oid); return git_index_add(data->index, &entry); diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index f0699fdb7..047c9ed98 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -925,3 +925,26 @@ void test_checkout_tree__fails_when_conflicts_exist_in_index(void) git_object_free(obj); } + +void test_checkout_tree__filemode_preserved_in_index(void) +{ + git_oid executable_oid; + git_commit *commit; + git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; + git_index *index; + const git_index_entry *entry; + + cl_git_pass(git_repository_index(&index, g_repo)); + + cl_git_pass(git_oid_fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); + + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + + cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); + cl_assert(entry = git_index_get_bypath(index, "executable.txt", 0)); + cl_assert_equal_i(0100755, entry->mode); + + git_commit_free(commit); + git_index_free(index); +} diff --git a/tests/resources/testrepo/.gitted/objects/1d/d0968be3ff95fcaecb6fa4245662db9fdc4568 b/tests/resources/testrepo/.gitted/objects/1d/d0968be3ff95fcaecb6fa4245662db9fdc4568 new file mode 100644 index 0000000000000000000000000000000000000000..97c6b2cfab03b001553d57eb70817c0b69647e1f GIT binary patch literal 73 zcmV-P0Ji^l0ZYosPf{>5V8}=;&QM57%u81&NG!=vD9KkS&d*I%$jmEAEh;EV1(IA` fAsLy)3Tc@+K;dGA)QZ&P(vrlaoK!9VB7zsLOamV1 literal 0 HcmV?d00001 diff --git a/tests/resources/testrepo/.gitted/objects/af/e4393b2b2a965f06acf2ca9658eaa01e0cd6b6 b/tests/resources/testrepo/.gitted/objects/af/e4393b2b2a965f06acf2ca9658eaa01e0cd6b6 new file mode 100644 index 0000000000000000000000000000000000000000..6948f1b1c70464b5914d8f83a3691e5732639ea6 GIT binary patch literal 171 zcmV;c095~Y0i}-3Z2~bA26J{5uYp8f|E(>dC>-d32A-ck3#53Bj1eiHrH0%_a~O^E z)~=I`b02d6B+%X!CmvR!^~Nwt%%a1R;+kE^D++9ey79m^NvBjfvsg~xWW7((n#TIhlFc@g@23d8y@KLk|S?Upq6S whs)s{_e1G}lm7G`HOYh84^y&SwC&*i7t3XG_U8!Ackl^w`fs=w0EuZ