Blame Scripts/Functions/cli_commitRepoChanges.sh

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