Poner especial atención en el uso de funciones, las cuales se pueden a adaptar a otras soluciones de scripting :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#! /bin/bash # # Merges the changes from a SVN repository into another. # # Useful when you have two branches or versions of the same project, # and need to bring changes from one into the other. # # Usage: # 1. > merge.sh <src_dir> <dest_dir> # 2. > merve.sh <src_dir> <dest_dir> <revision_number> # # In the first case, it runs a 'svn status' command in the source directory # to find the modified files # # In the second case, it runs a 'svn diff -r rev:HEAD' to find the modified files # # Note: tested on Mac OS X 10.7, with Xcode 4.5 # function pathForName { if [ "$1" = "proj1" ]; then dir="$HOME/Documents/Projects/Project1/"; elif [ "$1" = "proj2" ]; then dir="$HOME/Documents/Projects/Project2/"; elif [ "$1" = "proj3" ]; then dir="$HOME/Documents/Projects/Project3/"; elif [ "$1" = "proj4" ]; then dir="$HOME/Documents/Projects/Project4/"; fi } function doMerge { if [ "$stat" = "" ]; then stat=$1; else f=${1#$SRC} if [ "$stat" = "A" ]; then ask "Copy $f? " "cp ${SRC}${f} ${DST}${f}"; elif [ "$stat" = "M" ]; then ask "Merge $f? " "opendiff ${SRC}${f} ${DST}${f} -merge ${DST}${f}"; elif [ "$stat" = "D" ]; then ask "Delete $f? " "rm ${DEST}${f}" elif [ "$stat" = "?" ]; then echo "Ignoring: $f => status = ${stat}"; else echo "Status unknown ($stat) for file $f"; fi stat=""; fi } function ask { while true; do read -p "$1" yn case $yn in [Yy]* ) $2; break;; [Nn]* ) break;; * ) echo "Please answer yes or no.";; esac done } # Main pathForName $1 SRC=$dir echo "Source => $SRC" pathForName $2 DST=$dir echo "Destination => $DST" stat="" if [ "$3" = "" ]; then for f in $(svn status $SRC); do doMerge "$f"; done else for f in $(svn diff -r $3:HEAD --summarize); do doMerge "$f"; done fi |