dagnabbit, another typo!
[ikiwiki.git] / t / git.t
blob6d847dfb04d56808dab435a125bc6cbadcfd3af0
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"
15 if (! mkdir($dir)) {
16 die $@;
19 use Test::More tests => 18;
21 BEGIN { use_ok("IkiWiki"); }
23 %config=IkiWiki::defaultconfig();
24 $config{rcs} = "git";
25 $config{srcdir} = "$dir/src";
26 IkiWiki::loadplugins();
27 IkiWiki::checkconfig();
29 ok (mkdir($config{srcdir}));
30 is (system("./ikiwiki-makerepo git $config{srcdir} $dir/repo"), 0);
32 my @changes;
33 @changes = IkiWiki::rcs_recentchanges(3);
35 is($#changes, 0); # counts for dummy commit during repo creation
36 # ikiwiki-makerepo's first commit is setting up the .gitignore
37 is($changes[0]{message}[0]{"line"}, "initial commit");
38 is($changes[0]{pages}[0]{"page"}, ".gitignore");
40 # Web commit
41 my $test1 = readfile("t/test1.mdwn");
42 writefile('test1.mdwn', $config{srcdir}, $test1);
43 IkiWiki::rcs_add("test1.mdwn");
44 IkiWiki::rcs_commit(
45 file => "test1.mdwn",
46 message => "Added the first page",
47 token => "moo",
50 @changes = IkiWiki::rcs_recentchanges(3);
52 is($#changes, 1);
53 is($changes[0]{message}[0]{"line"}, "Added the first page");
54 is($changes[0]{pages}[0]{"page"}, "test1");
56 # Manual commit
57 my $message = "Added the second page";
59 my $test2 = readfile("t/test2.mdwn");
60 writefile('test2.mdwn', $config{srcdir}, $test2);
61 system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
62 system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
63 system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
65 @changes = IkiWiki::rcs_recentchanges(3);
67 is($#changes, 2);
68 is($changes[0]{message}[0]{"line"}, $message);
69 is($changes[0]{pages}[0]{"page"}, "test2");
71 is($changes[1]{pages}[0]{"page"}, "test1");
73 # Renaming
75 writefile('test3.mdwn', $config{srcdir}, $test1);
76 IkiWiki::rcs_add("test3.mdwn");
77 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
78 IkiWiki::rcs_commit_staged(message => "Added the 4th page");
80 @changes = IkiWiki::rcs_recentchanges(4);
82 is($#changes, 3);
83 is($changes[0]{pages}[0]{"page"}, "test4");
85 ok(mkdir($config{srcdir}."/newdir"));
86 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
87 IkiWiki::rcs_commit_staged(message => "Added the 5th page");
89 @changes = IkiWiki::rcs_recentchanges(4);
91 is($#changes, 3);
92 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
94 IkiWiki::rcs_remove("newdir/test5.mdwn");
95 IkiWiki::rcs_commit_staged(message => "Remove the 5th page");
97 system "rm -rf $dir";