summaryrefslogtreecommitdiff
path: root/tests/repo
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-26 15:33:58 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-27 04:36:47 +0000
commit4196dd8e8fceaaa42ad5854e1ce362c14b8c0bf6 (patch)
treef1d129bbed51fc1fcafa7ea7bda92749404cb4fc /tests/repo
parentc92987d1575b93eac3b6fa4d1b4bc166137305ac (diff)
downloadlibgit2-4196dd8e8fceaaa42ad5854e1ce362c14b8c0bf6.tar.gz
repository: Introduce "reserved names"
A repository can have multiple "reserved names" now, not just a single "short name" for the repository folder itself. Refactor to include a git_repository__reserved_names that returns all the reserved names for a repository.
Diffstat (limited to 'tests/repo')
-rw-r--r--tests/repo/reservedname.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/repo/reservedname.c b/tests/repo/reservedname.c
new file mode 100644
index 000000000..faea0cc2b
--- /dev/null
+++ b/tests/repo/reservedname.c
@@ -0,0 +1,108 @@
+#include "clar_libgit2.h"
+#include "../submodule/submodule_helpers.h"
+#include "repository.h"
+
+void test_repo_reservedname__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_repo_reservedname__includes_shortname_on_win32(void)
+{
+ git_repository *repo;
+ git_buf *reserved;
+ size_t reserved_len;
+
+ repo = cl_git_sandbox_init("nasty");
+ cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, false));
+
+#ifdef GIT_WIN32
+ cl_assert_equal_i(2, reserved_len);
+ cl_assert_equal_s(".git", reserved[0].ptr);
+ cl_assert_equal_s("GIT~1", reserved[1].ptr);
+#else
+ cl_assert_equal_i(1, reserved_len);
+ cl_assert_equal_s(".git", reserved[0].ptr);
+#endif
+}
+
+void test_repo_reservedname__includes_shortname_when_requested(void)
+{
+ git_repository *repo;
+ git_buf *reserved;
+ size_t reserved_len;
+
+ repo = cl_git_sandbox_init("nasty");
+ cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
+
+ cl_assert_equal_i(2, reserved_len);
+ cl_assert_equal_s(".git", reserved[0].ptr);
+ cl_assert_equal_s("GIT~1", reserved[1].ptr);
+}
+
+/* Ensures that custom shortnames are included: creates a GIT~1 so that the
+ * .git folder itself will have to be named GIT~2
+ */
+void test_repo_reservedname__custom_shortname_recognized(void)
+{
+#ifdef GIT_WIN32
+ git_repository *repo;
+ git_buf *reserved;
+ size_t reserved_len;
+
+ if (!cl_sandbox_supports_8dot3())
+ clar__skip();
+
+ repo = cl_git_sandbox_init("nasty");
+
+ cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
+ cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
+ cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
+
+ cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
+
+ cl_assert_equal_i(3, reserved_len);
+ cl_assert_equal_s(".git", reserved[0].ptr);
+ cl_assert_equal_s("GIT~1", reserved[1].ptr);
+ cl_assert_equal_s("GIT~2", reserved[2].ptr);
+#endif
+}
+
+/* When looking at the short name for a submodule, we need to prevent
+ * people from overwriting the `.git` file in the submodule working
+ * directory itself. We don't want to look at the actual repository
+ * path, since it will be in the super's repository above us, and
+ * typically named with the name of our subrepository. Consequently,
+ * preventing access to the short name of the actual repository path
+ * would prevent us from creating files with the same name as the
+ * subrepo. (Eg, a submodule named "libgit2" could not contain a file
+ * named "libgit2", which would be unfortunate.)
+ */
+void test_repo_reservedname__submodule_pointer(void)
+{
+#ifdef GIT_WIN32
+ git_repository *super_repo, *sub_repo;
+ git_submodule *sub;
+ git_buf *sub_reserved;
+ size_t sub_reserved_len;
+
+ if (!cl_sandbox_supports_8dot3())
+ clar__skip();
+
+ super_repo = setup_fixture_submod2();
+
+ assert_submodule_exists(super_repo, "sm_unchanged");
+
+ cl_git_pass(git_submodule_lookup(&sub, super_repo, "sm_unchanged"));
+ cl_git_pass(git_submodule_open(&sub_repo, sub));
+
+ cl_assert(git_repository__reserved_names(&sub_reserved, &sub_reserved_len, sub_repo, true));
+
+ cl_assert_equal_i(2, sub_reserved_len);
+ cl_assert_equal_s(".git", sub_reserved[0].ptr);
+ cl_assert_equal_s("GIT~1", sub_reserved[1].ptr);
+
+ git_submodule_free(sub);
+ git_repository_free(sub_repo);
+#endif
+}