Blame Automation/Modules/centos-art.sh-vcs/Subversion/subversion_commitRepoChanges.sh

Alain Reguera Delgado 8f60cb
#!/bin/bash
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# subversion_commitRepoChanges.sh -- This function explores the
Alain Reguera Delgado 8f60cb
# working copy and commits changes up to central repository after
Alain Reguera Delgado 8f60cb
# checking changes and adding files which aren't under version
Alain Reguera Delgado 8f60cb
# control.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# Copyright (C) 2009-2013 The CentOS Project
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is free software; you can redistribute it and/or modify
Alain Reguera Delgado 8f60cb
# it under the terms of the GNU General Public License as published by
Alain Reguera Delgado 8f60cb
# the Free Software Foundation; either version 2 of the License, or (at
Alain Reguera Delgado 8f60cb
# your option) any later version.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# This program is distributed in the hope that it will be useful, but
Alain Reguera Delgado 8f60cb
# WITHOUT ANY WARRANTY; without even the implied warranty of
Alain Reguera Delgado 8f60cb
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Alain Reguera Delgado 8f60cb
# General Public License for more details.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# You should have received a copy of the GNU General Public License
Alain Reguera Delgado 8f60cb
# along with this program; if not, write to the Free Software
Alain Reguera Delgado 8f60cb
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Alain Reguera Delgado 8f60cb
#
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
# $Id$
Alain Reguera Delgado 8f60cb
# ----------------------------------------------------------------------
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
function subversion_commitRepoChanges {
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    local -a FILES
Alain Reguera Delgado 8f60cb
    local -a INFO
Alain Reguera Delgado 8f60cb
    local -a FILESNUM
Alain Reguera Delgado 8f60cb
    local COUNT=0
Alain Reguera Delgado 8f60cb
    local STATUSOUT=''
Alain Reguera Delgado 8f60cb
    local PREDICATE=''
Alain Reguera Delgado 8f60cb
    local CHNGTOTAL=0
Alain Reguera Delgado 8f60cb
    local LOCATION=$(cli_checkRepoDirSource "$1")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Verify source location absolute path. It should point either to
Alain Reguera Delgado 8f60cb
    # existent files or directories both under version control inside
Alain Reguera Delgado 8f60cb
    # the working copy.  Otherwise, if it doesn't point to an existent
Alain Reguera Delgado 8f60cb
    # file under version control, finish the script execution with an
Alain Reguera Delgado 8f60cb
    # error message.
Alain Reguera Delgado 8f60cb
    cli_checkFiles ${LOCATION} -e --is-versioned
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Print action message.
Alain Reguera Delgado 8f60cb
    cli_printMessage "`gettext "Checking changes in the working copy"`" --as-banner-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Build list of files that have received changes in its version
Alain Reguera Delgado 8f60cb
    # status.  Be sure to keep output files off from this list.
Alain Reguera Delgado 8f60cb
    # Remember, output files are not version inside the working copy,
Alain Reguera Delgado 8f60cb
    # so they are not considered for evaluation here. But take care,
Alain Reguera Delgado 8f60cb
    # sometimes output files are in the same format of source files,
Alain Reguera Delgado 8f60cb
    # so we need to differentiate them using their locations.
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Process location based on its path information.
Alain Reguera Delgado 8f60cb
    if [[ ${LOCATION} =~ 'Documentation/Manuals/Texinfo)' ]];then
Alain Reguera Delgado 8f60cb
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|txt|xhtml|xml|docbook|bz2)$')\n$STATUSOUT"
Alain Reguera Delgado 8f60cb
    elif [[ $LOCATION =~ 'Documentation/Manuals/Docbook' ]];then
Alain Reguera Delgado 8f60cb
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|txt|xhtml)$')\n$STATUSOUT"
Alain Reguera Delgado 8f60cb
    elif [[ $LOCATION =~ 'Identity' ]];then
Alain Reguera Delgado 8f60cb
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|png|jpg|rc|xpm|xbm|tif|ppm|pnm|gz|lss|log)$')\n$STATUSOUT"
Alain Reguera Delgado 8f60cb
    else
Alain Reguera Delgado 8f60cb
        STATUSOUT="$(${COMMAND} status ${LOCATION})\n$STATUSOUT"
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Sanitate status output. Expand new lines, remove leading spaces
Alain Reguera Delgado 8f60cb
    # and empty lines.
Alain Reguera Delgado 8f60cb
    STATUSOUT=$(echo -e "$STATUSOUT" | sed -r 's!^[[:space:]]*!!' | egrep -v '^[[:space:]]*$')
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define path to files considered recent modifications from
Alain Reguera Delgado 8f60cb
    # working copy up to central repository.
