|
|
d627b6 |
#!/bin/bash
|
|
|
d627b6 |
#
|
|
|
4e4549 |
# cli_commitRepoChanges.sh -- This function looks for revision changes
|
|
|
640f58 |
# inside absolute path passed as action value and ask you to commit
|
|
|
640f58 |
# them up to central repository. Use this function before or after
|
|
|
640f58 |
# whatever function that makes changes to files inside the working
|
|
|
640f58 |
# copy. It 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=''
|
|
|
b3ea32 |
local CHNGTOTAL=0
|
|
|
ae2995 |
local LOCATION=''
|
|
|
d627b6 |
|
|
|
640f58 |
# If the first argument is provided to cli_commitRepoChanges is a
|
|
|
ae2995 |
# valid regular file or directory, use the first argument as path
|
|
|
ae2995 |
# location to work with. If first argument is not a file, nor a
|
|
|
ae2995 |
# directory, or simply is not provided, the ACTIONVAL variable
|
|
|
ae2995 |
# default value is used instead.
|
|
|
640f58 |
if [[ -f "$1" || -d "$1" ]];then
|
|
|
ae2995 |
LOCATION="$1"
|
|
|
ae2995 |
else
|
|
|
ae2995 |
LOCATION="$ACTIONVAL"
|
|
|
640f58 |
fi
|
|
|
640f58 |
|
|
|
4e4549 |
# Update working copy.
|
|
|
4e4549 |
echo '----------------------------------------------------------------------'
|
|
|
58a639 |
cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" 'AsResponseLine'
|
|
|
ae2995 |
UPDATEOUT=$(svn update ${LOCATION})
|
|
|
58a639 |
|
|
|
58a639 |
# Check working copy status.
|
|
|
58a639 |
cli_printMessage "`gettext "Checking changes in the working copy"`" 'AsResponseLine'
|
|
|
ae2995 |
STATUSOUT=$(svn status ${LOCATION})
|
|
|
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)
|
|
|
640f58 |
FILES[8]=$(echo "$STATUSOUT" | egrep '^A' | 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"`"
|
|
|
640f58 |
INFO[6]="`gettext "Unversioned"`"
|
|
|
58a639 |
INFO[7]=${INFO[1]}
|
|
|
640f58 |
INFO[8]=${INFO[0]}
|
|
|
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 |
|
|
|
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.
|
|
|
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 |
|
|
|
b3ea32 |
# Check total amount of changes. If there is no change, there is
|
|
|
b3ea32 |
# nothing more to do here except to return flow control to this
|
|
|
b3ea32 |
# function caller.
|
|
|
b3ea32 |
if [[ $CHNGTOTAL -eq 0 ]];then
|
|
|
b3ea32 |
return 0
|
|
|
b3ea32 |
fi
|
|
|
b3ea32 |
|
|
|
2ce3a5 |
# In case new unversioned files exist, ask user to add them into
|
|
|
2ce3a5 |
# the repository. This may happen when new documentation entries
|
|
|
2ce3a5 |
# are created.
|
|
|
2ce3a5 |
if [[ ${FILESNUM[6]} -gt 0 ]];then
|
|
|
00f591 |
cli_printMessage "`ngettext "The following file is unversioned" \
|
|
|
00f591 |
"The following files are unversioned" ${FILESNUM[6]}`:"
|
|
|
00f591 |
for FILE in ${FILES[6]};do
|
|
|
2ce3a5 |
cli_printMessage $FILE 'AsResponseLine'
|
|
|
2ce3a5 |
done
|
|
|
c4b35f |
cli_printMessage "`ngettext "Do you want to add it now?" \
|
|
|
c4b35f |
"Do you want to add them now?" ${FILESNUM[6]}`" 'AsYesOrNoRequestLine'
|
|
|
52155a |
svn add ${FILES[6]} --quiet
|
|
|
2ce3a5 |
fi
|
|
|
2ce3a5 |
|
|
|
b3ea32 |
# Reset counter.
|
|
|
b3ea32 |
COUNT=0
|
|
|
58a639 |
|
|
|
58a639 |
# Unify local changes into a common variable so common actions can
|
|
|
58a639 |
# be applied to them.
|
|
|
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 |
}
|