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

123ee8
#!/bin/bash
123ee8
#
123ee8
# git_deleteRepoFile.sh -- This function standardizes the way
123ee8
# centos-art.sh script deletes files and directories inside the
123ee8
# working copy.
123ee8
#
e6bbbf
# 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_deleteRepoFile {
123ee8
123ee8
    local TARGET=$(cli_checkRepoDirSource ${1})
123ee8
123ee8
    # Print action reference.
123ee8
    cli_printMessage "${TARGET}" --as-deleting-line
123ee8
123ee8
    # Reset target to its default status before remove it from the
123ee8
    # work copy.
123ee8
    if [[ $(cli_runFnEnvironment vcs --status ${TARGET}) =~ '^(A|M|R)$' ]];then
123ee8
        ${COMMAND} reset HEAD ${TARGET} --quiet
123ee8
    fi
123ee8
123ee8
    # Remove target based on whether it is under version control or
123ee8
    # not.
de6ddf
    if [[ $(cli_runFnEnvironment vcs --status ${TARGET}) =~ '^\?\?$' ]];then
123ee8
        # Target isn't under version control.
123ee8
        if [[ -d ${TARGET} ]];then
123ee8
            rm -r ${TARGET}
123ee8
        else
123ee8
            rm ${TARGET} 
123ee8
        fi 
123ee8
    else
123ee8
        # Target is under version control.
123ee8
        if [[ -d ${TARGET} ]];then
123ee8
            ${COMMAND} rm ${TARGET} -r --force --quiet
123ee8
        else
123ee8
            ${COMMAND} rm ${TARGET} --force --quiet
123ee8
        fi 
123ee8
    fi
123ee8
123ee8
}