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