Blame Scripts/Bash/Functions/Svn/svn_commitRepoChanges.sh

4debce
#!/bin/bash
4debce
#
807e1f
# svn_commitRepoChanges.sh -- This function explores the working copy
807e1f
# and commits changes up to central repository after checking changes
807e1f
# and adding unversioned files.
4debce
#
4debce
# Copyright (C) 2009, 2010, 2011, 2012 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
4debce
function svn_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
4debce
    # Print action message.
4debce
    cli_printMessage "`gettext "Checking changes in the working copy"`" --as-banner-line
4debce
4debce
    # Build list of files that have received changes in its versioned
4debce
    # status.  Be sure to keep output files off from this list.
4debce
    # Remember, output files are not versioned inside the working
4debce
    # copy, so they are not considered for evaluation here. But take
4debce
    # care, sometimes output files are in the same format of source
4debce
    # files, so we need to differentiate them using their locations.
4debce
0d9c14
    # Process location based on its path information.
1690fd
    if [[ ${LOCATION} =~ 'trunk/Documentation/Manuals/Texinfo)' ]];then
1690fd
        STATUSOUT="$(${SVN} status ${LOCATION} | egrep -v '(pdf|txt|xhtml|xml|docbook|bz2)$')\n$STATUSOUT"
1690fd
    elif [[ $LOCATION =~ 'trunk/Documentation/Manuals/Docbook' ]];then
1690fd
        STATUSOUT="$(${SVN} status ${LOCATION} | egrep -v '(pdf|txt|xhtml)$')\n$STATUSOUT"
1690fd
    elif [[ $LOCATION =~ 'trunk/Identity' ]];then
1690fd
        STATUSOUT="$(${SVN} status ${LOCATION} | egrep -v '(pdf|png|jpg|rc|xpm|xbm|tif|ppm|pnm|gz|lss|log)$')\n$STATUSOUT"
0d9c14
    else
1690fd
        STATUSOUT="$(${SVN} 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
807e1f
    # commtting 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
1690fd
        ${SVN} 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
1690fd
        ${SVN} 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
a3504f
            ${SVN} 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
1690fd
        ${SVN} 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
1690fd
        ${SVN} commit ${LOCATION}
4debce
    fi
807e1f
4debce
}