]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-init-db.c
prefix_path: use is_absolute_path() instead of *orig == '/'
[git.git] / builtin-init-db.c
index af15cb27392dae6b16cee960908295ac252fe920..5d7cdda93314b1d40f5f512897e8a35af0480a8f 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include "cache.h"
 #include "builtin.h"
+#include "exec_cmd.h"
 
 #ifndef DEFAULT_GIT_TEMPLATE_DIR
 #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -131,10 +132,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 (!is_absolute_path(template_dir)) {
+                       struct strbuf d = STRBUF_INIT;
+                       strbuf_addf(&d, "%s/%s", git_exec_path(), template_dir);
+                       template_dir = strbuf_detach(&d, NULL);
+               }
        }
        strcpy(template_path, template_dir);
        template_len = strlen(template_path);
@@ -264,6 +274,21 @@ static int create_default_files(const char *git_dir, const char *template_path)
                if (work_tree != git_work_tree_cfg)
                        git_config_set("core.worktree", work_tree);
        }
+
+       /* Check if symlink is supported in the work tree */
+       if (!reinit) {
+               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");
+       }
+
        return reinit;
 }