#!/bin/bash
# patchsync: Synchronizes a trunk, a branch, and a patch containing the
# differences between them.
#!/bin/bash
# patchsync: Synchronizes a trunk, a branch, and a patch containing the
# differences between them.
# usage: patchsync [--dry-run] <staging> [branch | patch]
#
# Patchsync is invoked on a "staging directory", which holds some configuration
# 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 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 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; }
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; }
if [ -n "$whichtoupdate" ]; then
# Always show what would happen if patch-new and branch-new were copied out.
if [ -n "$whichtoupdate" ]; then
# Always show what would happen if patch-new and branch-new were copied out.
function prepare_branch {
echo "Preparing updated branch..."
# No link-dest because we will modify and then link-dest when copying out
function prepare_branch {
echo "Preparing updated branch..."
# No link-dest because we will modify and then link-dest when copying out
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
hash_file patch-new >patch-new-hash
# Don't use rsync because we might have to write through a symlink.
echo "> patch"
! [ -e "$staging" ] || { echo "Staging dir already exists!" 1>&2; exit 1; }
[ -d "$trunk" ] || { echo "Trunk does not exist!" 1>&2; exit 1; }
! [ -e "$staging" ] || { echo "Staging dir already exists!" 1>&2; exit 1; }
[ -d "$trunk" ] || { echo "Trunk does not exist!" 1>&2; exit 1; }
usage: patchsync [--dry-run] <staging> [branch | patch]
patchsync --new <trunk> <patch> <branch> <staging>
Please read the top of the script for complete documentation.
usage: patchsync [--dry-run] <staging> [branch | patch]
patchsync --new <trunk> <patch> <branch> <staging>
Please read the top of the script for complete documentation.