#!/bin/bash
# patchsync: Synchronizes a trunk, a branch, and a patch containing the
# differences between them.
-# Version 2
# -- Matt McCutchen
-#
+
+# If I had to update the version in the --version message separately, I would forget.
+PATCHSYNC_VERSION=2.3
+
# usage: patchsync [--dry-run] <staging> [branch | patch]
#
# Patchsync is invoked on a "staging directory", which holds some configuration
type rsync >/dev/null 2>&1 || \
{ echo "Patchsync requires rsync, but there's no rsync on your path!" 1>&2; exit 1; }
# If a cp2 is available, use it; otherwise define our own.
-type cp2 >/dev/null 2>&1 || function cp2 { rsync -rltE --chmod=ugo=rwx "$@"; }
+type cp2 >/dev/null 2>&1 || function cp2 { exec rsync -rltE --chmod=ugo=rwx "$@"; }
function exitoneok {
"$@" || [ $? == 1 ]
cd "$staging" || { echo "Failed to enter staging dir!" 1>&2; exit 1; }
shift
-. settings
+. ./settings
type do_diff >/dev/null 2>&1 || { echo "do_diff is not defined!" 1>&2; exit 1; }
type do_patch >/dev/null 2>&1 || { echo "do_patch is not defined!" 1>&2; exit 1; }
#echo "Synchronization will update $whichtoupdate."
fi
+# Remove old copy-out files to be clean and to make sure we don't
+# mistakenly copy them out this time.
+rm -rf patch-new branch-new
+
if [ -n "$whichtoupdate" ]; then
# Always show what would happen if patch-new and branch-new were copied out.
# state if no error.
error=
-# Don't let stuff from an old run confuse us.
-rm -rf patch-new branch-new
-
function prepare_branch {
echo "Preparing updated branch..."
# No link-dest because we will modify and then link-dest when copying out
"${COPYOUT[@]}" -i --link-dest="$(wdpp_from branch/)branch-new/" branch-new/ branch/
rm -rf branch-new
}
- ! [ -e patch-new ] || cmp -s patch-work patch || {
+ ! [ -e patch-new ] || cmp -s patch patch-new || {
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
"${COPYOUT[@]}" -n -i --link-dest="$(wdpp_from branch/)branch-new/" branch-new/ branch/
#rm -rf branch-new
}
- ! [ -e patch-new ] || cmp -s patch-work patch || {
+ ! [ -e patch-new ] || cmp -s patch patch-new || {
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
exit 1
fi
- # Set up arguments. Open templates because we will change directories.
+ # Set up arguments.
trunk="$1"
patch="$2"
branch="$3"
staging="$4"
- # What exists? Whichtochange first?
+ # What exists?
! [ -e "$staging" ] || { echo "Staging dir already exists!" 1>&2; exit 1; }
[ -d "$trunk" ] || { echo "Trunk does not exist!" 1>&2; exit 1; }
function patchsync_help {
cat <<EOF
-Patchsync version 2 by Matt McCutchen
+Patchsync version $PATCHSYNC_VERSION by Matt McCutchen
usage: patchsync [--dry-run] <staging> [branch | patch]
patchsync --new <trunk> <patch> <branch> <staging>
Please read the top of the script for complete documentation.