{"thread":{"id":"6170","subject":"[PATCH] Force core.filemode to false on Cygwin.","startedAt":"2006-12-31T04:53:55Z","lastAt":"2006-12-31T04:53:55Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30548","messageId":"20061231045355.GA5956@spearce.org","threadId":"6170","inReplyTo":null,"subject":"[PATCH] Force core.filemode to false on Cygwin.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-31T04:53:55Z","receivedAt":"2006-12-31T04:53:55Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Many users have noticed that core.filemode doesn't appear to be\nautomatically set right on Cygwin when using a repository stored\non NTFS.  The issue is that Cygwin and NTFS correctly supports\nthe executable mode bit, and Git properly detected that, but most\nnative Windows applications tend to create files such that Cygwin\nsees the executable bit set when it probably shouldn't be.\n\nThis is especially bad if the user's favorite editor deletes the\nfile then recreates it whenever they save (vs. just overwriting)\nas now a file that was created with mode 0644 by checkout-index\nappears to have mode 0755.\n\nSo we introduce NO_TRUSTABLE_FILEMODE, settable at compile time.\nSetting this option forces core.filemode to false, even if the\ndetection code would have returned true.  This option should be\nenabled by default on Cygwin.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Makefile          |    7 +++++++\n builtin-init-db.c |   14 ++++++++++----\n 2 files changed, 17 insertions(+), 4 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 93dc494..fa1a022 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -72,6 +72,9 @@ all:\n # Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is\n # generally faster on your platform than accessing the working directory.\n #\n+# Define NO_TRUSTABLE_FILEMODE if your filesystem may claim to support\n+# the executable mode bit, but doesn't really do so.\n+#\n # Define NO_IPV6 if you lack IPv6 support and getaddrinfo().\n #\n # Define NO_SOCKADDR_STORAGE if your platform does not have struct\n@@ -361,6 +364,7 @@ ifeq ($(uname_O),Cygwin)\n \tNEEDS_LIBICONV = YesPlease\n \tNO_C99_FORMAT = YesPlease\n \tNO_FAST_WORKING_DIRECTORY = UnfortunatelyYes\n+\tNO_TRUSTABLE_FILEMODE = UnfortunatelyYes\n \t# There are conflicting reports about this.\n \t# On some boxes NO_MMAP is needed, and not so elsewhere.\n \t# Try commenting this out if you suspect MMAP is more efficient\n@@ -521,6 +525,9 @@ endif\n ifdef NO_FAST_WORKING_DIRECTORY\n \tBASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY\n endif\n+ifdef NO_TRUSTABLE_FILEMODE\n+\tBASIC_CFLAGS += -DNO_TRUSTABLE_FILEMODE\n+endif\n ifdef NO_IPV6\n \tBASIC_CFLAGS += -DNO_IPV6\n endif\ndiff --git a/builtin-init-db.c b/builtin-init-db.c\nindex 01f366a..cc4fd21 100644\n--- a/builtin-init-db.c\n+++ b/builtin-init-db.c\n@@ -10,6 +10,12 @@\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates/\"\n #endif\n \n+#ifdef NO_TRUSTABLE_FILEMODE\n+#define TEST_FILEMODE 0\n+#else\n+#define TEST_FILEMODE 1\n+#endif\n+\n static void safe_create_dir(const char *dir, int share)\n {\n \tif (mkdir(dir, 0777) < 0) {\n@@ -236,14 +242,14 @@ static int create_default_files(const char *git_dir, const char *template_path)\n \tstrcpy(path + len, \"config\");\n \n \t/* Check filemode trustability */\n-\tif (!lstat(path, &st1)) {\n+\tint filemode = TEST_FILEMODE;\n+\tif (TEST_FILEMODE && !lstat(path, &st1)) {\n \t\tstruct stat st2;\n-\t\tint filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&\n+\t\tfilemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&\n \t\t\t\t!lstat(path, &st2) &&\n \t\t\t\tst1.st_mode != st2.st_mode);\n-\t\tgit_config_set(\"core.filemode\",\n-\t\t\t       filemode ? \"true\" : \"false\");\n \t}\n+\tgit_config_set(\"core.filemode\", filemode ? \"true\" : \"false\");\n \n \t/* Enable logAllRefUpdates if a working tree is attached */\n \tif (!is_bare_git_dir(git_dir))\n-- \n1.5.0.rc0.g6bb1\n"}]}