Commit 63af449e by Edward Thomson

Merge pull request #3030 from linquize/symlink_supported

If work_dir is not specified, use repo_dir to test if symlink is supported
parents 8932c32c 7c2a2172
...@@ -1608,6 +1608,7 @@ int git_repository_init_ext( ...@@ -1608,6 +1608,7 @@ int git_repository_init_ext(
{ {
int error; int error;
git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT; git_buf repo_path = GIT_BUF_INIT, wd_path = GIT_BUF_INIT;
const char *wd;
assert(out && given_repo && opts); assert(out && given_repo && opts);
...@@ -1617,6 +1618,7 @@ int git_repository_init_ext( ...@@ -1617,6 +1618,7 @@ int git_repository_init_ext(
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_buf_cstr(&wd_path);
if (valid_repository_path(&repo_path)) { if (valid_repository_path(&repo_path)) {
if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) { if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) {
...@@ -1629,15 +1631,15 @@ int git_repository_init_ext( ...@@ -1629,15 +1631,15 @@ int git_repository_init_ext(
opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT; opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
error = repo_init_config( error = repo_init_config(
repo_path.ptr, wd_path.ptr, opts->flags, opts->mode); repo_path.ptr, wd, opts->flags, opts->mode);
/* TODO: reinitialize the templates */ /* TODO: reinitialize the templates */
} }
else { else {
if (!(error = repo_init_structure( if (!(error = repo_init_structure(
repo_path.ptr, wd_path.ptr, opts)) && repo_path.ptr, wd, opts)) &&
!(error = repo_init_config( !(error = repo_init_config(
repo_path.ptr, wd_path.ptr, opts->flags, opts->mode))) repo_path.ptr, wd, opts->flags, opts->mode)))
error = repo_init_create_head( error = repo_init_create_head(
repo_path.ptr, opts->initial_head); repo_path.ptr, opts->initial_head);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "git2/checkout.h" #include "git2/checkout.h"
#include "fileops.h" #include "fileops.h"
#include "repository.h" #include "repository.h"
#include "remote.h"
static git_repository *g_repo; static git_repository *g_repo;
...@@ -135,6 +136,52 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void) ...@@ -135,6 +136,52 @@ void test_checkout_index__honor_coreautocrlf_setting_set_to_true(void)
#endif #endif
} }
void test_checkout_index__honor_coresymlinks_default(void)
{
git_repository *repo;
git_remote *origin;
git_object *target;
char cwd[GIT_PATH_MAX];
const char *url = git_repository_path(g_repo);
getcwd(cwd, sizeof(cwd));
cl_assert_equal_i(0, p_mkdir("readonly", 0555)); // Read-only directory
cl_assert_equal_i(0, chdir("readonly"));
cl_git_pass(git_repository_init(&repo, "../symlink.git", true));
cl_assert_equal_i(0, chdir(cwd));
cl_assert_equal_i(0, p_mkdir("symlink", 0777));
cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));
cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH));
cl_git_pass(git_remote_download(origin, NULL));
cl_git_pass(git_remote_update_tips(origin, NULL));
git_remote_free(origin);
cl_git_pass(git_revparse_single(&target, repo, "remotes/origin/master"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
git_object_free(target);
git_repository_free(repo);
#ifdef GIT_WIN32
check_file_contents("./symlink/link_to_new.txt", "new.txt");
#else
{
char link_data[1024];
size_t link_size = 1024;
link_size = p_readlink("./symlink/link_to_new.txt", link_data, link_size);
link_data[link_size] = '\0';
cl_assert_equal_i(link_size, strlen("new.txt"));
cl_assert_equal_s(link_data, "new.txt");
check_file_contents("./symlink/link_to_new.txt", "my new file\n");
}
#endif
cl_fixture_cleanup("symlink");
}
void test_checkout_index__honor_coresymlinks_setting_set_to_true(void) void test_checkout_index__honor_coresymlinks_setting_set_to_true(void)
{ {
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment