Blame Scripts/Bash/Functions/Vcs/Subversion/subversion_updateRepoChanges.sh

4debce
#!/bin/bash
4debce
#
3b9515
# subversion_updateRepoChanges.sh -- This function realizes a
3b9515
# subversion update command against the working copy in order to bring
3b9515
# changes from the central repository into the working copy.
4debce
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
4debce
#
4debce
# This program is free software; you can redistribute it and/or modify
4debce
# it under the terms of the GNU General Public License as published by
4debce
# the Free Software Foundation; either version 2 of the License, or (at
4debce
# your option) any later version.
4debce
#
4debce
# This program is distributed in the hope that it will be useful, but
4debce
# WITHOUT ANY WARRANTY; without even the implied warranty of
4debce
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4debce
# General Public License for more details.
4debce
#
4debce
# You should have received a copy of the GNU General Public License
4debce
# along with this program; if not, write to the Free Software
4debce
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4debce
#
4debce
# ----------------------------------------------------------------------
4debce
# $Id$
4debce
# ----------------------------------------------------------------------
4debce
3b9515
function subversion_updateRepoChanges {
4debce
4debce
    local -a FILES
4debce
    local -a INFO
4debce
    local -a FILESNUM
4debce
    local COUNT=0
4debce
    local UPDATEOUT=''
4debce
    local PREDICATE=''
4debce
    local CHNGTOTAL=0
977940
    local LOCATION=$(cli_checkRepoDirSource "$1")
4debce
ccef8a
    # Verify source location absolute path. It should point either to
ccef8a
    # existent files or directories both under version control inside
ccef8a
    # the working copy.  Otherwise, if it doesn't point to an existent
ccef8a
    # file under version control, finish the script execution with an
ccef8a
    # error message.
ccef8a
    cli_checkFiles ${LOCATION} -e --is-versioned
ccef8a
ccef8a
    # Update working copy and retrieve update output.
4debce
    cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" --as-banner-line
3b9515
    UPDATEOUT=$(${COMMAND} update ${LOCATION} --quiet)
4debce
4debce
    # Define path of files considered recent modifications from
4debce
    # central repository to working copy.
4e1989
    FILES[0]=$(echo "$UPDATEOUT" | egrep "^A" | sed -r "s,^.+${TCAR_WORKDIR},,")
4e1989
    FILES[1]=$(echo "$UPDATEOUT" | egrep "^D" | sed -r "s,^.+${TCAR_WORKDIR},,")
4e1989
    FILES[2]=$(echo "$UPDATEOUT" | egrep "^U" | sed -r "s,^.+${TCAR_WORKDIR},,")
4e1989
    FILES[3]=$(echo "$UPDATEOUT" | egrep "^C" | sed -r "s,^.+${TCAR_WORKDIR},,")
4e1989
    FILES[4]=$(echo "$UPDATEOUT" | egrep "^G" | sed -r "s,^.+${TCAR_WORKDIR},,")
4debce
4debce
    # Define description of files considered recent modifications from
4debce
    # central repository to working copy.
4debce
    INFO[0]="`gettext "Added"`"
4debce
    INFO[1]="`gettext "Deleted"`"
4debce
    INFO[2]="`gettext "Updated"`"
4debce
    INFO[3]="`gettext "Conflicted"`"
4debce
    INFO[4]="`gettext "Merged"`"
4debce
4debce
    while [[ $COUNT -ne ${#FILES[*]} ]];do
4debce
4debce
        # Define total number of files. Avoid counting empty line.
4debce
        if [[ "${FILES[$COUNT]}" == '' ]];then
4debce
            FILESNUM[$COUNT]=0
4debce
        else
4debce
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
4debce
        fi
4debce
4debce
        # Calculate total amount of changes.
4debce
        CHNGTOTAL=$(($CHNGTOTAL + ${FILESNUM[$COUNT]}))
4debce
4debce
        # Build report predicate. Use report predicate to show any
4debce
        # information specific to the number of files found. For
4debce
        # example, you can use this section to show warning messages,
4debce
        # notes, and so on. By default we use the word `file' or
4debce
        # `files' at ngettext's consideration followed by change
4debce
        # direction.
4debce
        PREDICATE[$COUNT]=`ngettext "file from the repository" \
4debce
            "files from the repository" $((${FILESNUM[$COUNT]} + 1))`
4debce
4debce
        # Output report line.
977940
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" --as-stdout-line
4debce
4debce
        # Increase counter.
4debce
        COUNT=$(($COUNT + 1))
4debce
4debce
    done
4debce
4debce
}