|
|
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 |
#
|
|
|
7cd8e9 |
# Copyright (C) 2009, 2010 Alain Reguera Delgado
|
|
|
d627b6 |
#
|
|
|
7cd8e9 |
# This program is free software; you can redistribute it and/or
|
|
|
7cd8e9 |
# modify it under the terms of the GNU General Public License as
|
|
|
7cd8e9 |
# published by the Free Software Foundation; either version 2 of the
|
|
|
7cd8e9 |
# License, or (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=''
|
|
|
58a639 |
local LOCALFILES=''
|
|
|
58a639 |
local CHNGDIRECTION=''
|
|
|
d627b6 |
|
|
|
4e4549 |
# Update working copy.
|
|
|
4e4549 |
echo '----------------------------------------------------------------------'
|
|
|
58a639 |
cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" 'AsResponseLine'
|
|
|
4e4549 |
UPDATEOUT=$(svn update ${OPTIONVAL})
|
|
|
58a639 |
|
|
|
58a639 |
# Check working copy status.
|
|
|
58a639 |
cli_printMessage "`gettext "Checking changes in the working copy"`" 'AsResponseLine'
|
|
|
58a639 |
STATUSOUT=$(svn status ${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)
|
|
|
58a639 |
|
|
|
58a639 |
# Define path fo files considered recent modifications from
|
|
|
58a639 |
# working copy up to central repository.
|
|
|
58a639 |
FILES[5]=$(echo "$STATUSOUT" | egrep '^M' | cut -d' ' -f7)
|
|
|
58a639 |
FILES[6]=$(echo "$STATUSOUT" | egrep '^\?' | cut -d' ' -f7)
|
|
|
58a639 |
FILES[7]=$(echo "$STATUSOUT" | egrep '^D' | 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"`"
|
|
|
58a639 |
|
|
|
58a639 |
# Define description of files considered recent modifications from
|
|
|
58a639 |
# working copy up to central repository.
|
|
|
4e4549 |
INFO[5]="`gettext "Modified"`"
|
|
|
58a639 |
INFO[6]=${INFO[0]}
|
|
|
58a639 |
INFO[7]=${INFO[1]}
|
|
|
d627b6 |
|
|
|
4e4549 |
while [[ $COUNT -ne ${#FILES[*]} ]];do
|
|
|
d627b6 |
|
|
|
4e4549 |
# Get 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 |
|
|
|
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.
|
|
|
4e4549 |
if [[ ${FILESNUM[$COUNT]} -lt 1 ]];then
|
|
|
58a639 |
PREDICATE[$COUNT]=`gettext "file"`
|
|
|
4e4549 |
else
|
|
|
4e4549 |
PREDICATE[$COUNT]=`ngettext "file" "files" ${FILESNUM[$COUNT]}`
|
|
|
4e4549 |
fi
|
|
|
4e4549 |
|
|
|
58a639 |
# Redefine report predicate to add direction of changes.
|
|
|
58a639 |
if [[ $COUNT -le 4 ]]; then
|
|
|
58a639 |
# Consider recent modifications from central repository
|
|
|
58a639 |
# down to working copy.
|
|
|
58a639 |
CHNGDIRECTION="`gettext "from the repository."`"
|
|
|
58a639 |
elif [[ $COUNT -gt 4 ]];then
|
|
|
58a639 |
# Consider recent modifications from working copy up to
|
|
|
58a639 |
# central repository.
|
|
|
58a639 |
CHNGDIRECTION="`gettext "from the working copy."`"
|
|
|
58a639 |
fi
|
|
|
58a639 |
|
|
|
58a639 |
# Redefine report predicate using change direction.
|
|
|
58a639 |
PREDICATE[$COUNT]="${PREDICATE[$COUNT]} ${CHNGDIRECTION}"
|
|
|
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 |
|
|
|
4e4549 |
echo '----------------------------------------------------------------------'
|
|
|
4e4549 |
|
|
|
58a639 |
# Check list of local additions. If there are unversioned files in
|
|
|
58a639 |
# the working copy, mark them all as local additions so they can
|
|
|
58a639 |
# be sent up to central repository the next time a commit action
|
|
|
58a639 |
# be performed. As convenction, all file manipulations inside the
|
|
|
58a639 |
# working copy must be done with versioned files, and so, using
|
|
|
58a639 |
# subversion commands.
|
|
|
58a639 |
if [[ ${FILESNUM[6]} -gt 0 ]];then
|
|
|
58a639 |
svn add ${FILES[6]} --quiet
|
|
|
58a639 |
fi
|
|
|
58a639 |
|
|
|
58a639 |
# Unify local changes into a common variable so common actions can
|
|
|
58a639 |
# be applied to them.
|
|
|
58a639 |
COUNT=0
|
|
|
58a639 |
while [[ $COUNT -ne ${#FILES[*]} ]];do
|
|
|
58a639 |
LOCALFILES="$LOCALFILES ${FILES[$COUNT]}"
|
|
|
58a639 |
COUNT=$(($COUNT + 1 ))
|
|
|
58a639 |
done
|
|
|
58a639 |
|
|
|
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.
|
|
|
58a639 |
if [[ $LOCALFILES != '' ]];then
|
|
|
d627b6 |
|
|
|
d627b6 |
# Verify changes.
|
|
|
4e4549 |
cli_printMessage "`gettext "Do you want to see changes now?"`" "AsYesOrNoRequestLine"
|
|
|
58a639 |
svn diff $LOCALFILES | less
|
|
|
d627b6 |
|
|
|
d627b6 |
# Commit changes.
|
|
|
58a639 |
cli_printMessage "`gettext "Do you want to commit changes now?"`" "AsYesOrNoRequestLine"
|
|
|
58a639 |
svn commit $LOCALFILES
|
|
|
4e4549 |
|
|
|
d627b6 |
fi
|
|
|
d627b6 |
|
|
|
d627b6 |
}
|