- if (access(path, R_OK) < 0) {
- static const char contents[] =
- "#\n"
- "# This is the config file\n"
- "#\n"
- "\n"
- "; core variables\n"
- "[core]\n"
- " ; Don't trust file modes\n"
- " filemode = false\n"
- "\n";
- FILE *config = fopen(path, "w");
- struct stat st;
-
- if (!config)
- die("Can not write to %s?", path);
-
- fwrite(contents, sizeof(contents)-1, 1, config);
-
- fclose(config);
-
- if (!lstat(path, &st)) {
- struct stat st2;
- if (!chmod(path, st.st_mode ^ S_IXUSR) &&
- !lstat(path, &st2) &&
- st.st_mode != st2.st_mode)
- unlink(path);
- else
- fprintf(stderr, "Ignoring file modes\n");
- }
+
+ /* Check filemode trustability */
+ if (!lstat(path, &st1)) {
+ struct stat st2;
+ int 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");