summaryrefslogtreecommitdiff
path: root/t/git.t
blob: 0a5ba7266a74f7f55bf28b8839e897ae5f1e99f4 (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::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. # Renaming
  54. writefile('test3.mdwn', $config{srcdir}, $test1);
  55. IkiWiki::rcs_add("test3.mdwn");
  56. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  57. IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
  58. @changes = IkiWiki::rcs_recentchanges(4);
  59. is($#changes, 3);
  60. is($changes[0]{pages}[0]{"page"}, "test4.mdwn");
  61. ok(mkdir($config{srcdir}."/newdir"));
  62. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  63. IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
  64. @changes = IkiWiki::rcs_recentchanges(4);
  65. is($#changes, 3);
  66. is($changes[0]{pages}[0]{"page"}, "newdir/test5.mdwn");
  67. IkiWiki::rcs_remove("newdir/test5.mdwn");
  68. IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
  69. system "rm -rf $dir";