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