]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'nd/init-relative-template-fix'
authorJunio C Hamano <gitster@pobox.com>
Thu, 13 Jun 2019 20:18:46 +0000 (13:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 13 Jun 2019 20:18:46 +0000 (13:18 -0700)
A relative pathname given to "git init --template=<path> <repo>"
ought to be relative to the directory "git init" gets invoked in,
but it instead was made relative to the repository, which has been
corrected.

* nd/init-relative-template-fix:
  init: make --template path relative to $CWD

1  2 
builtin/init-db.c
t/t0001-init.sh

diff --combined builtin/init-db.c
index 6ca002893f47516ee8963db09d60b3716b60a205,6b72a9bb090a8b16d96d82b770740ed55a932f93..944ec77fe1032775ff595f0b1eb99a1fb22d059f
@@@ -96,7 -96,7 +96,7 @@@ static void copy_templates(const char *
        struct strbuf path = STRBUF_INIT;
        struct strbuf template_path = STRBUF_INIT;
        size_t template_len;
 -      struct repository_format template_format;
 +      struct repository_format template_format = REPOSITORY_FORMAT_INIT;
        struct strbuf err = STRBUF_INIT;
        DIR *dir;
        char *to_free = NULL;
@@@ -148,7 -148,6 +148,7 @@@ free_return
        free(to_free);
        strbuf_release(&path);
        strbuf_release(&template_path);
 +      clear_repository_format(&template_format);
  }
  
  static int git_init_db_config(const char *k, const char *v, void *cb)
        if (!strcmp(k, "init.templatedir"))
                return git_config_pathname(&init_db_template_dir, k, v);
  
 +      if (starts_with(k, "core."))
 +              return platform_core_config(k, v, cb);
 +
        return 0;
  }
  
@@@ -189,7 -185,6 +189,7 @@@ static int create_default_files(const c
        struct strbuf err = STRBUF_INIT;
  
        /* Just look for `init.templatedir` */
 +      init_db_template_dir = NULL; /* re-set in case it was set before */
        git_config(git_init_db_config, NULL);
  
        /*
@@@ -366,9 -361,6 +366,9 @@@ int init_db(const char *git_dir, const 
        }
        startup_info->have_repository = 1;
  
 +      /* Just look for `core.hidedotfiles` */
 +      git_config(git_init_db_config, NULL);
 +
        safe_create_dir(git_dir, 0);
  
        init_is_bare_repository = is_bare_repository();
@@@ -502,6 -494,9 +502,9 @@@ int cmd_init_db(int argc, const char **
        if (real_git_dir && !is_absolute_path(real_git_dir))
                real_git_dir = real_pathdup(real_git_dir, 1);
  
+       if (template_dir && *template_dir && !is_absolute_path(template_dir))
+               template_dir = absolute_pathdup(template_dir);
        if (argc == 1) {
                int mkdir_tried = 0;
        retry:
diff --combined t/t0001-init.sh
index 77a224aafb8c63a237f868bff23e6d3cd418bb44,802edb6c8fd06cb557769aa6d801fabc0477aef3..0276d14a0ba66d4af6ad7af14c6b7e98305a1b84
@@@ -93,7 -93,6 +93,7 @@@ test_expect_success 'No extra GIT_* on 
                sed -n \
                        -e "/^GIT_PREFIX=/d" \
                        -e "/^GIT_TEXTDOMAINDIR=/d" \
 +                      -e "/^GIT_TRACE2_PARENT/d" \
                        -e "/^GIT_/s/=.*//p" |
                sort
        EOF
@@@ -175,7 -174,7 +175,7 @@@ test_expect_success 'reinit' 
  test_expect_success 'init with --template' '
        mkdir template-source &&
        echo content >template-source/file &&
-       git init --template=../template-source template-custom &&
+       git init --template=template-source template-custom &&
        test_cmp template-source/file template-custom/.git/file
  '
  
@@@ -454,17 -453,6 +454,17 @@@ test_expect_success 're-init from a lin
        )
  '
  
 +test_expect_success MINGW 'core.hidedotfiles = false' '
 +      git config --global core.hidedotfiles false &&
 +      rm -rf newdir &&
 +      mkdir newdir &&
 +      (
 +              sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG &&
 +              git -C newdir init
 +      ) &&
 +      ! is_hidden newdir/.git
 +'
 +
  test_expect_success MINGW 'redirect std handles' '
        GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir &&
        test .git = "$(cat output.txt)" &&