132
return;
133
}
134
135
+ /* Make sure that template is from the correct vintage */
136
+ strcpy(template_path + template_len, "config");
137
+ repository_format_version = 0;
138
+ git_config_from_file(check_repository_format_version,
139
+ template_path);
140
+ template_path[template_len] = 0;
141
+
142
+ if (repository_format_version &&
143
+ repository_format_version != GIT_REPO_VERSION) {
144
+ fprintf(stderr, "warning: not copying templates of "
145
+ "a wrong format version %d from '%s'\n",
146
+ repository_format_version,
147
+ template_dir);
148
+ closedir(dir);
149
+ return;
150
+ }
151
+
152
memcpy(path, git_dir, len);
153
path[len] = 0;
154
copy_templates_1(path, len,
157
closedir(dir);
158
}
159
143
-static void create_default_files(const char *git_dir,
144
- char *template_path)
160
+static void create_default_files(const char *git_dir, char *template_path)
161
{
162
unsigned len = strlen(git_dir);
163
static char path[PATH_MAX];
164
unsigned char sha1[20];
165
+ struct stat st1;
166
+ char repo_version_string[10];
167
168
if (len > sizeof(path)-50)
169
die("insane git directory %s", git_dir);
182
strcpy(path + len, "refs/tags");
183
safe_create_dir(path);
184
185
+ /* First copy the templates -- we might have the default
186
+ * config file there, in which case we would want to read
187
+ * from it after installing.
188
+ */
189
+ path[len] = 0;
190
+ copy_templates(path, len, template_path);
191
+
192
+ git_config(git_default_config);
193
+
194
/*
195
* Create the default symlink from ".git/HEAD" to the "master"
196
* branch, if it does not exist yet.
200
if (create_symref(path, "refs/heads/master") < 0)
201
exit(1);
202
}
176
- path[len] = 0;
177
- copy_templates(path, len, template_path);
203
179
- /*
180
- * Find out if we can trust the executable bit.
181
- */
182
- safe_create_dir(path);
204
+ /* This forces creation of new config file */
205
+ sprintf(repo_version_string, "%d", GIT_REPO_VERSION);
206
+ git_config_set("core.repositoryformatversion", repo_version_string);
207
+
208
+ path[len] = 0;
209
strcpy(path + len, "config");
184
- if (access(path, R_OK) < 0) {
185
- static const char contents[] =
186
- "#\n"
187
- "# This is the config file\n"
188
- "#\n"
189
- "\n"
190
- "; core variables\n"
191
- "[core]\n"
192
- " ; Don't trust file modes\n"
193
- " filemode = false\n"
194
- "\n";
195
- FILE *config = fopen(path, "w");
196
- struct stat st;
197
-
198
- if (!config)
199
- die("Can not write to %s?", path);
200
-
201
- fwrite(contents, sizeof(contents)-1, 1, config);
202
-
203
- fclose(config);
204
-
205
- if (!lstat(path, &st)) {
206
- struct stat st2;
207
- if (!chmod(path, st.st_mode ^ S_IXUSR) &&
208
- !lstat(path, &st2) &&
209
- st.st_mode != st2.st_mode)
210
- unlink(path);
211
- else
212
- fprintf(stderr, "Ignoring file modes\n");
213
- }
210
+
211
+ /* Check filemode trustability */
212
+ if (!lstat(path, &st1)) {
213
+ struct stat st2;
214
+ int filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
215
+ !lstat(path, &st2) &&
216
+ st1.st_mode != st2.st_mode);
217
+ git_config_set("core.filemode",
218
+ filemode ? "true" : "false");
219
}
220
}
221
254
fprintf(stderr, "defaulting to local storage area\n");
255
}
256
safe_create_dir(git_dir);
257
+
258
+ /* Check to see if the repository version is right.
259
+ * Note that a newly created repository does not have
260
+ * config file, so this will not fail. What we are catching
261
+ * is an attempt to reinitialize new repository with an old tool.
262
+ */
263
+ check_repository_format();
264
+
265
create_default_files(git_dir, template_dir);
266
267
/*