From b953c77a5b55ff3b453c3500fbb42d97950fd8b4 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 19 Apr 2007 18:34:03 +0200 Subject: [PATCH] Allow a relative builtin template directory. In order to make git relocatable (i.e. not have the prefix compiled-in) the template directory must depend on the location where this git instance is found, which is GIT_EXEC_DIR. The exec path is prepended only to the compiled-in default directory if it is relative. Any relative directories that are specified via environment variable or the --exec-dir switch are taken as is. Signed-off-by: Johannes Sixt --- builtin-init-db.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 4df9fd0fad..ecf3db954a 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -130,10 +130,19 @@ static void copy_templates(const char *git_dir, int len, const char *template_di int template_len; DIR *dir; - if (!template_dir) { + if (!template_dir) template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT); - if (!template_dir) - template_dir = DEFAULT_GIT_TEMPLATE_DIR; + if (!template_dir) { + /* + * if the hard-coded template is relative, it is + * interpreted relative to the exec_dir + */ + template_dir = DEFAULT_GIT_TEMPLATE_DIR; + if (template_dir[0] != '/' && template_dir[1] != ':') { + const char *exec_path = git_exec_path(); + template_dir = prefix_path(exec_path, strlen(exec_path), + template_dir); + } } strcpy(template_path, template_dir); template_len = strlen(template_path); -- 2.11.4.GIT