diff --git a/Scripts/Bash/Functions/cli_commitRepoChanges.sh b/Scripts/Bash/Functions/cli_commitRepoChanges.sh index 1534071..5328d52 100755 --- a/Scripts/Bash/Functions/cli_commitRepoChanges.sh +++ b/Scripts/Bash/Functions/cli_commitRepoChanges.sh @@ -1,10 +1,10 @@ #!/bin/bash # -# cli_commitRepoChanges.sh -- This function looks for changes inside -# absolute path passed as option value and ask you to commit them up -# to central repository. Use this function at the end of whatever -# function you make a change to repository files. It is better to -# commit small changes than long ones. +# cli_commitRepoChanges.sh -- This function looks for revision changes +# inside absolute path passed as option value and ask you to commit +# them up to central repository. Use this function at the end of +# whatever function that makes changes to the working copy files. It +# is better to commit small changes than long ones. # # Copyright (C) 2009-2010 Alain Reguera Delgado # @@ -29,34 +29,80 @@ function cli_commitRepoChanges { - local FILES='' + local -a FILES + local -a INFO + local -a FILESNUM local COUNT=0 + local UPDATEOUT='' + local PREDICATE='' - # Define list of changed files. - FILES=$(svn status $OPTIONVAL | egrep '^M' | cut -d' ' -f7) + # Update working copy. + echo '----------------------------------------------------------------------' + cli_printMessage "`gettext "Bringing changes from the repository into the working copy"`" + UPDATEOUT=$(svn update ${OPTIONVAL}) + echo '----------------------------------------------------------------------' - # Define number of changed files. - COUNT=$(echo "$FILES" | wc -l) + # Define path of files considered recent modifications from + # central repository to working copy. + FILES[0]=$(echo "$UPDATEOUT" | egrep '^A' | cut -d' ' -f7) + FILES[1]=$(echo "$UPDATEOUT" | egrep '^D' | cut -d' ' -f7) + FILES[2]=$(echo "$UPDATEOUT" | egrep '^U' | cut -d' ' -f7) + FILES[3]=$(echo "$UPDATEOUT" | egrep '^C' | cut -d' ' -f7) + FILES[4]=$(echo "$UPDATEOUT" | egrep '^G' | cut -d' ' -f7) + FILES[5]=$(svn status "$OPTIONVAL" | egrep '^M' | cut -d' ' -f7) - # Check list of changed files and ask the user to commit changes - # if there is any. - if [[ $COUNT -gt 0 ]];then + # Define description of files considered recent modifications from + # central repository to working copy. + INFO[0]="`gettext "Added"`" + INFO[1]="`gettext "Deleted"`" + INFO[2]="`gettext "Updated"`" + INFO[3]="`gettext "Conflicted"`" + INFO[4]="`gettext "Merged"`" + INFO[5]="`gettext "Modified"`" - cli_printMessage "`ngettext "The following file was changed" \ - "The following files were changed" $COUNT`:" + while [[ $COUNT -ne ${#FILES[*]} ]];do - # Show list of affected entries. - for FILE in $FILES;do - cli_printMessage "$FILE" "AsResponseLine" - done + # Get total number of files. Avoid counting empty line. + if [[ ${FILES[$COUNT]} == '' ]];then + FILESNUM[$COUNT]=0 + else + FILESNUM[$COUNT]=$(echo "${FILES[$COUNT]}" | wc -l) + fi + + # Build report predicate. Use report predicate to show any + # information specific to the number of files found. For + # example, you can use this section to show warning messages, + # notes, and so on. By default we just output the word `file' + # or `files' at ngettext's consideration. + if [[ ${FILESNUM[$COUNT]} -lt 1 ]];then + PREDICATE[$COUNT]='' + else + PREDICATE[$COUNT]=`ngettext "file" "files" ${FILESNUM[$COUNT]}` + fi + + # Output report line. + cli_printMessage "${INFO[$COUNT]}: ${FILESNUM[$COUNT]} ${PREDICATE[$COUNT]}" 'AsRegularLine' + + # Increase counter. + COUNT=$(($COUNT + 1)) + + done + + echo '----------------------------------------------------------------------' + + # Check list of changed files. If there are changes in the working + # copy, ask the user to verify, and later, commit them up to + # central repository. + if [[ ${FILESNUM[5]} -gt 0 ]];then # Verify changes. - cli_printMessage "`gettext "Do you want to see these changes now?"`" "AsYesOrNoRequestLine" - svn diff $FILES | less + cli_printMessage "`gettext "Do you want to see changes now?"`" "AsYesOrNoRequestLine" + svn diff ${FILES[5]} | less # Commit changes. - cli_printMessage "`gettext "Do you want commit these changes now?"`" "AsYesOrNoRequestLine" - svn commit $FILES + cli_printMessage "`gettext "Do you want commit changes now?"`" "AsYesOrNoRequestLine" + svn commit ${FILES[5]} + fi }