Blame Scripts/Bash/Functions/Commons/cli_checkRepoDirSource.sh

878a2b
#!/bin/bash
878a2b
#
92f633
# cli_checkRepoDirSource.sh -- This function standardizes the path
92f633
# construction to directories inside the working copy, using absolute
92f633
# paths. This function transforms relative paths passed as non-option
92f633
# arguments to centos-art.sh script command-line into absolute paths
819c26
# inside the working copy based on whether you are using Subversion or
819c26
# Git as version control system. Further verifications, (e.g., whether
819c26
# they really exist as directories inside the working copy or not)
819c26
# should be realized outside this function.
a9ece5
#
819c26
# NOTE: Transforming relative paths into absolute paths before
819c26
# processing them is very useful when you need to execute the
819c26
# centos-art.sh script as command (e.g., `centos-art') anywhere
819c26
# inside the workstation.
a9ece5
#
a9ece5
# Use this function whenever you need to be sure that non-option
a9ece5
# arguments passed to centos-art.sh script command-line will always
a9ece5
# point to directories inside the working copy.
878a2b
#
e6bbbf
# Copyright (C) 2009-2013 The CentOS Project
878a2b
#
878a2b
# This program is free software; you can redistribute it and/or modify
878a2b
# it under the terms of the GNU General Public License as published by
878a2b
# the Free Software Foundation; either version 2 of the License, or (at
878a2b
# your option) any later version.
878a2b
#
878a2b
# This program is distributed in the hope that it will be useful, but
878a2b
# WITHOUT ANY WARRANTY; without even the implied warranty of
878a2b
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
878a2b
# General Public License for more details.
878a2b
#
878a2b
# You should have received a copy of the GNU General Public License
878a2b
# along with this program; if not, write to the Free Software
878a2b
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
878a2b
#
878a2b
# ----------------------------------------------------------------------
878a2b
# $Id$
878a2b
# ----------------------------------------------------------------------
878a2b
878a2b
function cli_checkRepoDirSource {
878a2b
893a6f
    local LOCATION=${1}
893a6f
123ee8
    # Remove any dot from arguments passed to centos-art.sh script.
123ee8
    # This way it is possible to use a single dot to reflect the
123ee8
    # current location from which centos-art.sh was executed. Notice
123ee8
    # that using a dot as argument is optional (e.g.: when you pass no
123ee8
    # argument to centos-art command-line, the current location is
123ee8
    # used as default location). However, it might be useful to use a
123ee8
    # dot as argument when you want to include the current location in
123ee8
    # a list of arguments to process.
123ee8
    LOCATION=$(echo "$LOCATION" | sed -r "s,^\.$,$(pwd),g")
123ee8
3b9515
    # Remove the working directory absolute path from location to
3b9515
    # avoid path duplications here.
3b9515
    LOCATION=$(echo "$LOCATION" | sed "s,${TCAR_WORKDIR}/,,g")
3b9515
9c43fe
    # When we use Git as version control system, there isn't a need of
9c43fe
    # using the `trunk', `branches', `tags' convention we were using
9c43fe
    # for Subversion.  The working copy begins directly with the
9c43fe
    # content of our repository (e.g., Documentation, Scripts,
9c43fe
    # Identity and Locales).
9c43fe
    #
819c26
    # When we use Subversion as version control system, we follow the
819c26
    # `trunk', `branches', `tags' convention to organize files inside
819c26
    # the repository and need to redefine the source path in order to
9c43fe
    # build the repository absolute path from the repository top level
9c43fe
    # on.  As convention, when you prepare your working copy through
9c43fe
    # centos-art.sh script, the absolute path to the `trunk/'
9c43fe
    # directory is used as working copy. This is, path arguments
9c43fe
    # provided to centos-art.sh script will be interpreted from trunk/
9c43fe
    # directory level on. For example, the following command should
9c43fe
    # work correctly in both Subversion and Git repositories:
819c26
    #
4f0fa2
    #   centos-art render Documentation/Manuals/Docbook/Tcar-ug
819c26
    #
819c26
    # There isn't a need of verifying the paths built here.  This is
819c26
    # something we do later, using the cli_checkFiles function. We
819c26
    # don't do the file verification here to avoid malformed error
819c26
    # messages when we reassign variable values using this function as
9c43fe
    # reference (e.g., in order to prevent error messages from being
819c26
    # stored inside variables.).
819c26
    LOCATION=${TCAR_WORKDIR}/${LOCATION}
878a2b
819c26
    # Output the absolute path to location.
5a1b27
    echo "${LOCATION}"
819c26
878a2b
}