[PATCH] init - Honour the global core.filemode setting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If "~/.gitconfig" contains a "core.filemode" entry then "git init"
should honour that setting.

Signed-off-by: Hilco Wijbenga <hilco.wijbenga@xxxxxxxxx>
---
This bit me at work where I have to work with Windows. Git on Cygwin
and the Eclipse Git plugin do not agree on file attributes so I had
set "filemode = false" in ~/.gitconfig.

A few weeks later, I did a "git init" and, some time later yet, I
noticed the strange behaviour of Cygwin/Eclipse again. This was very
surprising because things had been working well until then. It took
quite a bit of research before I realized that "git init" always sets
"filemode". I think "filemode" should only be set if not set already
in the global config (similar to log_all_ref_updates).

The usual caveat applies: this is my first patch. Having said that,
please feel free to be pedantic and strict. It's a small patch so I
would imagine that fixing any problems should not take long (assuming
it is acceptable at all, of course). I'd like to know I did it right.
:-)

AFAICT, all tests passed. Should a separate test be added for this change?

(I used "git format-patch" and "git imap-send" to send this patch to
the ML but looking below I still do not see tabs? In fact, I do not
see any indentation.)
 builtin/init-db.c | 19 +++++++++++--------
 environment.c     |  2 +-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 56f85e2..19cdc58 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -248,15 +248,18 @@ static int create_default_files(const char *template_path)
  path[len] = 0;
  strcpy(path + len, "config");

- /* Check filemode trustability */
- filemode = TEST_FILEMODE;
- if (TEST_FILEMODE && !lstat(path, &st1)) {
- struct stat st2;
- filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
- !lstat(path, &st2) &&
- st1.st_mode != st2.st_mode);
+ /* Do not override the global filemode setting. */
+ if (trust_executable_bit == -1) {
+ /* Check filemode trustability */
+ filemode = TEST_FILEMODE;
+ if (TEST_FILEMODE && !lstat(path, &st1)) {
+ struct stat st2;
+ filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
+ !lstat(path, &st2) &&
+ st1.st_mode != st2.st_mode);
+ }
+ git_config_set("core.filemode", filemode ? "true" : "false");
  }
- git_config_set("core.filemode", filemode ? "true" : "false");

  if (is_bare_repository())
  git_config_set("core.bare", "true");
diff --git a/environment.c b/environment.c
index 565f652..875a498 100644
--- a/environment.c
+++ b/environment.c
@@ -12,7 +12,7 @@
 #include "fmt-merge-msg.h"
 #include "commit.h"

-int trust_executable_bit = 1;
+int trust_executable_bit = -1;
 int trust_ctime = 1;
 int check_stat = 1;
 int has_symlinks = 1;
-- 
2.1.1.dirty
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]