git2darcs.hook.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. set -e
  3. refname="$1"
  4. OLDHEAD="$2"
  5. NEWHEAD="$3"
  6. NEW_COMMITS="$OLDHEAD..$NEWHEAD"
  7. WD=/home/ffdo/public_html/wiki
  8. G2D=$WD/wikidata-ffdo
  9. LOCK=$WD/git2darcs.lockf
  10. TMPDIR=/tmp/git2darcs.$USER
  11. PREFIX=/usr/local/bin
  12. GIT="$PREFIX/git --git-dir $G2D/.git"
  13. DARCS=$PREFIX/darcs
  14. cd $G2D
  15. [ -d _darcs -a -d .git ] || exit 1
  16. [ -d $TMPDIR -a -w $TMPDIR ] || mkdir -p $TMPDIR || exit 1
  17. lockf -t 10 $LOCK sh -x << -EOF-
  18. set -e
  19. cd $G2D
  20. export LANG=de_DE.UTF-8
  21. export LC_ALL=de_DE.UTF-8
  22. # Nur fast-forward kompatible commits ziehen, d.h. akzeptieren -
  23. # (git pull --ff-only --all)
  24. # aber wie kann man das hier (bei push) sicherstellen?
  25. [ -n "$OLDHEAD" -a -n "$NEWHEAD" ] && [ "$OLDHEAD" = "$NEWHEAD" ] && exit 0
  26. $GIT rev-list --reverse --no-walk "$NEW_COMMITS" > $TMPDIR/rev-list
  27. [ -s $TMPDIR/rev-list ] || { rm -rf $TMPDIR ; exit 0 ; }
  28. sed -n -E -e 's@^(.+)\$@cd $G2D \&\& '"$GIT"' reset --hard \1 \&\& '"$GIT"' rev-list --no-walk --pretty=\"%s%n%-b%n%ad %H\" \1 \| tail +2 > '"$TMPDIR/body"' \&\& '"$GIT"' rev-list --no-walk --pretty=format:\"'"$DARCS"' record --all --look-for-adds --logfile='"$TMPDIR/body"' --author \\\"%an <%ae>\\\"\" \1 | tail +2 > '"$TMPDIR/git2darcs.darcs.sh"' \&\& sh '"$TMPDIR/git2darcs.darcs.sh"'@p' $TMPDIR/rev-list > $TMPDIR/git2darcs.sh
  29. sh -x $TMPDIR/git2darcs.sh
  30. $DARCS push --all
  31. rm -rf $TMPDIR
  32. -EOF-