path: root/environment.c
diff options
authorJeff King <>2018-03-30 18:34:46 (GMT)
committerJunio C Hamano <>2018-03-30 19:49:57 (GMT)
commit48988c4d0c35b5c569a2645b61c9346f6062021d (patch)
treeef588c2b3f8f787ab317f157d30dc9f30e18eec7 /environment.c
parentc2a499e6c31ed613a606ffdeb5bb74ab41e9a586 (diff)
set_git_dir: die when setenv() fails
The set_git_dir() function returns an error if setenv() fails, but there are zero callers who pay attention to this return value. If this ever were to happen, it could cause confusing results, as sub-processes would see a potentially stale GIT_DIR (e.g., if it is relative and we chdir()-ed to the root of the working tree). We _could_ try to fix each caller, but there's really nothing useful to do after this failure except die. Let's just lump setenv() failure into the same category as malloc failure: things that should never happen and cause us to abort catastrophically. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'environment.c')
1 files changed, 2 insertions, 3 deletions
diff --git a/environment.c b/environment.c
index d6dd646..e01acf8 100644
--- a/environment.c
+++ b/environment.c
@@ -296,13 +296,12 @@ char *get_graft_file(void)
return the_repository->graft_file;
-int set_git_dir(const char *path)
+void set_git_dir(const char *path)
if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
- return error("Could not set GIT_DIR to '%s'", path);
+ die("could not set GIT_DIR to '%s'", path);
repo_set_gitdir(the_repository, path);
- return 0;
const char *get_log_output_encoding(void)