Import patchsync version 2.2
[utils/utils.git] / patchsync
index 07e2f0f..31dd624 100755 (executable)
--- a/patchsync
+++ b/patchsync
@@ -1,9 +1,11 @@
 #!/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.
-# Version 2
 # -- Matt McCutchen
 # -- Matt McCutchen
-#
+
+# If I had to update the version in the --version message separately, I would forget.
+PATCHSYNC_VERSION=2.2
+
 # 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
@@ -211,6 +213,10 @@ if [ -z "$whichtoupdate" ] && [[ -n $trunkch || -n $branchch || -n $patchch ]];
        #echo "Synchronization will update $whichtoupdate."
 fi
 
        #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.
 if [ -n "$whichtoupdate" ]; then
 
 # Always show what would happen if patch-new and branch-new were copied out.
@@ -219,9 +225,6 @@ if [ -n "$whichtoupdate" ]; then
 # state if no error.
 error=
 
 # 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
 function prepare_branch {
        echo "Preparing updated branch..."
        # No link-dest because we will modify and then link-dest when copying out
@@ -285,7 +288,7 @@ if ! [ $error ] && ! [ $dryrun ]; then
                "${COPYOUT[@]}" -i --link-dest="$(wdpp_from branch/)branch-new/" branch-new/ branch/
                rm -rf branch-new
        }
                "${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"
                hash_file patch-new >patch-new-hash
                # Don't use rsync because we might have to write through a symlink.
                echo "> patch"
@@ -306,7 +309,7 @@ else
                "${COPYOUT[@]}" -n -i --link-dest="$(wdpp_from branch/)branch-new/" branch-new/ branch/
                #rm -rf branch-new
        }
                "${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"
                hash_file patch-new >patch-new-hash
                # Don't use rsync because we might have to write through a symlink.
                echo "> patch"
@@ -422,7 +425,7 @@ END
 
 function patchsync_help {
        cat <<EOF
 
 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.
 usage: patchsync [--dry-run] <staging> [branch | patch]
        patchsync --new <trunk> <patch> <branch> <staging>
 Please read the top of the script for complete documentation.