summaryrefslogtreecommitdiff
path: root/t/git.t
blob: f4e27c473c5279f6e5a389e000d74f66a5edf2be (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 => 11;
  18. BEGIN { use_ok("IkiWiki"); }
  19. %config=IkiWiki::defaultconfig();
  20. $config{rcs} = "git";
  21. $config{srcdir} = "$dir/src";
  22. IkiWiki::checkconfig();
  23. system "cd $gitrepo && git init >/dev/null 2>&1";
  24. system "cd $gitrepo && echo dummy > dummy; git add . >/dev/null 2>&1";
  25. system "cd $gitrepo && git commit -m Initial >/dev/null 2>&1";
  26. system "git clone -l -s $gitrepo $config{srcdir} >/dev/null 2>&1";
  27. my @changes;
  28. @changes = IkiWiki::rcs_recentchanges(3);
  29. is($#changes, 0); # counts for dummy commit during repo creation
  30. is($changes[0]{message}[0]{"line"}, "Initial");
  31. is($changes[0]{pages}[0]{"page"}, "dummy");
  32. # Web commit
  33. my $test1 = readfile("t/test1.mdwn");
  34. writefile('test1.mdwn', $config{srcdir}, $test1);
  35. IkiWiki::rcs_add("test1.mdwn");
  36. IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo");
  37. @changes = IkiWiki::rcs_recentchanges(3);
  38. is($#changes, 1);
  39. is($changes[0]{message}[0]{"line"}, "Added the first page");
  40. is($changes[0]{pages}[0]{"page"}, "test1.mdwn");
  41. # Manual commit
  42. my $message = "Added the second page";
  43. my $test2 = readfile("t/test2.mdwn");
  44. writefile('test2.mdwn', $config{srcdir}, $test2);
  45. system "cd $config{srcdir}; git add test2.mdwn >/dev/null 2>&1";
  46. system "cd $config{srcdir}; git commit -m \"$message\" test2.mdwn >/dev/null 2>&1";
  47. system "cd $config{srcdir}; git push origin >/dev/null 2>&1";
  48. @changes = IkiWiki::rcs_recentchanges(3);
  49. is($#changes, 2);
  50. is($changes[0]{message}[0]{"line"}, $message);
  51. is($changes[0]{pages}[0]{"page"}, "test2.mdwn");
  52. is($changes[1]{pages}[0]{"page"}, "test1.mdwn");
  53. system "rm -rf $dir";