squash! config.c: create missing parent directories when modifying config files

We *must not* create the leading directories when locking a config file.
It is the caller's responsibility to ensure that the directory exists,
just like it is the caller's responsibility to call `git init` before
running repository operations.

Point in case: if we simply create all leading directories, calling
`git config user.name me` *outside* of a Git worktree will *create*
.git/!

This fixes https://github.com/git-for-windows/git/issues/643 and
https://groups.google.com/forum/#!topic/git-for-windows/fVRdnDIKVuw

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2016-02-24 12:47:18 +01:00
parent bc859c8ac9
commit 2db7919fff

View File

@@ -1951,10 +1951,6 @@ static int lock_config_file(const char *config_filename,
{
int fd;
/* make sure the parent directory exists */
if (safe_create_leading_directories_const(config_filename))
return error("could not create parent directory of %s",
config_filename);
*result = xcalloc(1, sizeof(struct lock_file));
fd = hold_lock_file_for_update(*result, config_filename, 0);
if (fd < 0)