From 4a4aee1112d9b73303ede92c3b9ca54aaf2e7a3e Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Sat, 12 Jan 2013 18:44:50 +0100 Subject: [PATCH 1/5] Added flag GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE to test_repo_init__extended_with_template(). Otherwise the template functionallity is not tested (as a TODO we also shall test that the specified template really got copied). --- tests-clar/repo/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index c0acbed5a..09b25c13a 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -367,7 +367,7 @@ void test_repo_init__extended_with_template(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; - opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE; + opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = cl_fixture("template"); cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); From b7b1acfdbdd2e9dc2abacfa97679180f4c07b0c1 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Sat, 12 Jan 2013 20:02:00 +0100 Subject: [PATCH 2/5] Clear local error variable after invoking giterr_clear(). --- src/repository.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/repository.c b/src/repository.c index 46b7f8f48..2c567c892 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1015,6 +1015,7 @@ static int repo_init_structure( /* if template was default, ignore error and use internal */ giterr_clear(); external_tpl = false; + error = 0; } } From 85f40312765f7d8df8d28a7dd61d7d5107071eeb Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Sun, 13 Jan 2013 11:30:05 +0100 Subject: [PATCH 3/5] Do not use GIT_CPDIR_CHMOD flag when copying the template. This is an intermin solution. While this essentially disables the --shared flag feature, previously external templates did not work at all. This change fixes the previously corrected, and since then failing, repo_init__extended_with_template() test. The problem is now documented in the source code comments. --- src/repository.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/repository.c b/src/repository.c index 2c567c892..014b40aff 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1005,8 +1005,17 @@ static int repo_init_structure( tdir = GIT_TEMPLATE_DIR; } + /* FIXME: GIT_CPDIR_CHMOD cannot applied here as an attempt + * would be made to chmod() all directories up to the last + * component of repo_dir, e.g., also /home etc. Recall that + * repo_dir is prettified at this point. + * + * Best probably would be to have the same logic as in + * git_futils_mkdir(), i.e., to separate the base from + * the path. + */ error = git_futils_cp_r(tdir, repo_dir, - GIT_CPDIR_COPY_SYMLINKS | GIT_CPDIR_CHMOD, dmode); + GIT_CPDIR_COPY_SYMLINKS /*| GIT_CPDIR_CHMOD*/, dmode); if (error < 0) { if (strcmp(tdir, GIT_TEMPLATE_DIR) != 0) From 5885ba112dd51c6446e500f72f92aebe5b872983 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Sun, 13 Jan 2013 12:23:30 +0100 Subject: [PATCH 4/5] Now checks in the template test whether the description file has been properly copied. This is a minimal effort to test whether the template really has been used when creating an repo with external templates. --- tests-clar/repo/init.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index 09b25c13a..9ddb39545 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -365,6 +365,9 @@ void test_repo_init__extended_1(void) void test_repo_init__extended_with_template(void) { + git_buf expected = GIT_BUF_INIT; + git_buf actual = GIT_BUF_INIT; + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; @@ -375,6 +378,14 @@ void test_repo_init__extended_with_template(void) cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); + cl_assert(git_futils_readbuffer(&expected,cl_fixture("template/description")) == GIT_OK); + cl_assert(git_futils_readbuffer(&actual,"templated.git/description") == GIT_OK); + + cl_assert(!git_buf_cmp(&expected,&actual)); + + git_buf_free(&expected); + git_buf_free(&actual); + cleanup_repository("templated.git"); } From 72719e733318df8418641abb3c3d67d7a9ef42fc Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Sun, 13 Jan 2013 12:21:52 +0100 Subject: [PATCH 5/5] Altered the description of the template. Before, it was identical to the default template making it difficult to check, if the proper template was copied an external template test. --- tests-clar/resources/template/description | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests-clar/resources/template/description b/tests-clar/resources/template/description index 498b267a8..ff04c4c13 100644 --- a/tests-clar/resources/template/description +++ b/tests-clar/resources/template/description @@ -1 +1 @@ -Unnamed repository; edit this file 'description' to name the repository. +Edit this file 'description' to name the repository.