]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/git.t
small bug
[git.ikiwiki.info.git] / t / git.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
5 my $dir;
6 BEGIN {
7         $dir="/tmp/ikiwiki-test-git.$$";
8         my $git=`which git`;
9         chomp $git;
10         if (! -x $git) {
11                 eval q{
12                         use Test::More skip_all => "git not available"
13                 }
14         }
15         if (! mkdir($dir)) {
16                 die $@;
17         }
18 }
19 use Test::More tests => 22;
21 BEGIN { use_ok("IkiWiki"); }
23 %config=IkiWiki::defaultconfig();
24 $config{rcs} = "git";
25 $config{srcdir} = "$dir/src";
26 $config{diffurl} = '/nonexistent/cgit/plain/[[file]]';
27 IkiWiki::loadplugins();
28 IkiWiki::checkconfig();
30 ok (mkdir($config{srcdir}));
31 is (system("./ikiwiki-makerepo git $config{srcdir} $dir/repo"), 0);
33 my @changes;
34 @changes = IkiWiki::rcs_recentchanges(3);
36 is($#changes, 0); # counts for dummy commit during repo creation
37 # ikiwiki-makerepo's first commit is setting up the .gitignore
38 is($changes[0]{message}[0]{"line"}, "initial commit");
39 is($changes[0]{pages}[0]{"page"}, ".gitignore");
41 # Web commit
42 my $test1 = readfile("t/test1.mdwn");
43 writefile('test1.mdwn', $config{srcdir}, $test1);
44 IkiWiki::rcs_add("test1.mdwn");
45 IkiWiki::rcs_commit(
46         file => "test1.mdwn",
47         message => "Added the first page",
48         token => "moo",
49 );
51 @changes = IkiWiki::rcs_recentchanges(3);
53 is($#changes, 1);
54 is($changes[0]{message}[0]{"line"}, "Added the first page");
55 is($changes[0]{pages}[0]{"page"}, "test1");
56         
57 # Manual commit
58 my $message = "Added the second page";
60 my $test2 = readfile("t/test2.mdwn");
61 writefile('test2.mdwn', $config{srcdir}, $test2);
62 system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
63 system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
64 system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
66 @changes = IkiWiki::rcs_recentchanges(3);
68 is($#changes, 2);
69 is($changes[0]{message}[0]{"line"}, $message);
70 is($changes[0]{pages}[0]{"page"}, "test2");
72 is($changes[1]{pages}[0]{"page"}, "test1");
74 # Renaming
76 writefile('test3.mdwn', $config{srcdir}, $test1);
77 IkiWiki::rcs_add("test3.mdwn");
78 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
79 IkiWiki::rcs_commit_staged(message => "Added the 4th page");
81 @changes = IkiWiki::rcs_recentchanges(4);
83 is($#changes, 3);
84 is($changes[0]{pages}[0]{"page"}, "test4");
86 ok(mkdir($config{srcdir}."/newdir"));
87 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
88 IkiWiki::rcs_commit_staged(message => "Added the 5th page");
90 @changes = IkiWiki::rcs_recentchanges(4);
92 is($#changes, 3);
93 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
95 IkiWiki::rcs_remove("newdir/test5.mdwn");
96 IkiWiki::rcs_commit_staged(message => "Remove the 5th page");
98 # diffurl escaping
99 ok(mkdir($config{srcdir}."/diffurl_dir"));
100 my $test3 = readfile("t/test1.mdwn");
101 writefile('test3.mdwn', $config{srcdir}."/diffurl_dir", $test3);
102 IkiWiki::rcs_add("diffurl_dir/test3.mdwn");
103 IkiWiki::rcs_commit(
104         file => "diffurl_dir/test3.mdwn",
105         message => "Added a page in diffurl_dir",
106         token => "moo",
107 );
109 @changes = IkiWiki::rcs_recentchanges(5);
111 is($#changes, 4);
112 is($changes[0]{pages}[0]{"page"}, "diffurl_dir/test3");
114 unlike(
115         $changes[0]{pages}[0]{"diffurl"},
116         qr{%2F}m,
117         q{path separators are preserved when UTF-8scaping filename}
118 );
120 system "rm -rf $dir";