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
#
2a50d0
# Copyright (C) 2009-2011 Alain Reguera Delgado
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.
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=''
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
3071b7
    # Verify locations existence. It shoud exist as regular file or
3071b7
    # directory inside the repository working copy.
3071b7
    cli_checkFiles "$LOCATIONS" 'fd'
3071b7
    cli_checkFiles "$LOCATIONS" 'isInWorkingCopy'
55612a
ba0dfe
    # Outout separator line.
ba0dfe
    cli_printMessage '-' 'AsSeparatorLine'
ba0dfe
55612a
    # Check working copy.
58a639
    cli_printMessage "`gettext "Checking changes in the working copy"`" 'AsResponseLine'
55612a
    STATUSOUT=$(svn status ${LOCATIONS})
ba0dfe
ba0dfe
    # Outout separator line.
ba0dfe
    cli_printMessage '-' 'AsSeparatorLine'
d627b6
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" \
1ff118
            "files in the repository" $((${FILESNUM[$COUNT]} + 1))`
58a639
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
3071b7
    # In case new unversioned files exist, ask the user to add them
3071b7
    # into the repository. This may happen when new documentation
3071b7
    # entries are created.
3071b7
    if [[ ${FILESNUM[1]} -gt 0 ]];then
3036ea
3036ea
        # Outout separator line.
3036ea
        cli_printMessage '-' 'AsSeparatorLine'
3036ea
00f591
        cli_printMessage "`ngettext "The following file is unversioned" \
3071b7
            "The following files are unversioned" ${FILESNUM[1]}`:"
3071b7
        for FILE in ${FILES[1]};do
2ce3a5
            cli_printMessage $FILE 'AsResponseLine'
2ce3a5
        done
c4b35f
        cli_printMessage "`ngettext "Do you want to add it now?" \
3071b7
            "Do you want to add them now?" ${FILESNUM[2]}`" 'AsYesOrNoRequestLine'
3071b7
        svn add ${FILES[1]} --quiet
2ce3a5
    fi
2ce3a5
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.
3036ea
        cli_printMessage '-' 'AsSeparatorLine'
3036ea
d627b6
        # Verify changes.
4e4549
        cli_printMessage "`gettext "Do you want to see changes now?"`" "AsYesOrNoRequestLine"
3071b7
        svn diff ${FILES[*]} | less
d627b6
d627b6
        # Commit changes.
58a639
        cli_printMessage "`gettext "Do you want to commit changes now?"`" "AsYesOrNoRequestLine"
3071b7
        svn commit ${FILES[*]}
4e4549
d627b6
    fi
d627b6
d627b6
}