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

4debce
#!/bin/bash
4debce
#
3b9515
# subversion_commitRepoChanges.sh -- This function explores the
3b9515
# working copy and commits changes up to central repository after
3b9515
# checking changes and adding files which aren't under version
3b9515
# control.
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_commitRepoChanges {
4debce
4debce
    local -a FILES
4debce
    local -a INFO
4debce
    local -a FILESNUM
4debce
    local COUNT=0
4debce
    local STATUSOUT=''
4debce
    local PREDICATE=''
4debce
    local CHNGTOTAL=0
1690fd
    local LOCATION=$(cli_checkRepoDirSource "$1")
4debce
f7b539
    # Verify source location absolute path. It should point either to
f7b539
    # existent files or directories both under version control inside
f7b539
    # the working copy.  Otherwise, if it doesn't point to an existent
f7b539
    # file under version control, finish the script execution with an
f7b539
    # error message.
f7b539
    cli_checkFiles ${LOCATION} -e --is-versioned
f7b539
4debce
    # Print action message.
4debce
    cli_printMessage "`gettext "Checking changes in the working copy"`" --as-banner-line
4debce
819c26
    # Build list of files that have received changes in its version
4debce
    # status.  Be sure to keep output files off from this list.
819c26
    # Remember, output files are not version inside the working copy,
819c26
    # so they are not considered for evaluation here. But take care,
819c26
    # sometimes output files are in the same format of source files,
819c26
    # so we need to differentiate them using their locations.
4debce
0d9c14
    # Process location based on its path information.
819c26
    if [[ ${LOCATION} =~ 'Documentation/Manuals/Texinfo)' ]];then
3b9515
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|txt|xhtml|xml|docbook|bz2)$')\n$STATUSOUT"
819c26
    elif [[ $LOCATION =~ 'Documentation/Manuals/Docbook' ]];then
3b9515
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|txt|xhtml)$')\n$STATUSOUT"
819c26
    elif [[ $LOCATION =~ 'Identity' ]];then
3b9515
        STATUSOUT="$(${COMMAND} status ${LOCATION} | egrep -v '(pdf|png|jpg|rc|xpm|xbm|tif|ppm|pnm|gz|lss|log)$')\n$STATUSOUT"
0d9c14
    else
3b9515
        STATUSOUT="$(${COMMAND} status ${LOCATION})\n$STATUSOUT"
0d9c14
    fi
4debce
4debce
    # Sanitate status output. Expand new lines, remove leading spaces
4debce
    # and empty lines.
4debce
    STATUSOUT=$(echo -e "$STATUSOUT" | sed -r 's!^[[:space:]]*!!' | egrep -v '^[[:space:]]*$')
4debce
a3504f
    # Define path to files considered recent modifications from
4debce
    # working copy up to central repository.
a3504f
    FILES[0]=$(echo "$STATUSOUT" | egrep "^M"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
a3504f
    FILES[1]=$(echo "$STATUSOUT" | egrep "^\?" | sed -r "s,^.+${TCAR_WORKDIR}/,,")
a3504f
    FILES[2]=$(echo "$STATUSOUT" | egrep "^D"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
a3504f
    FILES[3]=$(echo "$STATUSOUT" | egrep "^A"  | sed -r "s,^.+${TCAR_WORKDIR}/,,")
4debce
4debce
    # Define description of files considered recent modifications from
4debce
    # working copy up to central repository.
4debce
    INFO[0]="`gettext "Modified"`"
4debce
    INFO[1]="`gettext "Unversioned"`"
4debce
    INFO[2]="`gettext "Deleted"`"
4debce
    INFO[3]="`gettext "Added"`"
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 in the working copy" \
4debce
            "files in the working copy" $((${FILESNUM[$COUNT]} + 1))`
4debce
4debce
        # Output report line.
1690fd
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" --as-stdout-line
4debce
4debce
        # Increase counter.
4debce
        COUNT=$(($COUNT + 1))
4debce
4debce
    done
4debce
807e1f
    # When files have changed in the target location, show which these
807e1f
    # files are and request user to see such changes and then, for
123ee8
    # committing them up to the central repository.
807e1f
    if [[ ${FILESNUM[0]} -gt 0 ]];then
4debce
807e1f
        cli_printMessage "`gettext "Do you want to see changes now?"`" --as-yesornorequest-line
3b9515
        ${COMMAND} diff ${LOCATION} | less
4debce
807e1f
        # Commit changes up to central repository.
807e1f
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
3b9515
        ${COMMAND} commit ${LOCATION}
4debce
807e1f
    fi
807e1f
807e1f
    # When there are unversioned files in the target location, show
807e1f
    # which these files are and request user to add such files into
807e1f
    # the working copy.
807e1f
    if [[ ${FILESNUM[1]} -gt 0 ]];then
807e1f
a3504f
        cli_printMessage '-' --as-separator-line
a3504f
        cli_printMessage "`gettext "Do you want to add unversioned files now?"`" --as-yesornorequest-line
807e1f
        for FILE in ${FILES[1]};do
3b9515
            ${COMMAND} add "${TCAR_WORKDIR}/$FILE"
807e1f
        done
4debce
807e1f
        # Commit changes up to central repository.
807e1f
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
3b9515
        ${COMMAND} commit ${LOCATION}
807e1f
807e1f
    fi
807e1f
807e1f
    # When there are added files in the target location, show which
807e1f
    # these files are and request user to commit them up to central
807e1f
    # repository.
807e1f
    if [[ ${FILESNUM[3]} -gt 0 ]];then
a3504f
        cli_printMessage '-' --as-separator-line
807e1f
        cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
3b9515
        ${COMMAND} commit ${LOCATION}
4debce
    fi
807e1f
4debce
}