Don't error out, either warn or say nothing, depending.
[ikiwiki] / t / git.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 my $dir;
6 BEGIN {
7         $dir="/tmp/ikiwiki-test-git.$$";
8         my $git=`which git`;
9         chomp $git;
10         if (! -x $git || ! mkdir($dir)) {
11                 eval q{
12                         use Test::More skip_all => "git not available or could not make test dir"
13                 }
14         }
15 }
16 use Test::More tests => 18;
17
18 BEGIN { use_ok("IkiWiki"); }
19
20 %config=IkiWiki::defaultconfig();
21 $config{rcs} = "git";
22 $config{srcdir} = "$dir/src";
23 IkiWiki::loadplugins();
24 IkiWiki::checkconfig();
25
26 ok (mkdir($config{srcdir}));
27 is (system("./ikiwiki-makerepo git $config{srcdir} $dir/repo"), 0);
28
29 my @changes;
30 @changes = IkiWiki::rcs_recentchanges(3);
31
32 is($#changes, 0); # counts for dummy commit during repo creation
33 # ikiwiki-makerepo's first commit is setting up the .gitignore
34 is($changes[0]{message}[0]{"line"}, "initial commit");
35 is($changes[0]{pages}[0]{"page"}, ".gitignore");
36
37 # Web commit
38 my $test1 = readfile("t/test1.mdwn");
39 writefile('test1.mdwn', $config{srcdir}, $test1);
40 IkiWiki::rcs_add("test1.mdwn");
41 IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo");
42
43 @changes = IkiWiki::rcs_recentchanges(3);
44
45 is($#changes, 1);
46 is($changes[0]{message}[0]{"line"}, "Added the first page");
47 is($changes[0]{pages}[0]{"page"}, "test1");
48         
49 # Manual commit
50 my $message = "Added the second page";
51
52 my $test2 = readfile("t/test2.mdwn");
53 writefile('test2.mdwn', $config{srcdir}, $test2);
54 system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
55 system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
56 system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
57
58 @changes = IkiWiki::rcs_recentchanges(3);
59
60 is($#changes, 2);
61 is($changes[0]{message}[0]{"line"}, $message);
62 is($changes[0]{pages}[0]{"page"}, "test2");
63
64 is($changes[1]{pages}[0]{"page"}, "test1");
65
66 # Renaming
67
68 writefile('test3.mdwn', $config{srcdir}, $test1);
69 IkiWiki::rcs_add("test3.mdwn");
70 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
71 IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
72
73 @changes = IkiWiki::rcs_recentchanges(4);
74
75 is($#changes, 3);
76 is($changes[0]{pages}[0]{"page"}, "test4");
77
78 ok(mkdir($config{srcdir}."/newdir"));
79 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
80 IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
81
82 @changes = IkiWiki::rcs_recentchanges(4);
83
84 is($#changes, 3);
85 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
86
87 IkiWiki::rcs_remove("newdir/test5.mdwn");
88 IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
89
90 system "rm -rf $dir";