BASH – Script para sincronizar cambios entre repositorios SVN.-

Poner especial atención en el uso de funciones, las cuales se pueden a adaptar a otras soluciones de scripting :

#! /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
Esta entrada fue publicada en Unix - Linux. Guarda el enlace permanente.

Deja una respuesta

Tu dirección de correo electrónico no será publicada.