]> git.proxmox.com Git - libgit2.git/blob - tests/network/refspecs.c
Rename tests-clar to tests
[libgit2.git] / tests / network / refspecs.c
1 #include "clar_libgit2.h"
2 #include "refspec.h"
3 #include "remote.h"
4
5 static void assert_refspec(unsigned int direction, const char *input, bool is_expected_to_be_valid)
6 {
7 git_refspec refspec;
8 int error;
9
10 error = git_refspec__parse(&refspec, input, direction == GIT_DIRECTION_FETCH);
11 git_refspec__free(&refspec);
12
13 if (is_expected_to_be_valid)
14 cl_assert_equal_i(0, error);
15 else
16 cl_assert_equal_i(GIT_ERROR, error);
17 }
18
19 void test_network_refspecs__parsing(void)
20 {
21 // Ported from https://github.com/git/git/blob/abd2bde78bd994166900290434a2048e660dabed/t/t5511-refspec.sh
22
23 assert_refspec(GIT_DIRECTION_PUSH, "", false);
24 assert_refspec(GIT_DIRECTION_PUSH, ":", true);
25 assert_refspec(GIT_DIRECTION_PUSH, "::", false);
26 assert_refspec(GIT_DIRECTION_PUSH, "+:", true);
27
28 assert_refspec(GIT_DIRECTION_FETCH, "", true);
29 assert_refspec(GIT_DIRECTION_PUSH, ":", true);
30 assert_refspec(GIT_DIRECTION_FETCH, "::", false);
31
32 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*:refs/remotes/frotz/*", true);
33 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*:refs/remotes/frotz", false);
34 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads:refs/remotes/frotz/*", false);
35 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/master:refs/remotes/frotz/xyzzy", true);
36
37 /*
38 * These have invalid LHS, but we do not have a formal "valid sha-1
39 * expression syntax checker" so they are not checked with the current
40 * code. They will be caught downstream anyway, but we may want to
41 * have tighter check later...
42 */
43 //assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/master::refs/remotes/frotz/xyzzy", false);
44 //assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/maste :refs/remotes/frotz/xyzzy", false);
45
46 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*:refs/remotes/frotz/*", true);
47 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*:refs/remotes/frotz", false);
48 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads:refs/remotes/frotz/*", false);
49 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/master:refs/remotes/frotz/xyzzy", true);
50 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/master::refs/remotes/frotz/xyzzy", false);
51 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/maste :refs/remotes/frotz/xyzzy", false);
52
53 assert_refspec(GIT_DIRECTION_PUSH, "master~1:refs/remotes/frotz/backup", true);
54 assert_refspec(GIT_DIRECTION_FETCH, "master~1:refs/remotes/frotz/backup", false);
55 assert_refspec(GIT_DIRECTION_PUSH, "HEAD~4:refs/remotes/frotz/new", true);
56 assert_refspec(GIT_DIRECTION_FETCH, "HEAD~4:refs/remotes/frotz/new", false);
57
58 assert_refspec(GIT_DIRECTION_PUSH, "HEAD", true);
59 assert_refspec(GIT_DIRECTION_FETCH, "HEAD", true);
60 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/ nitfol", false);
61 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/ nitfol", false);
62
63 assert_refspec(GIT_DIRECTION_PUSH, "HEAD:", false);
64 assert_refspec(GIT_DIRECTION_FETCH, "HEAD:", true);
65 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/ nitfol:", false);
66 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/ nitfol:", false);
67
68 assert_refspec(GIT_DIRECTION_PUSH, ":refs/remotes/frotz/deleteme", true);
69 assert_refspec(GIT_DIRECTION_FETCH, ":refs/remotes/frotz/HEAD-to-me", true);
70 assert_refspec(GIT_DIRECTION_PUSH, ":refs/remotes/frotz/delete me", false);
71 assert_refspec(GIT_DIRECTION_FETCH, ":refs/remotes/frotz/HEAD to me", false);
72
73 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/for-linus:refs/remotes/mine/*-blah", false);
74 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/for-linus:refs/remotes/mine/*-blah", false);
75
76 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads*/for-linus:refs/remotes/mine/*", false);
77 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads*/for-linus:refs/remotes/mine/*", false);
78
79 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/*/for-linus:refs/remotes/mine/*", false);
80 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/*/for-linus:refs/remotes/mine/*", false);
81
82 assert_refspec(GIT_DIRECTION_FETCH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
83 assert_refspec(GIT_DIRECTION_PUSH, "refs/heads/*/for-linus:refs/remotes/mine/*", true);
84
85 assert_refspec(GIT_DIRECTION_FETCH, "master", true);
86 assert_refspec(GIT_DIRECTION_PUSH, "master", true);
87 }