Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-28 13:28:57 +0400
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-28 17:40:47 +0400
commit2614819cf3e2163fb831c12c6d793254c78adb3d (patch)
tree365e649c4468d5d1db64e0937e68be86a37f5089 /tests/clone
parent94f742bac60656f4f915711b953814477633b984 (diff)
clone: allow for linking in local clone
If requested, git_clone_local_into() will try to link the object files instead of copying them. This only works on non-Windows (since it doesn't have this) when both are on the same filesystem (which are unix semantics).
Diffstat (limited to 'tests/clone')
-rw-r--r--tests/clone/local.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/clone/local.c b/tests/clone/local.c
index 7b273b23a..289c50aaf 100644
--- a/tests/clone/local.c
+++ b/tests/clone/local.c
@@ -3,6 +3,8 @@
#include "git2/clone.h"
#include "clone.h"
#include "buffer.h"
+#include "path.h"
+#include "posix.h"
void assert_clone(const char *path, git_clone_local_t opt, int val)
{
@@ -29,3 +31,60 @@ void test_clone_local__should_clone_local(void)
cl_assert_equal_i(true, git_clone__should_clone_local(path, GIT_CLONE_LOCAL_NO_LINKS));
cl_assert_equal_i(false, git_clone__should_clone_local(path, GIT_CLONE_NO_LOCAL));
}
+
+void test_clone_local__hardlinks(void)
+{
+ git_repository *repo;
+ git_remote *remote;
+ git_signature *sig;
+ git_buf buf = GIT_BUF_INIT;
+ struct stat st;
+
+ cl_git_pass(git_repository_init(&repo, "./clone.git", true));
+ cl_git_pass(git_remote_create(&remote, repo, "origin", cl_fixture("testrepo.git")));
+ cl_git_pass(git_signature_now(&sig, "foo", "bar"));
+ cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, true, sig));
+
+ git_remote_free(remote);
+ git_repository_free(repo);
+
+ /*
+ * We can't rely on the link option taking effect in the first
+ * clone, since the temp dir and fixtures dir may reside on
+ * different filesystems. We perform the second clone
+ * side-by-side to make sure this is the case.
+ */
+
+ cl_git_pass(git_repository_init(&repo, "./clone2.git", true));
+ cl_git_pass(git_buf_puts(&buf, cl_git_path_url("clone.git")));
+ cl_git_pass(git_remote_create(&remote, repo, "origin", buf.ptr));
+ cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, true, sig));
+
+#ifndef GIT_WIN32
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ cl_git_pass(p_stat(buf.ptr, &st));
+ cl_assert(st.st_nlink > 1);
+#endif
+
+ git_remote_free(remote);
+ git_repository_free(repo);
+ git_buf_clear(&buf);
+
+ cl_git_pass(git_repository_init(&repo, "./clone3.git", true));
+ cl_git_pass(git_buf_puts(&buf, cl_git_path_url("clone.git")));
+ cl_git_pass(git_remote_create(&remote, repo, "origin", buf.ptr));
+ cl_git_pass(git_clone_local_into(repo, remote, NULL, NULL, false, sig));
+
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_join_n(&buf, '/', 4, git_repository_path(repo), "objects", "08", "b041783f40edfe12bb406c9c9a8a040177c125"));
+
+ cl_git_pass(p_stat(buf.ptr, &st));
+ cl_assert_equal_i(1, st.st_nlink);
+
+ git_buf_free(&buf);
+ git_signature_free(sig);
+ git_remote_free(remote);
+ git_repository_free(repo);
+}