2005-04-08 00:16:10 +02:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Linus Torvalds, 2005
|
|
|
|
*/
|
2005-04-08 00:13:13 +02:00
|
|
|
#include "cache.h"
|
2006-05-19 12:03:57 +02:00
|
|
|
#include "builtin.h"
|
2007-11-13 21:05:04 +01:00
|
|
|
#include "exec_cmd.h"
|
2009-07-12 12:24:32 +02:00
|
|
|
#include "parse-options.h"
|
2005-04-08 00:13:13 +02:00
|
|
|
|
2005-08-06 21:50:14 +02:00
|
|
|
#ifndef DEFAULT_GIT_TEMPLATE_DIR
|
2007-06-11 11:10:47 +02:00
|
|
|
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
|
2005-08-06 21:50:14 +02:00
|
|
|
#endif
|
|
|
|
|
2006-12-31 05:53:55 +01:00
|
|
|
#ifdef NO_TRUSTABLE_FILEMODE
|
|
|
|
#define TEST_FILEMODE 0
|
|
|
|
#else
|
|
|
|
#define TEST_FILEMODE 1
|
|
|
|
#endif
|
|
|
|
|
git init: --bare/--shared overrides system/global config
If core.bare or core.sharedRepository are set in /etc/gitconfig or
~/.gitconfig, then 'git init' will read the values when constructing a
new config file; reading them, however, will override the values
specified on the command line. In the case of --bare, this ends up
causing a segfault, without the repository being properly initialised;
in the case of --shared, the permissions are set according to the
existing config settings, not what was specified on the command line.
This fix saves any specified values for --bare and --shared prior to
reading existing config settings, and restores them after reading but
before writing the new config file. core.bare is ignored in all
situations, while core.sharedRepository will only be used if --shared
is not specified to git init.
Also includes testcases which use a specified global config file
override, demonstrating the former failure scenario.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-07 07:37:48 +02:00
|
|
|
static int init_is_bare_repository = 0;
|
|
|
|
static int init_shared_repository = -1;
|
2010-02-17 00:42:31 +01:00
|
|
|
static const char *init_db_template_dir;
|
2011-03-19 16:16:56 +01:00
|
|
|
static const char *git_link;
|
git init: --bare/--shared overrides system/global config
If core.bare or core.sharedRepository are set in /etc/gitconfig or
~/.gitconfig, then 'git init' will read the values when constructing a
new config file; reading them, however, will override the values
specified on the command line. In the case of --bare, this ends up
causing a segfault, without the repository being properly initialised;
in the case of --shared, the permissions are set according to the
existing config settings, not what was specified on the command line.
This fix saves any specified values for --bare and --shared prior to
reading existing config settings, and restores them after reading but
before writing the new config file. core.bare is ignored in all
situations, while core.sharedRepository will only be used if --shared
is not specified to git init.
Also includes testcases which use a specified global config file
override, demonstrating the former failure scenario.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-07 07:37:48 +02:00
|
|
|
|
2005-12-22 23:19:37 +01:00
|
|
|
static void safe_create_dir(const char *dir, int share)
|
2005-04-20 06:48:15 +02:00
|
|
|
{
|
2005-07-06 10:21:46 +02:00
|
|
|
if (mkdir(dir, 0777) < 0) {
|
2005-04-20 06:48:15 +02:00
|
|
|
if (errno != EEXIST) {
|
|
|
|
perror(dir);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2005-12-22 23:19:37 +01:00
|
|
|
else if (share && adjust_shared_perm(dir))
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("Could not make %s writable by group"), dir);
|
2005-04-20 06:48:15 +02:00
|
|
|
}
|
|
|
|
|
2005-08-03 01:45:21 +02:00
|
|
|
static void copy_templates_1(char *path, int baselen,
|
|
|
|
char *template, int template_baselen,
|
|
|
|
DIR *dir)
|
|
|
|
{
|
|
|
|
struct dirent *de;
|
|
|
|
|
|
|
|
/* Note: if ".git/hooks" file exists in the repository being
|
|
|
|
* re-initialized, /etc/core-git/templates/hooks/update would
|
2008-09-13 19:18:36 +02:00
|
|
|
* cause "git init" to fail here. I think this is sane but
|
2005-08-03 01:45:21 +02:00
|
|
|
* it means that the set of templates we ship by default, along
|
|
|
|
* with the way the namespace under .git/ is organized, should
|
|
|
|
* be really carefully chosen.
|
|
|
|
*/
|
2005-12-22 23:19:37 +01:00
|
|
|
safe_create_dir(path, 1);
|
2005-08-03 01:45:21 +02:00
|
|
|
while ((de = readdir(dir)) != NULL) {
|
|
|
|
struct stat st_git, st_template;
|
|
|
|
int namelen;
|
|
|
|
int exists = 0;
|
|
|
|
|
|
|
|
if (de->d_name[0] == '.')
|
|
|
|
continue;
|
|
|
|
namelen = strlen(de->d_name);
|
|
|
|
if ((PATH_MAX <= baselen + namelen) ||
|
|
|
|
(PATH_MAX <= template_baselen + namelen))
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("insanely long template name %s"), de->d_name);
|
2005-08-03 01:45:21 +02:00
|
|
|
memcpy(path + baselen, de->d_name, namelen+1);
|
|
|
|
memcpy(template + template_baselen, de->d_name, namelen+1);
|
|
|
|
if (lstat(path, &st_git)) {
|
|
|
|
if (errno != ENOENT)
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot stat '%s'"), path);
|
2005-08-03 01:45:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
exists = 1;
|
|
|
|
|
|
|
|
if (lstat(template, &st_template))
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot stat template '%s'"), template);
|
2005-08-03 01:45:21 +02:00
|
|
|
|
|
|
|
if (S_ISDIR(st_template.st_mode)) {
|
|
|
|
DIR *subdir = opendir(template);
|
|
|
|
int baselen_sub = baselen + namelen;
|
|
|
|
int template_baselen_sub = template_baselen + namelen;
|
|
|
|
if (!subdir)
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot opendir '%s'"), template);
|
2005-08-03 01:45:21 +02:00
|
|
|
path[baselen_sub++] =
|
|
|
|
template[template_baselen_sub++] = '/';
|
|
|
|
path[baselen_sub] =
|
|
|
|
template[template_baselen_sub] = 0;
|
|
|
|
copy_templates_1(path, baselen_sub,
|
|
|
|
template, template_baselen_sub,
|
|
|
|
subdir);
|
|
|
|
closedir(subdir);
|
|
|
|
}
|
|
|
|
else if (exists)
|
|
|
|
continue;
|
|
|
|
else if (S_ISLNK(st_template.st_mode)) {
|
|
|
|
char lnk[256];
|
|
|
|
int len;
|
|
|
|
len = readlink(template, lnk, sizeof(lnk));
|
|
|
|
if (len < 0)
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot readlink '%s'"), template);
|
2005-08-03 01:45:21 +02:00
|
|
|
if (sizeof(lnk) <= len)
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("insanely long symlink %s"), template);
|
2005-08-03 01:45:21 +02:00
|
|
|
lnk[len] = 0;
|
|
|
|
if (symlink(lnk, path))
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot symlink '%s' '%s'"), lnk, path);
|
2005-08-03 01:45:21 +02:00
|
|
|
}
|
|
|
|
else if (S_ISREG(st_template.st_mode)) {
|
|
|
|
if (copy_file(path, template, st_template.st_mode))
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot copy '%s' to '%s'"), template,
|
2009-06-27 17:58:47 +02:00
|
|
|
path);
|
2005-08-03 01:45:21 +02:00
|
|
|
}
|
|
|
|
else
|
2011-02-23 00:41:24 +01:00
|
|
|
error(_("ignoring template %s"), template);
|
2005-08-03 01:45:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
static void copy_templates(const char *template_dir)
|
2005-08-03 01:45:21 +02:00
|
|
|
{
|
|
|
|
char path[PATH_MAX];
|
|
|
|
char template_path[PATH_MAX];
|
2005-08-06 21:50:14 +02:00
|
|
|
int template_len;
|
2005-08-03 01:45:21 +02:00
|
|
|
DIR *dir;
|
2008-04-27 19:39:27 +02:00
|
|
|
const char *git_dir = get_git_dir();
|
|
|
|
int len = strlen(git_dir);
|
2014-11-24 20:33:54 +01:00
|
|
|
char *to_free = NULL;
|
2005-08-03 01:45:21 +02:00
|
|
|
|
2007-11-13 21:05:04 +01:00
|
|
|
if (!template_dir)
|
2006-12-19 10:28:15 +01:00
|
|
|
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
|
2010-02-17 00:42:31 +01:00
|
|
|
if (!template_dir)
|
|
|
|
template_dir = init_db_template_dir;
|
2008-07-13 22:31:18 +02:00
|
|
|
if (!template_dir)
|
2014-11-24 20:33:54 +01:00
|
|
|
template_dir = to_free = system_path(DEFAULT_GIT_TEMPLATE_DIR);
|
|
|
|
if (!template_dir[0]) {
|
|
|
|
free(to_free);
|
2008-07-28 08:02:04 +02:00
|
|
|
return;
|
2014-11-24 20:33:54 +01:00
|
|
|
}
|
2009-04-18 16:14:02 +02:00
|
|
|
template_len = strlen(template_dir);
|
|
|
|
if (PATH_MAX <= (template_len+strlen("/config")))
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("insanely long template path %s"), template_dir);
|
2005-08-03 01:45:21 +02:00
|
|
|
strcpy(template_path, template_dir);
|
|
|
|
if (template_path[template_len-1] != '/') {
|
|
|
|
template_path[template_len++] = '/';
|
|
|
|
template_path[template_len] = 0;
|
|
|
|
}
|
|
|
|
dir = opendir(template_path);
|
2005-08-06 21:50:14 +02:00
|
|
|
if (!dir) {
|
2011-02-23 00:41:24 +01:00
|
|
|
warning(_("templates not found %s"), template_dir);
|
2014-11-24 20:33:54 +01:00
|
|
|
goto free_return;
|
2005-08-06 21:50:14 +02:00
|
|
|
}
|
|
|
|
|
2005-11-26 01:03:56 +01:00
|
|
|
/* Make sure that template is from the correct vintage */
|
|
|
|
strcpy(template_path + template_len, "config");
|
|
|
|
repository_format_version = 0;
|
|
|
|
git_config_from_file(check_repository_format_version,
|
2008-05-14 19:46:53 +02:00
|
|
|
template_path, NULL);
|
2005-11-26 01:03:56 +01:00
|
|
|
template_path[template_len] = 0;
|
|
|
|
|
|
|
|
if (repository_format_version &&
|
|
|
|
repository_format_version != GIT_REPO_VERSION) {
|
2011-02-23 00:41:24 +01:00
|
|
|
warning(_("not copying templates of "
|
|
|
|
"a wrong format version %d from '%s'"),
|
2005-11-26 01:03:56 +01:00
|
|
|
repository_format_version,
|
|
|
|
template_dir);
|
2014-11-24 20:33:54 +01:00
|
|
|
goto close_free_return;
|
2005-11-26 01:03:56 +01:00
|
|
|
}
|
|
|
|
|
2005-08-06 21:50:14 +02:00
|
|
|
memcpy(path, git_dir, len);
|
2008-04-27 19:39:27 +02:00
|
|
|
if (len && path[len - 1] != '/')
|
|
|
|
path[len++] = '/';
|
2005-09-20 02:19:50 +02:00
|
|
|
path[len] = 0;
|
2005-08-03 01:45:21 +02:00
|
|
|
copy_templates_1(path, len,
|
|
|
|
template_path, template_len,
|
|
|
|
dir);
|
2014-11-24 20:33:54 +01:00
|
|
|
close_free_return:
|
2005-08-03 01:45:21 +02:00
|
|
|
closedir(dir);
|
2014-11-24 20:33:54 +01:00
|
|
|
free_return:
|
|
|
|
free(to_free);
|
2005-08-03 01:45:21 +02:00
|
|
|
}
|
|
|
|
|
2010-02-17 00:42:31 +01:00
|
|
|
static int git_init_db_config(const char *k, const char *v, void *cb)
|
|
|
|
{
|
|
|
|
if (!strcmp(k, "init.templatedir"))
|
|
|
|
return git_config_pathname(&init_db_template_dir, k, v);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
static int create_default_files(const char *template_path)
|
2005-05-30 19:20:44 +02:00
|
|
|
{
|
2008-04-27 19:39:27 +02:00
|
|
|
const char *git_dir = get_git_dir();
|
2005-05-30 19:20:44 +02:00
|
|
|
unsigned len = strlen(git_dir);
|
|
|
|
static char path[PATH_MAX];
|
2005-11-26 01:03:56 +01:00
|
|
|
struct stat st1;
|
|
|
|
char repo_version_string[10];
|
2008-03-24 16:14:52 +01:00
|
|
|
char junk[2];
|
2006-12-15 06:44:58 +01:00
|
|
|
int reinit;
|
2006-12-31 05:53:55 +01:00
|
|
|
int filemode;
|
2005-05-30 19:20:44 +02:00
|
|
|
|
|
|
|
if (len > sizeof(path)-50)
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("insane git directory %s"), git_dir);
|
2005-05-30 19:20:44 +02:00
|
|
|
memcpy(path, git_dir, len);
|
|
|
|
|
|
|
|
if (len && path[len-1] != '/')
|
|
|
|
path[len++] = '/';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create .git/refs/{heads,tags}
|
|
|
|
*/
|
2008-04-27 19:39:27 +02:00
|
|
|
safe_create_dir(git_path("refs"), 1);
|
|
|
|
safe_create_dir(git_path("refs/heads"), 1);
|
|
|
|
safe_create_dir(git_path("refs/tags"), 1);
|
2005-05-30 19:20:44 +02:00
|
|
|
|
2010-02-17 00:42:31 +01:00
|
|
|
/* Just look for `init.templatedir` */
|
|
|
|
git_config(git_init_db_config, NULL);
|
|
|
|
|
2005-11-26 01:03:56 +01:00
|
|
|
/* First copy the templates -- we might have the default
|
|
|
|
* config file there, in which case we would want to read
|
|
|
|
* from it after installing.
|
|
|
|
*/
|
2008-04-27 19:39:27 +02:00
|
|
|
copy_templates(template_path);
|
2005-11-26 01:03:56 +01:00
|
|
|
|
2008-05-14 19:46:53 +02:00
|
|
|
git_config(git_default_config, NULL);
|
git init: --bare/--shared overrides system/global config
If core.bare or core.sharedRepository are set in /etc/gitconfig or
~/.gitconfig, then 'git init' will read the values when constructing a
new config file; reading them, however, will override the values
specified on the command line. In the case of --bare, this ends up
causing a segfault, without the repository being properly initialised;
in the case of --shared, the permissions are set according to the
existing config settings, not what was specified on the command line.
This fix saves any specified values for --bare and --shared prior to
reading existing config settings, and restores them after reading but
before writing the new config file. core.bare is ignored in all
situations, while core.sharedRepository will only be used if --shared
is not specified to git init.
Also includes testcases which use a specified global config file
override, demonstrating the former failure scenario.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-07 07:37:48 +02:00
|
|
|
is_bare_repository_cfg = init_is_bare_repository;
|
2009-03-26 00:19:36 +01:00
|
|
|
|
|
|
|
/* reading existing config may have overwrote it */
|
git init: --bare/--shared overrides system/global config
If core.bare or core.sharedRepository are set in /etc/gitconfig or
~/.gitconfig, then 'git init' will read the values when constructing a
new config file; reading them, however, will override the values
specified on the command line. In the case of --bare, this ends up
causing a segfault, without the repository being properly initialised;
in the case of --shared, the permissions are set according to the
existing config settings, not what was specified on the command line.
This fix saves any specified values for --bare and --shared prior to
reading existing config settings, and restores them after reading but
before writing the new config file. core.bare is ignored in all
situations, while core.sharedRepository will only be used if --shared
is not specified to git init.
Also includes testcases which use a specified global config file
override, demonstrating the former failure scenario.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-07 07:37:48 +02:00
|
|
|
if (init_shared_repository != -1)
|
|
|
|
shared_repository = init_shared_repository;
|
2005-11-26 01:03:56 +01:00
|
|
|
|
2006-06-10 07:07:23 +02:00
|
|
|
/*
|
|
|
|
* We would have created the above under user's umask -- under
|
|
|
|
* shared-repository settings, we would need to fix them up.
|
|
|
|
*/
|
|
|
|
if (shared_repository) {
|
2008-04-27 19:39:27 +02:00
|
|
|
adjust_shared_perm(get_git_dir());
|
|
|
|
adjust_shared_perm(git_path("refs"));
|
|
|
|
adjust_shared_perm(git_path("refs/heads"));
|
|
|
|
adjust_shared_perm(git_path("refs/tags"));
|
2006-06-10 07:07:23 +02:00
|
|
|
}
|
|
|
|
|
2005-05-30 19:20:44 +02:00
|
|
|
/*
|
|
|
|
* Create the default symlink from ".git/HEAD" to the "master"
|
2005-09-30 23:26:57 +02:00
|
|
|
* branch, if it does not exist yet.
|
2005-05-30 19:20:44 +02:00
|
|
|
*/
|
|
|
|
strcpy(path + len, "HEAD");
|
2008-03-24 16:14:52 +01:00
|
|
|
reinit = (!access(path, R_OK)
|
|
|
|
|| readlink(path, junk, sizeof(junk)-1) != -1);
|
2006-12-15 06:44:58 +01:00
|
|
|
if (!reinit) {
|
2007-01-26 23:26:10 +01:00
|
|
|
if (create_symref("HEAD", "refs/heads/master", NULL) < 0)
|
2005-05-30 19:20:44 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2005-10-26 01:43:03 +02:00
|
|
|
|
2005-11-26 01:03:56 +01:00
|
|
|
/* This forces creation of new config file */
|
|
|
|
sprintf(repo_version_string, "%d", GIT_REPO_VERSION);
|
|
|
|
git_config_set("core.repositoryformatversion", repo_version_string);
|
|
|
|
|
|
|
|
path[len] = 0;
|
2005-10-26 01:43:03 +02:00
|
|
|
strcpy(path + len, "config");
|
2005-11-26 01:03:56 +01:00
|
|
|
|
|
|
|
/* Check filemode trustability */
|
2006-12-31 05:53:55 +01:00
|
|
|
filemode = TEST_FILEMODE;
|
|
|
|
if (TEST_FILEMODE && !lstat(path, &st1)) {
|
2005-11-26 01:03:56 +01:00
|
|
|
struct stat st2;
|
2006-12-31 05:53:55 +01:00
|
|
|
filemode = (!chmod(path, st1.st_mode ^ S_IXUSR) &&
|
2005-11-26 01:03:56 +01:00
|
|
|
!lstat(path, &st2) &&
|
2014-11-18 14:50:24 +01:00
|
|
|
st1.st_mode != st2.st_mode &&
|
|
|
|
!chmod(path, st1.st_mode));
|
2014-11-21 10:34:54 +01:00
|
|
|
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
|
|
|
|
filemode = 0;
|
2005-10-26 01:43:03 +02:00
|
|
|
}
|
2006-12-31 05:53:55 +01:00
|
|
|
git_config_set("core.filemode", filemode ? "true" : "false");
|
2006-12-15 06:44:58 +01:00
|
|
|
|
Clean up work-tree handling
The old version of work-tree support was an unholy mess, barely readable,
and not to the point.
For example, why do you have to provide a worktree, when it is not used?
As in "git status". Now it works.
Another riddle was: if you can have work trees inside the git dir, why
are some programs complaining that they need a work tree?
IOW it is allowed to call
$ git --git-dir=../ --work-tree=. bla
when you really want to. In this case, you are both in the git directory
and in the working tree. So, programs have to actually test for the right
thing, namely if they are inside a working tree, and not if they are
inside a git directory.
Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was
specified, unless there is a repository in the current working directory.
It does now.
The logic to determine if a repository is bare, or has a work tree
(tertium non datur), is this:
--work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true,
which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR
ends in /.git, which overrides the directory in which .git/ was found.
In related news, a long standing bug was fixed: when in .git/bla/x.git/,
which is a bare repository, git formerly assumed ../.. to be the
appropriate git dir. This problem was reported by Shawn Pearce to have
caused much pain, where a colleague mistakenly ran "git init" in "/" a
long time ago, and bare repositories just would not work.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-08-01 02:30:14 +02:00
|
|
|
if (is_bare_repository())
|
2007-01-07 11:00:28 +01:00
|
|
|
git_config_set("core.bare", "true");
|
|
|
|
else {
|
Clean up work-tree handling
The old version of work-tree support was an unholy mess, barely readable,
and not to the point.
For example, why do you have to provide a worktree, when it is not used?
As in "git status". Now it works.
Another riddle was: if you can have work trees inside the git dir, why
are some programs complaining that they need a work tree?
IOW it is allowed to call
$ git --git-dir=../ --work-tree=. bla
when you really want to. In this case, you are both in the git directory
and in the working tree. So, programs have to actually test for the right
thing, namely if they are inside a working tree, and not if they are
inside a git directory.
Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was
specified, unless there is a repository in the current working directory.
It does now.
The logic to determine if a repository is bare, or has a work tree
(tertium non datur), is this:
--work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true,
which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR
ends in /.git, which overrides the directory in which .git/ was found.
In related news, a long standing bug was fixed: when in .git/bla/x.git/,
which is a bare repository, git formerly assumed ../.. to be the
appropriate git dir. This problem was reported by Shawn Pearce to have
caused much pain, where a colleague mistakenly ran "git init" in "/" a
long time ago, and bare repositories just would not work.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-08-01 02:30:14 +02:00
|
|
|
const char *work_tree = get_git_work_tree();
|
2007-01-07 11:00:28 +01:00
|
|
|
git_config_set("core.bare", "false");
|
2007-01-23 16:51:18 +01:00
|
|
|
/* allow template config file to override the default */
|
|
|
|
if (log_all_ref_updates == -1)
|
|
|
|
git_config_set("core.logallrefupdates", "true");
|
2013-11-30 21:55:40 +01:00
|
|
|
if (!starts_with(git_dir, work_tree) ||
|
2008-04-27 19:39:27 +02:00
|
|
|
strcmp(git_dir + strlen(work_tree), "/.git")) {
|
Clean up work-tree handling
The old version of work-tree support was an unholy mess, barely readable,
and not to the point.
For example, why do you have to provide a worktree, when it is not used?
As in "git status". Now it works.
Another riddle was: if you can have work trees inside the git dir, why
are some programs complaining that they need a work tree?
IOW it is allowed to call
$ git --git-dir=../ --work-tree=. bla
when you really want to. In this case, you are both in the git directory
and in the working tree. So, programs have to actually test for the right
thing, namely if they are inside a working tree, and not if they are
inside a git directory.
Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was
specified, unless there is a repository in the current working directory.
It does now.
The logic to determine if a repository is bare, or has a work tree
(tertium non datur), is this:
--work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true,
which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR
ends in /.git, which overrides the directory in which .git/ was found.
In related news, a long standing bug was fixed: when in .git/bla/x.git/,
which is a bare repository, git formerly assumed ../.. to be the
appropriate git dir. This problem was reported by Shawn Pearce to have
caused much pain, where a colleague mistakenly ran "git init" in "/" a
long time ago, and bare repositories just would not work.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-08-01 02:30:14 +02:00
|
|
|
git_config_set("core.worktree", work_tree);
|
2008-04-27 19:39:27 +02:00
|
|
|
}
|
2007-01-07 11:00:28 +01:00
|
|
|
}
|
2007-08-31 09:25:04 +02:00
|
|
|
|
|
|
|
if (!reinit) {
|
2008-05-11 18:16:39 +02:00
|
|
|
/* Check if symlink is supported in the work tree */
|
2007-08-31 09:25:04 +02:00
|
|
|
path[len] = 0;
|
|
|
|
strcpy(path + len, "tXXXXXX");
|
|
|
|
if (!close(xmkstemp(path)) &&
|
|
|
|
!unlink(path) &&
|
|
|
|
!symlink("testing", path) &&
|
|
|
|
!lstat(path, &st1) &&
|
|
|
|
S_ISLNK(st1.st_mode))
|
|
|
|
unlink(path); /* good */
|
|
|
|
else
|
|
|
|
git_config_set("core.symlinks", "false");
|
2008-05-11 18:16:39 +02:00
|
|
|
|
|
|
|
/* Check if the filesystem is case-insensitive */
|
|
|
|
path[len] = 0;
|
|
|
|
strcpy(path + len, "CoNfIg");
|
|
|
|
if (!access(path, F_OK))
|
|
|
|
git_config_set("core.ignorecase", "true");
|
git on Mac OS and precomposed unicode
Mac OS X mangles file names containing unicode on file systems HFS+,
VFAT or SAMBA. When a file using unicode code points outside ASCII
is created on a HFS+ drive, the file name is converted into
decomposed unicode and written to disk. No conversion is done if
the file name is already decomposed unicode.
Calling open("\xc3\x84", ...) with a precomposed "Ä" yields the same
result as open("\x41\xcc\x88",...) with a decomposed "Ä".
As a consequence, readdir() returns the file names in decomposed
unicode, even if the user expects precomposed unicode. Unlike on
HFS+, Mac OS X stores files on a VFAT drive (e.g. an USB drive) in
precomposed unicode, but readdir() still returns file names in
decomposed unicode. When a git repository is stored on a network
share using SAMBA, file names are send over the wire and written to
disk on the remote system in precomposed unicode, but Mac OS X
readdir() returns decomposed unicode to be compatible with its
behaviour on HFS+ and VFAT.
The unicode decomposition causes many problems:
- The names "git add" and other commands get from the end user may
often be precomposed form (the decomposed form is not easily input
from the keyboard), but when the commands read from the filesystem
to see what it is going to update the index with already is on the
filesystem, readdir() will give decomposed form, which is different.
- Similarly "git log", "git mv" and all other commands that need to
compare pathnames found on the command line (often but not always
precomposed form; a command line input resulting from globbing may
be in decomposed) with pathnames found in the tree objects (should
be precomposed form to be compatible with other systems and for
consistency in general).
- The same for names stored in the index, which should be
precomposed, that may need to be compared with the names read from
readdir().
NFS mounted from Linux is fully transparent and does not suffer from
the above.
As Mac OS X treats precomposed and decomposed file names as equal,
we can
- wrap readdir() on Mac OS X to return the precomposed form, and
- normalize decomposed form given from the command line also to the
precomposed form,
to ensure that all pathnames used in Git are always in the
precomposed form. This behaviour can be requested by setting
"core.precomposedunicode" configuration variable to true.
The code in compat/precomposed_utf8.c implements basically 4 new
functions: precomposed_utf8_opendir(), precomposed_utf8_readdir(),
precomposed_utf8_closedir() and precompose_argv(). The first three
are to wrap opendir(3), readdir(3), and closedir(3) functions.
The argv[] conversion allows to use the TAB filename completion done
by the shell on command line. It tolerates other tools which use
readdir() to feed decomposed file names into git.
When creating a new git repository with "git init" or "git clone",
"core.precomposedunicode" will be set "false".
The user needs to activate this feature manually. She typically
sets core.precomposedunicode to "true" on HFS and VFAT, or file
systems mounted via SAMBA.
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-08 15:50:25 +02:00
|
|
|
probe_utf8_pathname_composition(path, len);
|
2007-08-31 09:25:04 +02:00
|
|
|
}
|
|
|
|
|
2006-12-15 06:44:58 +01:00
|
|
|
return reinit;
|
2005-05-30 19:20:44 +02:00
|
|
|
}
|
|
|
|
|
2010-10-04 06:34:27 +02:00
|
|
|
static void create_object_directory(void)
|
|
|
|
{
|
|
|
|
const char *object_directory = get_object_directory();
|
|
|
|
int len = strlen(object_directory);
|
|
|
|
char *path = xmalloc(len + 40);
|
|
|
|
|
|
|
|
memcpy(path, object_directory, len);
|
|
|
|
|
|
|
|
safe_create_dir(object_directory, 1);
|
|
|
|
strcpy(path+len, "/pack");
|
|
|
|
safe_create_dir(path, 1);
|
|
|
|
strcpy(path+len, "/info");
|
|
|
|
safe_create_dir(path, 1);
|
|
|
|
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
2011-03-19 16:16:56 +01:00
|
|
|
int set_git_dir_init(const char *git_dir, const char *real_git_dir,
|
|
|
|
int exist_ok)
|
|
|
|
{
|
|
|
|
if (real_git_dir) {
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (!exist_ok && !stat(git_dir, &st))
|
2011-04-10 21:34:02 +02:00
|
|
|
die(_("%s already exists"), git_dir);
|
2011-03-19 16:16:56 +01:00
|
|
|
|
|
|
|
if (!exist_ok && !stat(real_git_dir, &st))
|
2011-04-10 21:34:02 +02:00
|
|
|
die(_("%s already exists"), real_git_dir);
|
2011-03-19 16:16:56 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure symlinks are resolved because we'll be
|
|
|
|
* moving the target repo later on in separate_git_dir()
|
|
|
|
*/
|
|
|
|
git_link = xstrdup(real_path(git_dir));
|
2014-07-28 20:42:05 +02:00
|
|
|
set_git_dir(real_path(real_git_dir));
|
2011-03-19 16:16:56 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-07-28 20:42:05 +02:00
|
|
|
set_git_dir(real_path(git_dir));
|
2011-03-19 16:16:56 +01:00
|
|
|
git_link = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void separate_git_dir(const char *git_dir)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (!stat(git_link, &st)) {
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
if (S_ISREG(st.st_mode))
|
2011-08-22 23:04:56 +02:00
|
|
|
src = read_gitfile(git_link);
|
2011-03-19 16:16:56 +01:00
|
|
|
else if (S_ISDIR(st.st_mode))
|
|
|
|
src = git_link;
|
|
|
|
else
|
2011-12-21 00:27:41 +01:00
|
|
|
die(_("unable to handle file type %d"), (int)st.st_mode);
|
2011-03-19 16:16:56 +01:00
|
|
|
|
|
|
|
if (rename(src, git_dir))
|
2011-04-10 21:34:02 +02:00
|
|
|
die_errno(_("unable to move %s to %s"), src, git_dir);
|
2011-03-19 16:16:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fp = fopen(git_link, "w");
|
|
|
|
if (!fp)
|
2011-04-10 21:34:02 +02:00
|
|
|
die(_("Could not create git link %s"), git_link);
|
2011-03-19 16:16:56 +01:00
|
|
|
fprintf(fp, "gitdir: %s\n", git_dir);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
int init_db(const char *template_dir, unsigned int flags)
|
|
|
|
{
|
2010-10-04 06:34:27 +02:00
|
|
|
int reinit;
|
2011-03-19 16:16:56 +01:00
|
|
|
const char *git_dir = get_git_dir();
|
2008-04-27 19:39:27 +02:00
|
|
|
|
2011-03-19 16:16:56 +01:00
|
|
|
if (git_link)
|
|
|
|
separate_git_dir(git_dir);
|
2008-04-27 19:39:27 +02:00
|
|
|
|
2011-03-19 16:16:56 +01:00
|
|
|
safe_create_dir(git_dir, 0);
|
2008-04-27 19:39:27 +02:00
|
|
|
|
git init: --bare/--shared overrides system/global config
If core.bare or core.sharedRepository are set in /etc/gitconfig or
~/.gitconfig, then 'git init' will read the values when constructing a
new config file; reading them, however, will override the values
specified on the command line. In the case of --bare, this ends up
causing a segfault, without the repository being properly initialised;
in the case of --shared, the permissions are set according to the
existing config settings, not what was specified on the command line.
This fix saves any specified values for --bare and --shared prior to
reading existing config settings, and restores them after reading but
before writing the new config file. core.bare is ignored in all
situations, while core.sharedRepository will only be used if --shared
is not specified to git init.
Also includes testcases which use a specified global config file
override, demonstrating the former failure scenario.
Signed-off-by: Deskin Miller <deskinm@umich.edu>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-10-07 07:37:48 +02:00
|
|
|
init_is_bare_repository = is_bare_repository();
|
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
/* Check to see if the repository version is right.
|
|
|
|
* Note that a newly created repository does not have
|
|
|
|
* config file, so this will not fail. What we are catching
|
|
|
|
* is an attempt to reinitialize new repository with an old tool.
|
|
|
|
*/
|
|
|
|
check_repository_format();
|
|
|
|
|
|
|
|
reinit = create_default_files(template_dir);
|
|
|
|
|
2010-10-04 06:34:27 +02:00
|
|
|
create_object_directory();
|
2008-04-27 19:39:27 +02:00
|
|
|
|
|
|
|
if (shared_repository) {
|
|
|
|
char buf[10];
|
|
|
|
/* We do not spell "group" and such, so that
|
|
|
|
* the configuration can be read by older version
|
|
|
|
* of git. Note, we use octal numbers for new share modes,
|
|
|
|
* and compatibility values for PERM_GROUP and
|
|
|
|
* PERM_EVERYBODY.
|
|
|
|
*/
|
2009-03-26 00:19:36 +01:00
|
|
|
if (shared_repository < 0)
|
|
|
|
/* force to the mode value */
|
|
|
|
sprintf(buf, "0%o", -shared_repository);
|
|
|
|
else if (shared_repository == PERM_GROUP)
|
2008-04-27 19:39:27 +02:00
|
|
|
sprintf(buf, "%d", OLD_PERM_GROUP);
|
|
|
|
else if (shared_repository == PERM_EVERYBODY)
|
|
|
|
sprintf(buf, "%d", OLD_PERM_EVERYBODY);
|
|
|
|
else
|
2009-03-26 00:19:36 +01:00
|
|
|
die("oops");
|
2008-04-27 19:39:27 +02:00
|
|
|
git_config_set("core.sharedrepository", buf);
|
|
|
|
git_config_set("receive.denyNonFastforwards", "true");
|
|
|
|
}
|
|
|
|
|
2010-02-14 16:44:42 +01:00
|
|
|
if (!(flags & INIT_DB_QUIET)) {
|
|
|
|
int len = strlen(git_dir);
|
2011-02-23 00:41:25 +01:00
|
|
|
|
i18n: only extract comments marked with "TRANSLATORS:"
When extract l10n messages, we use "--add-comments" option to keep
comments right above the l10n messages for references. But sometimes
irrelevant comments are also extracted. For example in the following
code block, the comment in line 2 will be extracted as comment for the
l10n message in line 3, but obviously it's wrong.
{ OPTION_CALLBACK, 0, "ignore-removal", &addremove_explicit,
NULL /* takes no arguments */,
N_("ignore paths removed in the working tree (same as
--no-all)"),
PARSE_OPT_NOARG, ignore_removal_cb },
Since almost all comments for l10n translators are marked with the same
prefix (tag): "TRANSLATORS:", it's safe to only extract comments with
this special tag. I.E. it's better to call xgettext as:
xgettext --add-comments=TRANSLATORS: ...
Also tweaks the multi-line comment in "init-db.c", to make it start with
the proper tag, not "* TRANSLATORS:" (which has a star before the tag).
Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-04-17 07:37:18 +02:00
|
|
|
/* TRANSLATORS: The first '%s' is either "Reinitialized
|
|
|
|
existing" or "Initialized empty", the second " shared" or
|
|
|
|
"", and the last '%s%s' is the verbatim directory name. */
|
2011-02-23 00:41:25 +01:00
|
|
|
printf(_("%s%s Git repository in %s%s\n"),
|
|
|
|
reinit ? _("Reinitialized existing") : _("Initialized empty"),
|
|
|
|
shared_repository ? _(" shared") : "",
|
2010-02-14 16:44:42 +01:00
|
|
|
git_dir, len && git_dir[len-1] != '/' ? "/" : "");
|
|
|
|
}
|
2008-04-27 19:39:27 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int guess_repository_type(const char *git_dir)
|
2007-08-27 09:58:06 +02:00
|
|
|
{
|
|
|
|
const char *slash;
|
2014-07-28 20:30:39 +02:00
|
|
|
char *cwd;
|
|
|
|
int cwd_is_git_dir;
|
2007-08-27 09:58:06 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "GIT_DIR=. git init" is always bare.
|
|
|
|
* "GIT_DIR=`pwd` git init" too.
|
|
|
|
*/
|
|
|
|
if (!strcmp(".", git_dir))
|
2008-04-27 19:39:27 +02:00
|
|
|
return 1;
|
2014-07-28 20:30:39 +02:00
|
|
|
cwd = xgetcwd();
|
|
|
|
cwd_is_git_dir = !strcmp(git_dir, cwd);
|
|
|
|
free(cwd);
|
|
|
|
if (cwd_is_git_dir)
|
2008-04-27 19:39:27 +02:00
|
|
|
return 1;
|
2007-08-27 09:58:06 +02:00
|
|
|
/*
|
|
|
|
* "GIT_DIR=.git or GIT_DIR=something/.git is usually not.
|
|
|
|
*/
|
|
|
|
if (!strcmp(git_dir, ".git"))
|
2008-04-27 19:39:27 +02:00
|
|
|
return 0;
|
2007-08-27 09:58:06 +02:00
|
|
|
slash = strrchr(git_dir, '/');
|
|
|
|
if (slash && !strcmp(slash, "/.git"))
|
2008-04-27 19:39:27 +02:00
|
|
|
return 0;
|
2007-08-27 09:58:06 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise it is often bare. At this point
|
|
|
|
* we are just guessing.
|
|
|
|
*/
|
2008-04-27 19:39:27 +02:00
|
|
|
return 1;
|
2007-08-27 09:58:06 +02:00
|
|
|
}
|
|
|
|
|
2009-07-12 12:24:32 +02:00
|
|
|
static int shared_callback(const struct option *opt, const char *arg, int unset)
|
|
|
|
{
|
|
|
|
*((int *) opt->value) = (arg) ? git_config_perm("arg", arg) : PERM_GROUP;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *const init_db_usage[] = {
|
2015-01-13 08:44:47 +01:00
|
|
|
N_("git init [-q | --quiet] [--bare] [--template=<template-directory>] [--shared[=<permissions>]] [<directory>]"),
|
2009-07-12 12:24:32 +02:00
|
|
|
NULL
|
|
|
|
};
|
2005-08-06 21:50:14 +02:00
|
|
|
|
2005-04-20 06:48:15 +02:00
|
|
|
/*
|
|
|
|
* If you want to, you can share the DB area with any number of branches.
|
|
|
|
* That has advantages: you can save space by sharing all the SHA1 objects.
|
|
|
|
* On the other hand, it might just make lookup slower and messier. You
|
|
|
|
* be the judge. The default case is to have one DB per managed directory.
|
|
|
|
*/
|
2006-07-29 07:44:25 +02:00
|
|
|
int cmd_init_db(int argc, const char **argv, const char *prefix)
|
2005-04-08 00:13:13 +02:00
|
|
|
{
|
2005-05-30 19:20:44 +02:00
|
|
|
const char *git_dir;
|
2011-03-19 16:16:56 +01:00
|
|
|
const char *real_git_dir = NULL;
|
2010-11-26 16:32:40 +01:00
|
|
|
const char *work_tree;
|
2006-05-19 12:03:57 +02:00
|
|
|
const char *template_dir = NULL;
|
2008-04-27 19:39:27 +02:00
|
|
|
unsigned int flags = 0;
|
2009-07-12 12:24:32 +02:00
|
|
|
const struct option init_db_options[] = {
|
2012-08-20 14:32:18 +02:00
|
|
|
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
|
|
|
|
N_("directory from which templates will be used")),
|
2009-07-12 12:24:32 +02:00
|
|
|
OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
|
2012-08-20 14:32:18 +02:00
|
|
|
N_("create a bare repository"), 1),
|
2009-07-12 12:24:32 +02:00
|
|
|
{ OPTION_CALLBACK, 0, "shared", &init_shared_repository,
|
2012-08-20 14:32:18 +02:00
|
|
|
N_("permissions"),
|
|
|
|
N_("specify that the git repository is to be shared amongst several users"),
|
2009-07-12 12:24:32 +02:00
|
|
|
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, shared_callback, 0},
|
2012-08-20 14:32:18 +02:00
|
|
|
OPT_BIT('q', "quiet", &flags, N_("be quiet"), INIT_DB_QUIET),
|
|
|
|
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
|
|
|
|
N_("separate git dir from working tree")),
|
2009-07-12 12:24:32 +02:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
2009-08-05 21:39:33 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
|
|
|
|
|
2011-03-19 16:16:56 +01:00
|
|
|
if (real_git_dir && !is_absolute_path(real_git_dir))
|
|
|
|
real_git_dir = xstrdup(real_path(real_git_dir));
|
|
|
|
|
2009-08-05 21:39:33 +02:00
|
|
|
if (argc == 1) {
|
2009-07-24 23:59:28 +02:00
|
|
|
int mkdir_tried = 0;
|
|
|
|
retry:
|
2009-08-05 21:39:33 +02:00
|
|
|
if (chdir(argv[0]) < 0) {
|
2009-07-24 23:59:28 +02:00
|
|
|
if (!mkdir_tried) {
|
|
|
|
int saved;
|
|
|
|
/*
|
|
|
|
* At this point we haven't read any configuration,
|
|
|
|
* and we know shared_repository should always be 0;
|
|
|
|
* but just in case we play safe.
|
|
|
|
*/
|
|
|
|
saved = shared_repository;
|
|
|
|
shared_repository = 0;
|
2009-08-05 21:39:33 +02:00
|
|
|
switch (safe_create_leading_directories_const(argv[0])) {
|
2014-01-06 14:45:26 +01:00
|
|
|
case SCLD_OK:
|
|
|
|
case SCLD_PERMS:
|
|
|
|
break;
|
2014-01-06 14:45:25 +01:00
|
|
|
case SCLD_EXISTS:
|
2009-07-24 23:59:28 +02:00
|
|
|
errno = EEXIST;
|
|
|
|
/* fallthru */
|
|
|
|
default:
|
2014-01-06 14:45:26 +01:00
|
|
|
die_errno(_("cannot mkdir %s"), argv[0]);
|
2009-07-24 23:59:28 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
shared_repository = saved;
|
2009-08-05 21:39:33 +02:00
|
|
|
if (mkdir(argv[0], 0777) < 0)
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot mkdir %s"), argv[0]);
|
2009-07-24 23:59:28 +02:00
|
|
|
mkdir_tried = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno(_("cannot chdir to %s"), argv[0]);
|
2009-07-24 23:59:28 +02:00
|
|
|
}
|
2009-08-05 21:39:33 +02:00
|
|
|
} else if (0 < argc) {
|
|
|
|
usage(init_db_usage[0]);
|
2005-08-06 21:50:14 +02:00
|
|
|
}
|
2009-08-05 21:39:33 +02:00
|
|
|
if (is_bare_repository_cfg == 1) {
|
2014-07-28 20:31:57 +02:00
|
|
|
char *cwd = xgetcwd();
|
|
|
|
setenv(GIT_DIR_ENVIRONMENT, cwd, argc > 0);
|
|
|
|
free(cwd);
|
2005-08-06 21:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-03-26 00:19:36 +01:00
|
|
|
if (init_shared_repository != -1)
|
|
|
|
shared_repository = init_shared_repository;
|
|
|
|
|
2007-08-27 09:58:06 +02:00
|
|
|
/*
|
|
|
|
* GIT_WORK_TREE makes sense only in conjunction with GIT_DIR
|
|
|
|
* without --bare. Catch the error early.
|
|
|
|
*/
|
|
|
|
git_dir = getenv(GIT_DIR_ENVIRONMENT);
|
2010-11-26 16:32:40 +01:00
|
|
|
work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
|
|
|
|
if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
|
2011-02-23 00:41:24 +01:00
|
|
|
die(_("%s (or --work-tree=<directory>) not allowed without "
|
|
|
|
"specifying %s (or --git-dir=<directory>)"),
|
2007-08-27 09:58:06 +02:00
|
|
|
GIT_WORK_TREE_ENVIRONMENT,
|
|
|
|
GIT_DIR_ENVIRONMENT);
|
|
|
|
|
2005-05-30 19:20:44 +02:00
|
|
|
/*
|
|
|
|
* Set up the default .git directory contents
|
|
|
|
*/
|
2006-12-15 06:44:58 +01:00
|
|
|
if (!git_dir)
|
2005-05-30 19:20:44 +02:00
|
|
|
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
|
2005-12-22 23:19:37 +01:00
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
if (is_bare_repository_cfg < 0)
|
|
|
|
is_bare_repository_cfg = guess_repository_type(git_dir);
|
|
|
|
|
|
|
|
if (!is_bare_repository_cfg) {
|
2011-03-03 13:34:51 +01:00
|
|
|
const char *git_dir_parent = strrchr(git_dir, '/');
|
|
|
|
if (git_dir_parent) {
|
|
|
|
char *rel = xstrndup(git_dir, git_dir_parent - git_dir);
|
2011-03-17 12:26:46 +01:00
|
|
|
git_work_tree_cfg = xstrdup(real_path(rel));
|
2011-03-03 13:34:51 +01:00
|
|
|
free(rel);
|
2008-04-27 19:39:27 +02:00
|
|
|
}
|
2014-07-28 20:30:39 +02:00
|
|
|
if (!git_work_tree_cfg)
|
|
|
|
git_work_tree_cfg = xgetcwd();
|
2010-11-26 16:32:40 +01:00
|
|
|
if (work_tree)
|
2014-07-28 20:42:05 +02:00
|
|
|
set_git_work_tree(work_tree);
|
2010-11-26 16:32:40 +01:00
|
|
|
else
|
|
|
|
set_git_work_tree(git_work_tree_cfg);
|
2008-04-27 19:39:27 +02:00
|
|
|
if (access(get_git_work_tree(), X_OK))
|
2011-02-23 00:41:24 +01:00
|
|
|
die_errno (_("Cannot access work tree '%s'"),
|
2009-06-27 17:58:47 +02:00
|
|
|
get_git_work_tree());
|
2006-06-10 08:09:49 +02:00
|
|
|
}
|
2010-11-26 16:32:40 +01:00
|
|
|
else {
|
|
|
|
if (work_tree)
|
2014-07-28 20:42:05 +02:00
|
|
|
set_git_work_tree(work_tree);
|
2010-11-26 16:32:40 +01:00
|
|
|
}
|
2005-12-22 23:19:37 +01:00
|
|
|
|
2011-03-19 16:16:56 +01:00
|
|
|
set_git_dir_init(git_dir, real_git_dir, 1);
|
2006-12-15 06:44:58 +01:00
|
|
|
|
2008-04-27 19:39:27 +02:00
|
|
|
return init_db(template_dir, flags);
|
2005-04-08 00:13:13 +02:00
|
|
|
}
|