Blame Scripts/Bash/Functions/Commons/cli_commitRepoChanges.sh

878a2b
#!/bin/bash
878a2b
#
878a2b
# cli_commitRepoChanges.sh -- This function realizes a subversion
878a2b
# commit command agains the workgin copy in order to send local
878a2b
# changes up to central repository.
878a2b
#
03486a
# Copyright (C) 2009, 2010, 2011, 2012 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function cli_commitRepoChanges {
878a2b
878a2b
    # Verify `--dont-commit-changes' option.
878a2b
    if [[ $FLAG_DONT_COMMIT_CHANGES == 'true' ]];then
878a2b
        return
878a2b
    fi
878a2b
878a2b
    local -a FILES
878a2b
    local -a INFO
878a2b
    local -a FILESNUM
878a2b
    local COUNT=0
878a2b
    local STATUSOUT=''
878a2b
    local PREDICATE=''
878a2b
    local CHNGTOTAL=0
878a2b
    local LOCATIONS=''
878a2b
    local LOCATION=''
878a2b
878a2b
    # Define source location the subversion status action will take
878a2b
    # place on. If arguments are provided use them as srouce location.
878a2b
    # Otherwise use action value as default source location.
878a2b
    if [[ "$@" != '' ]];then
878a2b
        LOCATIONS="$@"
878a2b
    else
878a2b
        LOCATIONS="$ACTIONVAL"
878a2b
    fi
878a2b
878a2b
    # Print action message.
878a2b
    cli_printMessage "`gettext "Checking changes in the working copy"`" --as-banner-line
878a2b
878a2b
    # Build list of files that have received changes in its versioned
878a2b
    # status.  Be sure to keep output files off from this list.
878a2b
    # Remember, output files are not versioned inside the working
878a2b
    # copy, so they are not considered for evaluation here. But take
878a2b
    # care, sometimes output files are in the same format of source
878a2b
    # files, so we need to differentiate them using their locations.
878a2b
    for LOCATION in $LOCATIONS;do
878a2b
878a2b
        # Don't process location outside of version control.
878a2b
        if [[ $(cli_isVersioned $LOCATION) == 'false' ]];then
878a2b
            continue
878a2b
        fi
878a2b
878a2b
        # Process location based on its path information.
878a2b
        if [[ $LOCATION =~ '(trunk/Manuals/Tcar-fs|branches/Manuals/Texinfo)' ]];then
878a2b
            STATUSOUT="$(svn status ${LOCATION} | egrep -v '(pdf|txt|xhtml|xml|docbook|bz2)$')\n$STATUSOUT"
878a2b
        elif [[ $LOCATION =~ 'trunk/Manuals' ]];then
878a2b
            STATUSOUT="$(svn status ${LOCATION} | egrep -v '(pdf|txt|xhtml)$')\n$STATUSOUT"
878a2b
        elif [[ $LOCATION =~ 'trunk/Identity' ]];then
878a2b
            STATUSOUT="$(svn status ${LOCATION} | egrep -v '(pdf|png|jpg|rc|xpm|xbm|tif|ppm|pnm|gz|lss|log)$')\n$STATUSOUT"
878a2b
        else
878a2b
            STATUSOUT="$(svn status ${LOCATION})\n$STATUSOUT"
878a2b
        fi
878a2b
878a2b
    done
878a2b
878a2b
    # Sanitate status output. Expand new lines, remove leading spaces
878a2b
    # and empty lines.
878a2b
    STATUSOUT=$(echo -e "$STATUSOUT" | sed -r 's!^[[:space:]]*!!' | egrep -v '^[[:space:]]*$')
878a2b
878a2b
    # Define path fo files considered recent modifications from
878a2b
    # working copy up to central repository.
