diff options
Diffstat (limited to 'builtin-init-db.c')
-rw-r--r-- | builtin-init-db.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/builtin-init-db.c b/builtin-init-db.c index 4df9fd0fad..0d9b1e0559 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -7,7 +7,7 @@ #include "builtin.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR -#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates/" +#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates" #endif #ifdef NO_TRUSTABLE_FILEMODE @@ -40,7 +40,8 @@ static int copy_file(const char *dst, const char *src, int mode) return fdo; } status = copy_fd(fdi, fdo); - close(fdo); + if (close(fdo) != 0) + return error("%s: write error: %s", dst, strerror(errno)); if (!status && adjust_shared_perm(dst)) return -1; @@ -252,20 +253,22 @@ static int create_default_files(const char *git_dir, const char *template_path) } git_config_set("core.filemode", filemode ? "true" : "false"); - if (is_bare_repository()) { + if (is_bare_repository()) git_config_set("core.bare", "true"); - } else { + const char *work_tree = get_git_work_tree(); git_config_set("core.bare", "false"); /* allow template config file to override the default */ if (log_all_ref_updates == -1) git_config_set("core.logallrefupdates", "true"); + if (work_tree != git_work_tree_cfg) + git_config_set("core.worktree", work_tree); } return reinit; } static const char init_db_usage[] = -"git-init [--template=<template-directory>] [--shared]"; +"git-init [-q | --quiet] [--template=<template-directory>] [--shared]"; /* * If you want to, you can share the DB area with any number of branches. @@ -280,6 +283,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) const char *template_dir = NULL; char *path; int len, i, reinit; + int quiet = 0; for (i = 1; i < argc; i++, argv++) { const char *arg = argv[1]; @@ -289,10 +293,18 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) shared_repository = PERM_GROUP; else if (!prefixcmp(arg, "--shared=")) shared_repository = git_config_perm("arg", arg+9); + else if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) + quiet = 1; else usage(init_db_usage); } + git_work_tree_cfg = xcalloc(PATH_MAX, 1); + if (!getcwd(git_work_tree_cfg, PATH_MAX)) + die ("Cannot access current working directory."); + if (access(get_git_work_tree(), X_OK)) + die ("Cannot access work tree '%s'", get_git_work_tree()); + /* * Set up the default .git directory contents */ @@ -335,10 +347,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) git_config_set("receive.denyNonFastforwards", "true"); } - printf("%s%s Git repository in %s/\n", - reinit ? "Reinitialized existing" : "Initialized empty", - shared_repository ? " shared" : "", - git_dir); + if (!quiet) + printf("%s%s Git repository in %s/\n", + reinit ? "Reinitialized existing" : "Initialized empty", + shared_repository ? " shared" : "", + git_dir); return 0; } |