Blame Scripts/Bash/Functions/cli_commitRepoChanges.sh

d627b6
#!/bin/bash
d627b6
#
4e4549
# cli_commitRepoChanges.sh -- This function looks for revision changes
4e4549
# inside absolute path passed as option value and ask you to commit
4e4549
# them up to central repository. Use this function at the end of
4e4549
# whatever function that makes changes to the working copy files. It
4e4549
# is better to commit small changes than long ones.
d627b6
#
d627b6
# Copyright (C) 2009-2010 Alain Reguera Delgado
d627b6
# 
d627b6
# This program is free software; you can redistribute it and/or modify
d627b6
# it under the terms of the GNU General Public License as published by
d627b6
# the Free Software Foundation; either version 2 of the License, or
d627b6
# (at your option) any later version.
d627b6
# 
d627b6
# This program is distributed in the hope that it will be useful, but
d627b6
# 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
d627b6
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
d627b6
# USA.
d627b6
# 
d627b6
# ----------------------------------------------------------------------
d627b6
# $Id$
d627b6
# ----------------------------------------------------------------------
d627b6
d627b6
function cli_commitRepoChanges {
d627b6
4e4549
    local -a FILES
4e4549
    local -a INFO
4e4549
    local -a FILESNUM
d627b6
    local COUNT=0
4e4549
    local UPDATEOUT=''
4e4549
    local PREDICATE=''
d627b6
4e4549
    # Update working copy.
4e4549
    echo '----------------------------------------------------------------------'
4e4549
    cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`"
4e4549
    UPDATEOUT=$(svn update ${OPTIONVAL})
4e4549
    echo '----------------------------------------------------------------------'
d627b6
4e4549
    # Define path of files considered recent modifications from
4e4549
    # central repository to working copy.
4e4549
    FILES[0]=$(echo "$UPDATEOUT" | egrep '^A' | cut -d' ' -f7)
4e4549
    FILES[1]=$(echo "$UPDATEOUT" | egrep '^D' | cut -d' ' -f7)
4e4549
    FILES[2]=$(echo "$UPDATEOUT" | egrep '^U' | cut -d' ' -f7)
4e4549
    FILES[3]=$(echo "$UPDATEOUT" | egrep '^C' | cut -d' ' -f7)
4e4549
    FILES[4]=$(echo "$UPDATEOUT" | egrep '^G' | cut -d' ' -f7)
4e4549
    FILES[5]=$(svn status "$OPTIONVAL" | egrep '^M' | cut -d' ' -f7)
d627b6
4e4549
    # Define description of files considered recent modifications from
4e4549
    # central repository to working copy.
4e4549
    INFO[0]="`gettext "Added"`"
4e4549
    INFO[1]="`gettext "Deleted"`"
4e4549
    INFO[2]="`gettext "Updated"`"
4e4549
    INFO[3]="`gettext "Conflicted"`"
4e4549
    INFO[4]="`gettext "Merged"`"
4e4549
    INFO[5]="`gettext "Modified"`"
d627b6
4e4549
    while [[ $COUNT -ne ${#FILES[*]} ]];do
d627b6
4e4549
        # Get total number of files. Avoid counting empty line.
4e4549
        if [[ ${FILES[$COUNT]} == '' ]];then
4e4549
            FILESNUM[$COUNT]=0
4e4549
        else
4e4549
            FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l)
4e4549
        fi
4e4549
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,
4e4549
        # notes, and so on. By default we just output the word `file'
4e4549
        # or `files' at ngettext's consideration.
4e4549
        if [[ ${FILESNUM[$COUNT]} -lt 1 ]];then
4e4549
            PREDICATE[$COUNT]=''
4e4549
        else
4e4549
            PREDICATE[$COUNT]=`ngettext "file" "files" ${FILESNUM[$COUNT]}`
4e4549
        fi
4e4549
4e4549
        # Output report line.
4e4549
        cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" 'AsRegularLine'
4e4549
4e4549
        # Increase counter.
4e4549
        COUNT=$(($COUNT + 1))
4e4549
4e4549
    done
4e4549
4e4549
    echo '----------------------------------------------------------------------'
4e4549
4e4549
    # Check list of changed files. If there are changes in the working
4e4549
    # copy, ask the user to verify, and later, commit them up to
4e4549
    # central repository.
4e4549
    if [[ ${FILESNUM[5]} -gt 0 ]];then
d627b6
d627b6
        # Verify changes.
4e4549
        cli_printMessage "`gettext "Do you want to see changes now?"`" "AsYesOrNoRequestLine"
4e4549
        svn diff ${FILES[5]} | less
d627b6
d627b6
        # Commit changes.
4e4549
        cli_printMessage "`gettext "Do you want commit changes now?"`" "AsYesOrNoRequestLine"
4e4549
        svn commit ${FILES[5]}
4e4549
d627b6
    fi
d627b6
d627b6
}