Skip to content

Commit

Permalink
Enhance update procedure
Browse files Browse the repository at this point in the history
– Display news of CHANGELOG
– Inform of Bash autocompletion update
– Describe concrete evolution of config file
closes #48
  • Loading branch information
geoffroy-aubry committed Apr 29, 2012
1 parent bdec3cb commit 745716d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ChangeLog
Features:

- #41: Add subject in commit messages of `twgit feature start` when a connector (github, redmine) is setted.
**Must update** `TWGIT_FIRST_COMMIT_MSG` parameter of `conf/twgit.sh` :
**Must update** `TWGIT_FIRST_COMMIT_MSG` parameter of `conf/twgit.sh`:

```bash
TWGIT_FIRST_COMMIT_MSG="${TWGIT_PREFIX_COMMIT_MSG}Init %s '%s'%s."
Expand Down
69 changes: 66 additions & 3 deletions inc/common.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,33 @@ function display_rank_contributors () {
echo
}
##
# Display section of CHANGELOG.md from $from_tag (exclusive) to $to_tag (inclusive).
#
# @param string $1 Full name of $from_tag
# @param string $2 Full name of $to_tag
#
function displayChangelogSection () {
local from_tag="$1"
local to_tag="$2"
local content="$(git show $to_tag:CHANGELOG.md)";
content="## Version $(echo "${content#*## Version }")";
content="$(echo "${content%## Version ${from_tag:1}*}")";
content="$(echo -e "$content\n" | sed -r ':a;N;$!ba;s/\n\n( -|```)/\n\1/g')";
local line
while read line; do
if [[ "$line" =~ ^## ]]; then
help "${line:3}"
elif [[ "$line" =~ ^[^-*\`].*:$ ]]; then
info "$line"
else
echo " $line"
fi;
done <<< "$content"
}
##
# Permet la mise à jour automatique de l'application dans le cas où le .git est toujours présent.
# Tous les $TWGIT_UPDATE_NB_DAYS jours un fetch sera exécuté afin de proposer à l'utilisateur une
Expand All @@ -1115,17 +1142,53 @@ function autoupdate () {
processing "Fetch twgit repository for auto-update check..."
git fetch
# Retrieve both current and last tag:
assert_tag_exists
local current_tag="$(git describe)"
local current_tag="$(git describe --abbrev=0)"
local current_ref_on_top=''
if [ "$(git describe)" != "$current_tag" ]; then
current_ref_on_top="$(git describe | sed -r 's/^.*-g//')"
fi
local last_tag="$(get_last_tag)"
if [ "$current_tag" != "$last_tag" ]; then
echo -n $(question "Update $last_tag available! Do you want to update twgit (or manually: twgit update)? [Y/N] ")
# If new update:
if [ "$current_tag$current_ref_on_top" != "$last_tag" ]; then
echo 'New content of CHANGELOG.md:'
displayChangelogSection "$current_tag" "$last_tag"
# Question:
local question
if [ "$current_tag" != "$last_tag" ]; then
question="Do you want to update twgit from <b>$current_tag</b> to <b>$last_tag</b> (or manually: twgit update)? [Y/N] "
else
question="You are ahead of last tag <b>$last_tag</b>. Would you like to return to it? [Y/N] "
fi
echo -n $(question "$question")
# Read answer:
read answer
if [ "$answer" = "Y" ] || [ "$answer" = "y" ]; then
processing 'Update in progress...'
exec_git_command 'git reset --hard' 'Hard reset failed!'
exec_git_command "git checkout tags/$last_tag" "Could not check out tag '$last_tag'!"
> "$TWGIT_FEATURES_SUBJECT_PATH"
# Bash autcompletion updated?
if ! git diff --quiet "$current_tag" "$last_tag" -- install/bash_completion.sh; then
warn "Bash autocompletion updated. Please restart your Bash session or try: <b>source ~/.bashrc</b>";
fi
# Config file updated?
if ! git diff --quiet "$current_tag" "$last_tag" -- $TWGIT_CONF_DIR/twgit-dist.sh; then
warn "Config file updated! \
Please consider the following diff between old and new version of <b>$TWGIT_CONF_DIR/twgit-dist.sh</b>, \
then consequently update <b>$TWGIT_CONF_DIR/twgit.sh</b>";
git diff "$current_tag" "$last_tag" -- $TWGIT_CONF_DIR/twgit-dist.sh
if [ "$(git config --get color.diff)" != 'always' ]; then
help "Try this to get colored diff in this command: <b>git config --global color.diff always</b>"
fi
fi
fi
else
processing 'Twgit already up-to-date.'
Expand Down
2 changes: 1 addition & 1 deletion inc/twgit_feature.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function cmd_status () {
exec_git_command "git status" "Error while git status!"
if [ "$(git config --get color.status)" != 'always' ]; then
echo
help "Try this to get colored status in this command: git config --global color.status always"
help "Try this to get colored status in this command: <b>git config --global color.status always</b>"
fi
fi
echo
Expand Down
1 change: 1 addition & 0 deletions inc/ui.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ UI=(
[warning.color]='\033[0;33m'
[warning.bold.color]='\033[1;33m'
[question.color]='\033[1;33m'
[question.bold.color]='\033[1;37m'
[processing.color]='\033[1;30m'
[ok.color]='\033[0;32m'
)
Expand Down

0 comments on commit 745716d

Please sign in to comment.