summaryrefslogtreecommitdiff
path: root/builtin/init-db.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2014-07-28 20:31:57 +0200
committerJunio C Hamano <gitster@pobox.com>2014-08-26 11:06:06 -0700
commit4d3ab44d26c47d100cec39d0ef9ed9746eb7e454 (patch)
tree8ef114ab2ed8e2667fa12124b18f34df5922c3f3 /builtin/init-db.c
parent56b9f6e738af6f5238f57a29e96103cf61e3f8cd (diff)
downloadgit-4d3ab44d26c47d100cec39d0ef9ed9746eb7e454.tar.gz
use xgetcwd() to set $GIT_DIR
Instead of dying of a segmentation fault if getcwd() returns NULL, use xgetcwd() to make sure to write a useful error message and then exit in an orderly fashion. Suggested-by: Jeff King <peff@peff.net> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/init-db.c')
-rw-r--r--builtin/init-db.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c
index f6dd1727ec..ab0ea02d25 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -537,10 +537,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
usage(init_db_usage[0]);
}
if (is_bare_repository_cfg == 1) {
- static char git_dir[PATH_MAX+1];
-
- setenv(GIT_DIR_ENVIRONMENT,
- getcwd(git_dir, sizeof(git_dir)), argc > 0);
+ char *cwd = xgetcwd();
+ setenv(GIT_DIR_ENVIRONMENT, cwd, argc > 0);
+ free(cwd);
}
if (init_shared_repository != -1)