mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
win32: tests around handling forbidden paths
Introduce a repository that contains some paths that were illegal on PC-DOS circa 1981 (like `aux`, `con`, `com1`) and that in a bizarre fit of retrocomputing, remain illegal on some "modern" computers, despite being "new technology". Introduce some aspirational tests that suggest that we should be able to cope with trees and indexes that contain paths that would be illegal on the filesystem, so that we can at least diff them. Further ensure that checkout will not write a repository with forbidden paths.
This commit is contained in:
1
tests/resources/win32-forbidden/.gitted/HEAD
Normal file
1
tests/resources/win32-forbidden/.gitted/HEAD
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
7
tests/resources/win32-forbidden/.gitted/config
Normal file
7
tests/resources/win32-forbidden/.gitted/config
Normal file
@@ -0,0 +1,7 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
BIN
tests/resources/win32-forbidden/.gitted/index
Normal file
BIN
tests/resources/win32-forbidden/.gitted/index
Normal file
Binary file not shown.
6
tests/resources/win32-forbidden/.gitted/info/exclude
Normal file
6
tests/resources/win32-forbidden/.gitted/info/exclude
Normal file
@@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
x•<>Í
|
||||
!…[ûw„ãï†hÓ¢}/à8šB*8N½~½@guÎÇÕœS‡ Í¡7ïa¢
|
||||
©fš2ËÐ"s
e.È%ŒÁQ —ŠØ½ÇÚ຾m[ákÞj<C39E>Ùúm—Gêq_N®æ3LBJÅ”FG:B¯Ýÿ㮄ùùäVROö ͿҖj!èÖ=ö
|
||||
@@ -0,0 +1,2 @@
|
||||
xÁA
|
||||
€ ÐÖ<C390>â/kÓ.ð ]`„™¾ŽhÞ¾÷"=âË•ò€e*’¨·UŠÂ+¶äMí%çý´O4ÊcÞ˱þá<C3BE>–
|
||||
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
x<01><>M
|
||||
B!F»Š;BoW}BD“ÍÛ€¥<7F>
|
||||
>_m?ÛBgôqàãøVJ ³=FÀ ‰¤ÕdJTæqD<71>dBá<42>æNå¼'Îì6Rëp
ÛÜS+k«pŠÓþÖå™GÚÜÁ·rAR*Tz!Øó ›vVGü÷Ïn5<6E>l_Ðã;¯¹Uö>H
|
||||
@@ -0,0 +1 @@
|
||||
3496991d72d500af36edef68bbfcccd1661d88db
|
||||
183
tests/win32/forbidden.c
Normal file
183
tests/win32/forbidden.c
Normal file
@@ -0,0 +1,183 @@
|
||||
#include "clar_libgit2.h"
|
||||
|
||||
#include "repository.h"
|
||||
#include "buffer.h"
|
||||
#include "submodule.h"
|
||||
|
||||
static const char *repo_name = "win32-forbidden";
|
||||
static git_repository *repo;
|
||||
|
||||
void test_win32_forbidden__initialize(void)
|
||||
{
|
||||
repo = cl_git_sandbox_init(repo_name);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__cleanup(void)
|
||||
{
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_open_index(void)
|
||||
{
|
||||
git_index *index;
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
cl_assert_equal_i(7, git_index_entrycount(index));
|
||||
|
||||
/* ensure we can even write the unmodified index */
|
||||
cl_git_pass(git_index_write(index));
|
||||
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_add_forbidden_filename_with_entry(void)
|
||||
{
|
||||
git_index *index;
|
||||
git_index_entry entry = {{0}};
|
||||
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
|
||||
entry.path = "aux";
|
||||
entry.mode = GIT_FILEMODE_BLOB;
|
||||
git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37");
|
||||
|
||||
cl_git_pass(git_index_add(index, &entry));
|
||||
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__cannot_add_dot_git_even_with_entry(void)
|
||||
{
|
||||
git_index *index;
|
||||
git_index_entry entry = {{0}};
|
||||
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
|
||||
entry.path = "foo/.git";
|
||||
entry.mode = GIT_FILEMODE_BLOB;
|
||||
git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37");
|
||||
|
||||
cl_git_fail(git_index_add(index, &entry));
|
||||
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__cannot_add_forbidden_filename_from_filesystem(void)
|
||||
{
|
||||
git_index *index;
|
||||
|
||||
/* since our function calls are very low-level, we can create `aux.`,
|
||||
* but we should not be able to add it to the index
|
||||
*/
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
cl_git_write2file("win32-forbidden/aux.", "foo\n", 4, O_RDWR | O_CREAT, 0666);
|
||||
|
||||
#ifdef GIT_WIN32
|
||||
cl_git_fail(git_index_add_bypath(index, "aux."));
|
||||
#else
|
||||
cl_git_pass(git_index_add_bypath(index, "aux."));
|
||||
#endif
|
||||
|
||||
cl_must_pass(p_unlink("win32-forbidden/aux."));
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
static int dummy_submodule_cb(
|
||||
git_submodule *sm, const char *name, void *payload)
|
||||
{
|
||||
GIT_UNUSED(sm);
|
||||
GIT_UNUSED(name);
|
||||
GIT_UNUSED(payload);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_diff_tree_to_index(void)
|
||||
{
|
||||
git_diff *diff;
|
||||
git_tree *tree;
|
||||
|
||||
cl_git_pass(git_repository_head_tree(&tree, repo));
|
||||
cl_git_pass(git_diff_tree_to_index(&diff, repo, tree, NULL, NULL));
|
||||
cl_assert_equal_i(0, git_diff_num_deltas(diff));
|
||||
git_diff_free(diff);
|
||||
git_tree_free(tree);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_diff_tree_to_tree(void)
|
||||
{
|
||||
git_diff *diff;
|
||||
git_tree *tree;
|
||||
|
||||
cl_git_pass(git_repository_head_tree(&tree, repo));
|
||||
cl_git_pass(git_diff_tree_to_tree(&diff, repo, tree, tree, NULL));
|
||||
cl_assert_equal_i(0, git_diff_num_deltas(diff));
|
||||
git_diff_free(diff);
|
||||
git_tree_free(tree);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_diff_index_to_workdir(void)
|
||||
{
|
||||
git_index *index;
|
||||
git_diff *diff;
|
||||
const git_diff_delta *delta;
|
||||
git_tree *tree;
|
||||
size_t i;
|
||||
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
cl_git_pass(git_repository_head_tree(&tree, repo));
|
||||
cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL));
|
||||
|
||||
for (i = 0; i < git_diff_num_deltas(diff); i++) {
|
||||
delta = git_diff_get_delta(diff, i);
|
||||
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
||||
}
|
||||
|
||||
git_diff_free(diff);
|
||||
git_tree_free(tree);
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
void test_win32_forbidden__checking_out_forbidden_index_fails(void)
|
||||
{
|
||||
#ifdef GIT_WIN32
|
||||
git_index *index;
|
||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||
git_diff *diff;
|
||||
const git_diff_delta *delta;
|
||||
git_tree *tree;
|
||||
size_t num_deltas, i;
|
||||
|
||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||
|
||||
cl_git_pass(git_repository_index(&index, repo));
|
||||
cl_git_fail(git_checkout_index(repo, index, &opts));
|
||||
|
||||
cl_git_pass(git_repository_head_tree(&tree, repo));
|
||||
cl_git_pass(git_diff_index_to_workdir(&diff, repo, index, NULL));
|
||||
|
||||
num_deltas = git_diff_num_deltas(diff);
|
||||
|
||||
cl_assert(num_deltas > 0);
|
||||
|
||||
for (i = 0; i < num_deltas; i++) {
|
||||
delta = git_diff_get_delta(diff, i);
|
||||
cl_assert_equal_i(GIT_DELTA_DELETED, delta->status);
|
||||
}
|
||||
|
||||
git_diff_free(diff);
|
||||
git_tree_free(tree);
|
||||
git_index_free(index);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_query_submodules(void)
|
||||
{
|
||||
cl_git_pass(git_submodule_foreach(repo, dummy_submodule_cb, NULL));
|
||||
}
|
||||
|
||||
void test_win32_forbidden__can_blame_file(void)
|
||||
{
|
||||
git_blame *blame;
|
||||
|
||||
cl_git_pass(git_blame_file(&blame, repo, "aux", NULL));
|
||||
git_blame_free(blame);
|
||||
}
|
||||
Reference in New Issue
Block a user