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