Blame Scripts/Bash/Functions/Vcs/Git/git_isVersioned.sh

123ee8
#!/bin/bash
123ee8
#
123ee8
# git_isVersioned.sh -- This function determines whether a location is
123ee8
# under version control or not. When the location is under version
123ee8
# control, this function returns `0'. When the location isn't under
123ee8
# version control, this function returns `1'.
123ee8
#
123ee8
# Copyright (C) 2009-2013 The CentOS Project
123ee8
#
123ee8
# This program is free software; you can redistribute it and/or modify
123ee8
# it under the terms of the GNU General Public License as published by
123ee8
# the Free Software Foundation; either version 2 of the License, or (at
123ee8
# your option) any later version.
123ee8
#
123ee8
# This program is distributed in the hope that it will be useful, but
123ee8
# WITHOUT ANY WARRANTY; without even the implied warranty of
123ee8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
123ee8
# General Public License for more details.
123ee8
#
123ee8
# You should have received a copy of the GNU General Public License
123ee8
# along with this program; if not, write to the Free Software
123ee8
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
123ee8
#
123ee8
# ----------------------------------------------------------------------
123ee8
# $Id$
123ee8
# ----------------------------------------------------------------------
123ee8
123ee8
function git_isVersioned {
123ee8
123ee8
    # Define the location absolute path we want to determine whether
123ee8
    # it is under version control or not. Only the first non-option
123ee8
    # argument passed to centos-art.sh command-line will be used.
123ee8
    local LOCATION=$(cli_checkRepoDirSource "${1}")
123ee8
123ee8
    # Use Git to determine whether the location is under version
123ee8
    # control or not.
123ee8
    local OUTPUT=$(${COMMAND} status --porcelain ${LOCATION} \
123ee8
        | egrep "\?\? ${LOCATION}")
123ee8
123ee8
    # If there are unversioned files inside location, stop the script
123ee8
    # execution with an error message. All files must be under version
123ee8
    # control except those set in the `.git/info/exclude/' file.
123ee8
    if [[ ! -z ${OUTPUT} ]];then
123ee8
        cli_printMessage "${LOCATION} `gettext " contains untracked files."`" --as-error-line
123ee8
    fi
123ee8
123ee8
}