Blame Scripts/Bash/Functions/cli_getRepoStatus.sh

c8faf4
#!/bin/bash
c8faf4
#
c8faf4
# cli_getRepoStatus.sh -- This function requests the working copy
c8faf4
# using the `svn status' command to return the first character on each
c8faf4
# output line, as described in `svn help status`. Use this function to
c8faf4
# know which status, the first argument passed to this function, has.
c8faf4
#
c8faf4
# Copyright (C) 2009, 2010 Alain Reguera Delgado
c8faf4
# 
c8faf4
# This program is free software; you can redistribute it and/or
c8faf4
# modify it under the terms of the GNU General Public License as
c8faf4
# published by the Free Software Foundation; either version 2 of the
c8faf4
# License, or (at your option) any later version.
c8faf4
# 
c8faf4
# This program is distributed in the hope that it will be useful, but
c8faf4
# WITHOUT ANY WARRANTY; without even the implied warranty of
c8faf4
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c8faf4
# General Public License for more details.
c8faf4
#
c8faf4
# You should have received a copy of the GNU General Public License
c8faf4
# along with this program; if not, write to the Free Software
c8faf4
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
c8faf4
# USA.
c8faf4
# 
c8faf4
# ----------------------------------------------------------------------
c8faf4
# $Id$
c8faf4
# ----------------------------------------------------------------------
c8faf4
c8faf4
function cli_getRepoStatus {
c8faf4
c8faf4
    local FILE="$1"
c8faf4
    local STATUS=''
c8faf4
2120de
    # Define regular expression pattern to retrive first column,
2120de
    # returned by subversion status command. This column is one
2120de
    # character column as describes `svn help status' command.
2120de
    local PATTERN="^( |A|C|D|I|M|R|X|\?|!|~]).+$"
2120de
c8faf4
    # Verify the file used as source to retrive its status
c8faf4
    # information. We only use regular files or directories inside the
c8faf4
    # working copy.
c8faf4
    cli_checkFiles "$FILE" 'fd'
c8faf4
c8faf4
    # Use subversion `status' command to retrive the first character
c8faf4
    # in the output.
2120de
    STATUS="$(svn status "$FILE" --quiet | sed -r "s/${PATTER}/\1/")"
2120de
2120de
    # Sanitate status output.
2120de
    if [[ "$STATUS" == '' ]];then
2120de
        # If status is empty, there is no output error and we assume
2120de
        # file being checked doesn't have changes either, so redefine
2120de
        # status as `no modification'.
2120de
        STATUS=' '
2120de
    elif [[ ! "$STATUS" =~ "$PATTERN" ]];then
2120de
        # If status doesn't match the regular expression pattern
2120de
        # defined previusly, we assume file being checked is not under
2120de
        # version control, so we redefine status as `item is not under
2120de
        # version control'.
2120de
        STATUS='?'
2120de
    fi
c8faf4
c8faf4
    # Outout status information.
c8faf4
    echo -n "$STATUS"
c8faf4
c8faf4
}