Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6260254

Browse files
committed
git_repository_init: include dotfiles when copying templates
Include dotfiles when copying template directory, which will handle both a template directory itself that begins with a dotfile, and any dotfiles inside the directory.
1 parent 0028218 commit 6260254

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/repository.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,9 @@ static int repo_init_structure(
14381438
}
14391439

14401440
if (tdir) {
1441-
uint32_t cpflags = GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_SIMPLE_TO_MODE;
1441+
uint32_t cpflags = GIT_CPDIR_COPY_SYMLINKS |
1442+
GIT_CPDIR_SIMPLE_TO_MODE |
1443+
GIT_CPDIR_COPY_DOTFILES;
14421444
if (opts->mode != GIT_REPOSITORY_INIT_SHARED_UMASK)
14431445
cpflags |= GIT_CPDIR_CHMOD_DIRS;
14441446
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);

tests/repo/init.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ static void assert_mode_seems_okay(
519519

520520
static const char *template_sandbox(const char *name)
521521
{
522-
git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT;
522+
git_buf hooks_path = GIT_BUF_INIT, link_path = GIT_BUF_INIT,
523+
dotfile_path = GIT_BUF_INIT;
523524
const char *path = cl_fixture(name);
524525

525526
cl_fixture_sandbox(name);
@@ -537,6 +538,12 @@ static const char *template_sandbox(const char *name)
537538
cl_must_pass(symlink("update.sample", link_path.ptr));
538539
#endif
539540

541+
/* create a file starting with a dot */
542+
cl_git_pass(git_buf_joinpath(&dotfile_path, hooks_path.ptr, ".dotfile"));
543+
cl_git_mkfile(dotfile_path.ptr, "something\n");
544+
git_buf_free(&dotfile_path);
545+
546+
git_buf_free(&dotfile_path);
540547
git_buf_free(&link_path);
541548
git_buf_free(&hooks_path);
542549

@@ -595,6 +602,10 @@ static void validate_templates(git_repository *repo, const char *template_path)
595602
template_path, git_repository_path(repo),
596603
"hooks/link.sample", filemode);
597604

605+
assert_hooks_match(
606+
template_path, git_repository_path(repo),
607+
"hooks/.dotfile", filemode);
608+
598609
git_buf_free(&expected);
599610
git_buf_free(&actual);
600611
git_buf_free(&repo_description);

0 commit comments

Comments
 (0)