878a2b
    FILES[0]=$(echo "$STATUSOUT" | egrep "^M.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[1]=$(echo "$STATUSOUT" | egrep "^\?.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[2]=$(echo "$STATUSOUT" | egrep "^D.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
    FILES[3]=$(echo "$STATUSOUT" | egrep "^A.+$(cli_getRepoTLDir "${LOCATIONS}").+$" | sed -r "s,^.+($(cli_getRepoTLDir "${LOCATIONS}").+)$,\1,")
878a2b
878a2b
    # Define description of files considered recent modifications from
878a2b
    # working copy up to central repository.
878a2b
    INFO[0]="`gettext "Modified"`"
878a2b
    INFO[1]="`gettext "Unversioned"`"
878a2b
    INFO[2]="`gettext "Deleted"`"
878a2b
    INFO[3]="`gettext "Added"`"
878a2b
878a2b
    while [[ $COUNT -ne ${#FILES[*]} ]];do
878a2b
878a2b
        # Define total number of files. Avoid counting empty line.
878a2b
        if [[ "${FILES[$COUNT]}" == '' ]];then
878a2b
            FILESNUM[$COUNT]=0
878a2b
        else
878a2b
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
878a2b
        fi
878a2b
878a2b
        # Calculate total amount of changes.
878a2b
        CHNGTOTAL=$(($CHNGTOTAL + ${FILESNUM[$COUNT]}))
878a2b
878a2b
        # Build report predicate. Use report predicate to show any
878a2b
        # information specific to the number of files found. For
878a2b
        # example, you can use this section to show warning messages,
878a2b
        # notes, and so on. By default we use the word `file' or
878a2b
        # `files' at ngettext's consideration followed by change
878a2b
        # direction.
878a2b
        PREDICATE[$COUNT]=`ngettext "file in the working copy" \
878a2b
            "files in the working copy" $((${FILESNUM[$COUNT]} + 1))`
878a2b
878a2b
        # Output report line.
878a2b
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}"
878a2b
878a2b
        # Increase counter.
878a2b
        COUNT=$(($COUNT + 1))
878a2b
878a2b
    done
878a2b
878a2b
    # Check total amount of changes and, if any, check differences and
878a2b
    # commit them up to central repository.
878a2b
    if [[ $CHNGTOTAL -gt 0 ]];then
878a2b
878a2b
        # Outout separator line.
878a2b
        cli_printMessage '-' --as-separator-line
878a2b
878a2b
        # In the very specific case unversioned files, we need to add
878a2b
        # them to the repository first, in order to make them
878a2b
        # available for subversion commands (e.g., `copy') Otherwise,
878a2b
        # if no unversioned file is found, go ahead with change
878a2b
        # differences and committing. Notice that if there is mix of
878a2b
        # changes (e.g., aditions and modifications), addition take
878a2b
        # preference and no other change is considered.  In order
878a2b
        # for other changes to be considered, be sure no adition is
878a2b
        # present, or that they have already happened.
878a2b
        if [[ ${FILESNUM[1]} -gt 0 ]];then
878a2b
878a2b
            cli_printMessage "`ngettext "The following file is unversioned" \
878a2b
                "The following files are unversioned" ${FILESNUM[1]}`:"
878a2b
            for FILE in ${FILES[1]};do
878a2b
                cli_printMessage "$FILE" --as-response-line
878a2b
            done
878a2b
            cli_printMessage "`ngettext "Do you want to add it now?" \
878a2b
                "Do you want to add them now?" ${FILESNUM[1]}`" --as-yesornorequest-line
878a2b
            svn add ${FILES[1]} --quiet
878a2b
878a2b
        else
878a2b
878a2b
            # Verify changes on locations.
878a2b
            cli_printMessage "`gettext "Do you want to see changes now?"`" --as-yesornorequest-line
878a2b
            svn diff $LOCATIONS | less
878a2b
878a2b
            # Commit changes on locations.
878a2b
            cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line
878a2b
            svn commit $LOCATIONS
878a2b
878a2b
        fi
878a2b
878a2b
    fi
878a2b
878a2b
}