{"thread":{"id":"5717","subject":"[PATCH] Ignore executable bit when adding files if filemode=0.","startedAt":"2006-09-27T05:21:19Z","lastAt":"2006-09-27T05:21:19Z","messageCount":1,"participants":["Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"27758","messageId":"20060927052119.GA9614@spearce.org","threadId":"5717","inReplyTo":null,"subject":"[PATCH] Ignore executable bit when adding files if filemode=0.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-09-27T05:21:19Z","receivedAt":"2006-09-27T05:21:19Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If the user has configured core.filemode=0 then we shouldn't set\nthe execute bit in the index when adding a new file as the user\nhas indicated that the local filesystem can't be trusted.\n\nThis means that when adding files that should be marked executable\nin a repository with core.filemode=0 the user must perform a\n'git update-index --chmod=+x' on the file before committing the\naddition.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-update-index.c |    4 +++-\n read-cache.c           |    4 +++-\n t/t3700-add.sh         |   22 ++++++++++++++++++++++\n 3 files changed, 28 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-update-index.c b/builtin-update-index.c\nindex 0620e77..a3c0a45 100644\n--- a/builtin-update-index.c\n+++ b/builtin-update-index.c\n@@ -112,11 +112,13 @@ static int add_file_to_cache(const char \n \tce->ce_mode = create_ce_mode(st.st_mode);\n \tif (!trust_executable_bit) {\n \t\t/* If there is an existing entry, pick the mode bits\n-\t\t * from it.\n+\t\t * from it, otherwise force to 644.\n \t\t */\n \t\tint pos = cache_name_pos(path, namelen);\n \t\tif (0 <= pos)\n \t\t\tce->ce_mode = active_cache[pos]->ce_mode;\n+\t\telse\n+\t\t\tce->ce_mode = create_ce_mode(S_IFREG | 0644);\n \t}\n \n \tif (index_path(ce->sha1, path, &st, !info_only))\ndiff --git a/read-cache.c b/read-cache.c\nindex 20c9d49..97c3867 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -347,11 +347,13 @@ int add_file_to_index(const char *path, \n \tce->ce_mode = create_ce_mode(st.st_mode);\n \tif (!trust_executable_bit) {\n \t\t/* If there is an existing entry, pick the mode bits\n-\t\t * from it.\n+\t\t * from it, otherwise force to 644.\n \t\t */\n \t\tint pos = cache_name_pos(path, namelen);\n \t\tif (pos >= 0)\n \t\t\tce->ce_mode = active_cache[pos]->ce_mode;\n+\t\telse\n+\t\t\tce->ce_mode = create_ce_mode(S_IFREG | 0644);\n \t}\n \n \tif (index_path(ce->sha1, path, &st, 1))\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 6cd05c3..d36f22d 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -19,4 +19,26 @@ test_expect_success \\\n     'Test that \"git-add -- -q\" works' \\\n     'touch -- -q && git-add -- -q'\n \n+test_expect_success \\\n+\t'git-add: Test that executable bit is not used if core.filemode=0' \\\n+\t'git repo-config core.filemode 0 &&\n+\t echo foo >xfoo1 &&\n+\t chmod 755 xfoo1 &&\n+\t git-add xfoo1 &&\n+\t case \"`git-ls-files --stage xfoo1`\" in\n+\t 100644\" \"*xfoo1) echo ok;;\n+\t *) echo fail; git-ls-files --stage xfoo1; exit 1;;\n+\t esac'\n+\n+test_expect_success \\\n+\t'git-update-index --add: Test that executable bit is not used...' \\\n+\t'git repo-config core.filemode 0 &&\n+\t echo foo >xfoo2 &&\n+\t chmod 755 xfoo2 &&\n+\t git-add xfoo2 &&\n+\t case \"`git-ls-files --stage xfoo2`\" in\n+\t 100644\" \"*xfoo2) echo ok;;\n+\t *) echo fail; git-ls-files --stage xfoo2; exit 1;;\n+\t esac'\n+\n test_done\n-- \n1.4.2.1.g7a39b\n"}]}