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