7 $dir="/tmp/ikiwiki-test-git.$$";
12 use Test::More skip_all => "git not available"
19 use Test::More tests => 26;
21 BEGIN { use_ok("IkiWiki"); }
23 %config=IkiWiki::defaultconfig();
25 $config{srcdir} = "$dir/src";
26 $config{diffurl} = '/nonexistent/cgit/plain/[[file]]';
27 IkiWiki::loadplugins();
28 IkiWiki::checkconfig();
31 if ($ENV{INSTALLED_TESTS}) {
32 $makerepo = "ikiwiki-makerepo";
35 $makerepo = "./ikiwiki-makerepo";
38 ok (mkdir($config{srcdir}));
39 is (system("$makerepo git $config{srcdir} $dir/repo"), 0);
42 @changes = IkiWiki::rcs_recentchanges(3);
44 is($#changes, 0); # counts for dummy commit during repo creation
45 # ikiwiki-makerepo's first commit is setting up the .gitignore
46 is($changes[0]{message}[0]{"line"}, "initial commit");
47 is($changes[0]{pages}[0]{"page"}, ".gitignore");
50 my $test1 = readfile("t/test1.mdwn");
51 writefile('test1.mdwn', $config{srcdir}, $test1);
52 IkiWiki::rcs_add("test1.mdwn");
55 message => "Added the first page",
59 @changes = IkiWiki::rcs_recentchanges(3);
62 is($changes[0]{message}[0]{"line"}, "Added the first page");
63 is($changes[0]{pages}[0]{"page"}, "test1");
66 my $message = "Added the second page";
68 my $test2 = readfile("t/test2.mdwn");
69 writefile('test2.mdwn', $config{srcdir}, $test2);
70 system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
71 system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
72 system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
74 @changes = IkiWiki::rcs_recentchanges(3);
77 is($changes[0]{message}[0]{"line"}, $message);
78 is($changes[0]{pages}[0]{"page"}, "test2");
80 is($changes[1]{pages}[0]{"page"}, "test1");
84 writefile('test3.mdwn', $config{srcdir}, $test1);
85 IkiWiki::rcs_add("test3.mdwn");
86 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
87 IkiWiki::rcs_commit_staged(message => "Added the 4th page");
89 @changes = IkiWiki::rcs_recentchanges(4);
92 is($changes[0]{pages}[0]{"page"}, "test4");
94 ok(mkdir($config{srcdir}."/newdir"));
95 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
96 IkiWiki::rcs_commit_staged(message => "Added the 5th page");
98 @changes = IkiWiki::rcs_recentchanges(4);
101 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
103 IkiWiki::rcs_remove("newdir/test5.mdwn");
104 IkiWiki::rcs_commit_staged(message => "Remove the 5th page");
107 ok(mkdir($config{srcdir}."/diffurl_dir"));
108 my $test3 = readfile("t/test1.mdwn");
109 writefile('test3.mdwn', $config{srcdir}."/diffurl_dir", $test3);
110 IkiWiki::rcs_add("diffurl_dir/test3.mdwn");
112 file => "diffurl_dir/test3.mdwn",
113 message => "Added a page in diffurl_dir",
117 @changes = IkiWiki::rcs_recentchanges(5);
120 is($changes[0]{pages}[0]{"page"}, "diffurl_dir/test3");
123 $changes[0]{pages}[0]{"diffurl"},
125 q{path separators are preserved when UTF-8scaping filename}
128 # do a clean checkout to verify that "empty ident not allowed" is avoided
129 ok(! system("rm", "-rf", $config{srcdir}));
130 ok(! system("git", "clone", "$dir/repo", $config{srcdir}));
132 writefile('unconfigured_author.mdwn', $config{srcdir}, 'I am an unconfigured git author');
133 IkiWiki::rcs_add("unconfigured_author.mdwn");
135 file => "unconfigured_author.mdwn",
136 message => "hello, world",
140 @changes = IkiWiki::rcs_recentchanges(6);
143 is($changes[0]{pages}[0]{"page"}, "unconfigured_author");
145 system "rm -rf $dir";