Alain Reguera Delgado 8f60cb
    FILES[0]=$(echo "$STATUSOUT" | egrep "^M"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
Alain Reguera Delgado 8f60cb
    FILES[1]=$(echo "$STATUSOUT" | egrep "^\?" | sed -r "s,^.+${TCAR_WORKDIR}/,,")
Alain Reguera Delgado 8f60cb
    FILES[2]=$(echo "$STATUSOUT" | egrep "^D"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
Alain Reguera Delgado 8f60cb
    FILES[3]=$(echo "$STATUSOUT" | egrep "^A"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # Define description of files considered recent modifications from
Alain Reguera Delgado 8f60cb
    # working copy up to central repository.
Alain Reguera Delgado 8f60cb
    INFO[0]="`gettext "Modified"`"
Alain Reguera Delgado 8f60cb
    INFO[1]="`gettext "Unversioned"`"
Alain Reguera Delgado 8f60cb
    INFO[2]="`gettext "Deleted"`"
Alain Reguera Delgado 8f60cb
    INFO[3]="`gettext "Added"`"
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    while [[ $COUNT -ne ${#FILES[*]} ]];do
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Define total number of files. Avoid counting empty line.
Alain Reguera Delgado 8f60cb
        if [[ "${FILES[$COUNT]}" == '' ]];then
Alain Reguera Delgado 8f60cb
            FILESNUM[$COUNT]=0
Alain Reguera Delgado 8f60cb
        else
Alain Reguera Delgado 8f60cb
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
Alain Reguera Delgado 8f60cb
        fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Calculate total amount of changes.
Alain Reguera Delgado 8f60cb
        CHNGTOTAL=$(($CHNGTOTAL + ${FILESNUM[$COUNT]}))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Build report predicate. Use report predicate to show any
Alain Reguera Delgado 8f60cb
        # information specific to the number of files found. For
Alain Reguera Delgado 8f60cb
        # example, you can use this section to show warning messages,
Alain Reguera Delgado 8f60cb
        # notes, and so on. By default we use the word `file' or
Alain Reguera Delgado 8f60cb
        # `files' at ngettext's consideration followed by change
Alain Reguera Delgado 8f60cb
        # direction.
Alain Reguera Delgado 8f60cb
        PREDICATE[$COUNT]=`ngettext "file in the working copy" \
Alain Reguera Delgado 8f60cb
            "files in the working copy" $((${FILESNUM[$COUNT]} + 1))`
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Output report line.
Alain Reguera Delgado 8f60cb
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" --as-stdout-line
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Increase counter.
Alain Reguera Delgado 8f60cb
        COUNT=$(($COUNT + 1))
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # When files have changed in the target location, show which these
Alain Reguera Delgado 8f60cb
    # files are and request user to see such changes and then, for
Alain Reguera Delgado 8f60cb
    # committing them up to the central repository.
Alain Reguera Delgado 8f60cb
    if [[ ${FILESNUM[0]} -gt 0 ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to see changes now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
        ${COMMAND} diff ${LOCATION} | less
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Commit changes up to central repository.
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
        ${COMMAND} commit ${LOCATION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # When there are unversioned files in the target location, show
Alain Reguera Delgado 8f60cb
    # which these files are and request user to add such files into
Alain Reguera Delgado 8f60cb
    # the working copy.
Alain Reguera Delgado 8f60cb
    if [[ ${FILESNUM[1]} -gt 0 ]];then
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        cli_printMessage '-' --as-separator-line
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to add unversioned files now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
        for FILE in ${FILES[1]};do
Alain Reguera Delgado 8f60cb
            ${COMMAND} add "${TCAR_WORKDIR}/$FILE"
Alain Reguera Delgado 8f60cb
        done
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
        # Commit changes up to central repository.
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
        ${COMMAND} commit ${LOCATION}
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
    # When there are added files in the target location, show which
Alain Reguera Delgado 8f60cb
    # these files are and request user to commit them up to central
Alain Reguera Delgado 8f60cb
    # repository.
Alain Reguera Delgado 8f60cb
    if [[ ${FILESNUM[3]} -gt 0 ]];then
Alain Reguera Delgado 8f60cb
        cli_printMessage '-' --as-separator-line
Alain Reguera Delgado 8f60cb
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
Alain Reguera Delgado 8f60cb
        ${COMMAND} commit ${LOCATION}
Alain Reguera Delgado 8f60cb
    fi
Alain Reguera Delgado 8f60cb
Alain Reguera Delgado 8f60cb
}