summaryrefslogtreecommitdiff
path: root/ikiwiki-makerepo
blob: b733bd13ab96d1801db4e31d0cc01f1f7e890f4a (plain)
  1. #!/bin/sh
  2. set -e
  3. rcs="$1"
  4. srcdir="$2"
  5. repository="$3"
  6. usage () {
  7. echo "usage: ikiwiki-makerepo svn|git srcdir repository" >&2
  8. echo " ikiwiki-makerepo bzr|mercurial srcdir" >&2
  9. exit 1
  10. }
  11. if [ -z "$rcs" ] || [ -z "$srcdir" ]; then
  12. usage
  13. fi
  14. if [ ! -d "$srcdir" ]; then
  15. echo "srcdir $srcdir not found" >&2
  16. exit 1
  17. fi
  18. if [ "$rcs" != mercurial ] && [ "$rcs" != bzr ]; then
  19. if [ -z "$repository" ]; then
  20. echo "you need to specify both a srcdir and a repository for $rcs" >&2
  21. usage
  22. fi
  23. if [ -e "$repository" ]; then
  24. echo "repository $repository already exists, aborting" >&2
  25. exit 1
  26. fi
  27. repository="$(perl -e 'use Cwd q{abs_path}; $r=shift; $r=~s/\/*$//; print abs_path($r)' $repository)"
  28. if [ -z "$repository" ]; then
  29. echo "internal error finding repository abs_path" >&2
  30. exit 1
  31. fi
  32. fi
  33. echo "Importing $srcdir into $rcs"
  34. case "$rcs" in
  35. svn)
  36. if [ -e "$srcdir/.svn" ]; then
  37. echo "$srcdir already seems to be a svn working copy" >&2
  38. exit 1
  39. fi
  40. svnadmin create "$repository"
  41. svn mkdir "file://$repository/trunk" -m "create trunk directory"
  42. cd "$srcdir"
  43. svn co "file://$repository/trunk" .
  44. svn propset svn:ignore ".ikiwiki" .
  45. svn add *
  46. svn commit -m "initial import"
  47. echo "Directory $srcdir is now a checkout of $rcs repository $repository"
  48. ;;
  49. git)
  50. # There are better ways to do this, but this works with older
  51. # versions of git.)
  52. mkdir -p "$repository"
  53. (cd "$repository" && git --bare init --shared)
  54. cd "$srcdir"
  55. git init
  56. echo /.ikiwiki > .gitignore
  57. echo /recentchanges >> .gitignore
  58. git add .
  59. git commit -m "initial commit"
  60. git remote add origin "$repository"
  61. git config branch.master.merge refs/heads/master
  62. git config branch.master.remote origin
  63. git push --all
  64. echo "Directory $srcdir is now a clone of $rcs repository $repository"
  65. ;;
  66. mercurial)
  67. hg init "$srcdir"
  68. cd "$srcdir"
  69. echo .ikiwiki > .hgignore
  70. hg add * .hgignore
  71. hg commit -m "initial import"
  72. echo "Directory $srcdir is now set up as a mercurial repository"
  73. ;;
  74. bzr)
  75. bzr init "$srcdir"
  76. cd "$srcdir"
  77. echo .ikiwiki > .bzrignore
  78. bzr add * .bzrignore
  79. bzr commit -m "initial import"
  80. echo "Directory $srcdir is now set up as a bzr repository"
  81. ;;
  82. *)
  83. echo "Unsupported revision control system $rcs" >&2
  84. usage
  85. ;;
  86. esac