diff --git a/Scripts/Bash/Functions/Vcs/Git/git.sh b/Scripts/Bash/Functions/Vcs/Git/git.sh index b272da8..0f6bdd5 100755 --- a/Scripts/Bash/Functions/Vcs/Git/git.sh +++ b/Scripts/Bash/Functions/Vcs/Git/git.sh @@ -37,6 +37,13 @@ function git { # to fail when indeed is should not. Thus, go to action names # processing directly. + # All git actions will be performed against the working copy. + # Otherwise, errors like `fatal: Not a git repository (or any of + # the parent directories): .git' or `Unable to determine absolute + # path of git directory' might occur. So, move from whenever you + # be right now up to the git working copy. + pushd ${TCAR_WORKDIR} > /dev/null + # Execute action names. This is required in order to realize # actions like copy and rename which need two values as argument. # Otherwise, it wouldn't be possible to execute them because @@ -46,4 +53,7 @@ function git { $ACTIONNAM "$@" done + # Return to the place you were initially. + popd > /dev/null + } diff --git a/Scripts/Bash/Functions/Vcs/Git/git_commitRepoChanges.sh b/Scripts/Bash/Functions/Vcs/Git/git_commitRepoChanges.sh index bc483e8..f965966 100755 --- a/Scripts/Bash/Functions/Vcs/Git/git_commitRepoChanges.sh +++ b/Scripts/Bash/Functions/Vcs/Git/git_commitRepoChanges.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# git_commitRepoChanges.sh -- This function commits all the changes -# found in files under version control. +# git_commitRepoChanges.sh -- This function standardizes the way local +# changes are committed up to central repository. # # Copyright (C) 2009-2013 The CentOS Project # @@ -32,7 +32,7 @@ function git_commitRepoChanges { local STATUSOUT='' local PREDICATE='' local CHNGTOTAL=0 - local LOCATION=$(cli_checkRepoDirSource "$1") + local LOCATION=$(cli_checkRepoDirSource "${1}") # Verify source location absolute path. It should point to # existent files or directories. They don't need to be under @@ -56,17 +56,19 @@ function git_commitRepoChanges { # Define path to files considered recent modifications from # working copy up to local repository. - FILES[0]=$(echo "$STATUSOUT" | egrep "^.M" | sed -r "s,^.+${TCAR_WORKDIR}/,,") - FILES[1]=$(echo "$STATUSOUT" | egrep "^.\?" | sed -r "s,^.+${TCAR_WORKDIR}/,,") - FILES[2]=$(echo "$STATUSOUT" | egrep "^.D" | sed -r "s,^.+${TCAR_WORKDIR}/,,") - FILES[3]=$(echo "$STATUSOUT" | egrep "^.A" | sed -r "s,^.+${TCAR_WORKDIR}/,,") + FILES[0]=$(echo "$STATUSOUT" | egrep "^[[:space:]]M") + FILES[1]=$(echo "$STATUSOUT" | egrep "^\?\?") + FILES[2]=$(echo "$STATUSOUT" | egrep "^[[:space:]]D") + FILES[3]=$(echo "$STATUSOUT" | egrep "^[[:space:]]A") + FILES[4]=$(echo "$STATUSOUT" | egrep "^(A|M|R|C)( |M|D)") # Define description of files considered recent modifications from # working copy up to local repository. INFO[0]="`gettext "Modified"`" - INFO[1]="`gettext "Unversioned"`" + INFO[1]="`gettext "Untracked"`" INFO[2]="`gettext "Deleted"`" INFO[3]="`gettext "Added"`" + INFO[4]="`gettext "Staged"`" while [[ $COUNT -ne ${#FILES[*]} ]];do @@ -97,57 +99,20 @@ function git_commitRepoChanges { done - # When files have changed in the target location, show which these - # files are and request user to see such changes and then, for - # committing them up to the local repository. - if [[ ${FILESNUM[0]} -gt 0 ]];then + # Stage files + cli_printMessage "`gettext "Do you want to stage files?"`" --as-yesornorequest-line + ${COMMAND} add ${LOCATION} - # Print action message. - cli_printMessage "`gettext "Do you want to see changes now?"`" --as-yesornorequest-line + # See staged differences. + cli_printMessage "`gettext "Do you want to see staged files differences?"`" --as-yesornorequest-line + ${COMMAND} diff --staged ${LOCATION} | less - # Show differences. - ${COMMAND} diff ${LOCATION} | less + # Commit staged files. + cli_printMessage "`gettext "Do you want to commit staged files differences?"`" --as-yesornorequest-line + ${COMMAND} commit ${LOCATION} - # Print action message. - cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line - - # Add changes for next commit. - ${COMMAND} add ${LOCATION} - - # Commit changes up to local repository. - ${COMMAND} commit ${LOCATION} - - fi - - # When there are unversioned files in the target location, show - # which these files are and request user to add such files into - # the working copy. - if [[ ${FILESNUM[1]} -gt 0 ]];then - - # Print action message. - cli_printMessage '-' --as-separator-line - cli_printMessage "`gettext "Do you want to add unversioned files now?"`" --as-yesornorequest-line - - # Add unversioned files to be considered in the next commit. - for FILE in ${FILES[1]};do - ${COMMAND} add "${TCAR_WORKDIR}/$FILE" - done - - # Print action message. - cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line - - # Commit changes up to local repository. - ${COMMAND} commit ${LOCATION} - - fi - - # When there are added files in the target location, show which - # these files are and request user to commit them up to local - # repository. - if [[ ${FILESNUM[3]} -gt 0 ]];then - cli_printMessage '-' --as-separator-line - cli_printMessage "`gettext "Do you want to commit changes now?"`" --as-yesornorequest-line - ${COMMAND} commit ${LOCATION} - fi + # Push committed files. + cli_printMessage "`gettext "Do you want to push committed files?"`" --as-yesornorequest-line + ${COMMAND} push } diff --git a/Scripts/Bash/Functions/Vcs/Git/git_copyRepoFile.sh b/Scripts/Bash/Functions/Vcs/Git/git_copyRepoFile.sh index 2282cc6..28e9cab 100755 --- a/Scripts/Bash/Functions/Vcs/Git/git_copyRepoFile.sh +++ b/Scripts/Bash/Functions/Vcs/Git/git_copyRepoFile.sh @@ -32,7 +32,7 @@ function git_copyRepoFile { # Verify source location absolute path. It should point to # existent files or directories. They don't need to be under # version control. - cli_checkFiles ${LOCATION} -e + cli_checkFiles ${SOURCE} -e # Print action reference. if [[ -f ${SOURCE} ]];then diff --git a/Scripts/Bash/Functions/Vcs/Git/git_deleteRepoFile.sh b/Scripts/Bash/Functions/Vcs/Git/git_deleteRepoFile.sh index 1d426b1..3623084 100755 --- a/Scripts/Bash/Functions/Vcs/Git/git_deleteRepoFile.sh +++ b/Scripts/Bash/Functions/Vcs/Git/git_deleteRepoFile.sh @@ -39,7 +39,7 @@ function git_deleteRepoFile { # Remove target based on whether it is under version control or # not. - if [[ $(cli_runFnEnvironment vcs --status ${TARGET}) == '?' ]];then + if [[ $(cli_runFnEnvironment vcs --status ${TARGET}) =~ '^\?\?$' ]];then # Target isn't under version control. if [[ -d ${TARGET} ]];then rm -r ${TARGET} diff --git a/Scripts/Bash/Functions/Vcs/Git/git_syncRepoChanges.sh b/Scripts/Bash/Functions/Vcs/Git/git_syncRepoChanges.sh new file mode 100755 index 0000000..c2aa395 --- /dev/null +++ b/Scripts/Bash/Functions/Vcs/Git/git_syncRepoChanges.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# git_syncRepoChanges.sh -- This function standardizes the way changes +# are brought from central repository and merged into the local +# repository. It also standardizes the way local changes are send from +# the local repository up to central repository. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function git_syncRepoChanges { + + local LOCATION='' + local LOCATIONS="${@}" + + for LOCATION in $LOCATIONS;do + + # Verify whether the location is valid or not. + LOCATION=$(cli_checkRepoDirSource ${LOCATION}) + + # Verify source location absolute path. It should point either + # to existent files or directories both under version control + # inside the working copy. Otherwise, if it doesn't point to + # an existent file under version control, finish the script + # execution with an error message. + cli_checkFiles ${LOCATION} -e --is-versioned + + # Bring changes from the repository into the working copy. + git_updateRepoChanges ${LOCATION} + + # Check changes in the working copy. + git_commitRepoChanges ${LOCATION} + + done + +} diff --git a/Scripts/Bash/Functions/Vcs/Git/git_updateRepoChanges.sh b/Scripts/Bash/Functions/Vcs/Git/git_updateRepoChanges.sh new file mode 100755 index 0000000..f24f399 --- /dev/null +++ b/Scripts/Bash/Functions/Vcs/Git/git_updateRepoChanges.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# +# git_updateRepoChanges.sh -- This function standardizes the way +# changes are merged into the repository's local working copy. +# +# Copyright (C) 2009-2013 The CentOS Project +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or (at +# your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# ---------------------------------------------------------------------- +# $Id$ +# ---------------------------------------------------------------------- + +function git_updateRepoChanges { + + # Print action message. + cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" --as-banner-line + + # Update working copy and retrieve update output. When we use + # git, it is not possible to bring changes for specific + # directories trees but the whole repository tree. So, we need to + # position the script in the local working copy directory and + # execute the pull command therein. + # + # NOTE: The `${COMMAND} pull' command triggers the error `Unable + # to determine absolute path of git directory' while fetch and + # merge equivalents seems to do what we expect without any visible + # error. + ${COMMAND} fetch + ${COMMAND} merge FETCH_HEAD + +}