summaryrefslogtreecommitdiff
path: root/t/git.t
blob: f1c24b3598e1709d9d58a9f962df4fef1f12a3f1 (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("test1.mdwn", "Added the first page", "moo");
  35. @changes = IkiWiki::rcs_recentchanges(3);
  36. is($#changes, 1);
  37. is($changes[0]{message}[0]{"line"}, "Added the first page");
  38. is($changes[0]{pages}[0]{"page"}, "test1");
  39. # Manual commit
  40. my $message = "Added the second page";
  41. my $test2 = readfile("t/test2.mdwn");
  42. writefile('test2.mdwn', $config{srcdir}, $test2);
  43. system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
  44. system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
  45. system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
  46. @changes = IkiWiki::rcs_recentchanges(3);
  47. is($#changes, 2);
  48. is($changes[0]{message}[0]{"line"}, $message);
  49. is($changes[0]{pages}[0]{"page"}, "test2");
  50. is($changes[1]{pages}[0]{"page"}, "test1");
  51. # Renaming
  52. writefile('test3.mdwn', $config{srcdir}, $test1);
  53. IkiWiki::rcs_add("test3.mdwn");
  54. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  55. IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
  56. @changes = IkiWiki::rcs_recentchanges(4);
  57. is($#changes, 3);
  58. is($changes[0]{pages}[0]{"page"}, "test4");
  59. ok(mkdir($config{srcdir}."/newdir"));
  60. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  61. IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
  62. @changes = IkiWiki::rcs_recentchanges(4);
  63. is($#changes, 3);
  64. is($changes[0]{pages}[0]{"page"}, "newdir/test5");
  65. IkiWiki::rcs_remove("newdir/test5.mdwn");
  66. IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
  67. system "rm -rf $dir";