Intégration de la feature branch ptools
This commit is contained in:
commit
6d853303b9
2
.udir
2
.udir
|
@ -18,7 +18,7 @@ kvm_service=
|
|||
openvz_service=
|
||||
|
||||
configure_variables=(dest uninst_utools rm_utools kvm_service openvz_service)
|
||||
configure_dest_for=(bashrc profile lib/uinst/conf lib/uinst/rootconf lib/profile.d/nutools lib/bashrc.d/bash_completion.nutools lib/init.d/kvm-stop-all legacy/sysinc/utools legacy/sysinc/system_caps legacy/sysinc/private/init)
|
||||
configure_dest_for=(bashrc profile lib/uinst/conf lib/uinst/rootconf lib/profile.d/nutools lib/bashrc.d/bash_completion lib/init.d/kvm-stop-all legacy/sysinc/utools legacy/sysinc/system_caps legacy/sysinc/private/init)
|
||||
config_scripts=(lib/uinst/conf lib/uinst/system_caps.legacy)
|
||||
install_profiles=true
|
||||
profiledir=lib/profile.d
|
||||
|
|
|
@ -2,22 +2,28 @@
|
|||
##@before *
|
||||
|
||||
if [ -n "$UTOOLS_BASH_COMPLETION" ]; then
|
||||
if [ -f /etc/debian_version ]; then
|
||||
if [ -z "$BASH_COMPLETION" -a -f /etc/debian_version ]; then
|
||||
case "$(</etc/debian_version)" in
|
||||
6*|squeeze*)
|
||||
# le code suivant n'est compatible qu'avec debian squeeze (plus
|
||||
# exactement, avec bash 4.0)
|
||||
source "@@dest@@/lib/ulib/bash40/bash_completion"
|
||||
_file="@@dest@@/lib/ulib/bash40/bash_completion"
|
||||
;;
|
||||
7*|wheezy*)
|
||||
# le code suivant n'est compatible qu'avec debian wheezy (plus
|
||||
# exactement, avec bash 4.1)
|
||||
source "@@dest@@/lib/ulib/bash41/bash_completion"
|
||||
_file="@@dest@@/lib/ulib/bash41/bash_completion"
|
||||
;;
|
||||
esac
|
||||
[ -f "$_file" ] && source "$_file"
|
||||
unset _file
|
||||
fi
|
||||
if [ -n "$BASH_COMPLETION" ]; then
|
||||
for i in "@@dest@@/lib/bash_completion.d/"*; do
|
||||
for i in "@@dest@@/lib/completion.d/"*; do
|
||||
[ -f "$i" ] || continue
|
||||
source "$i"
|
||||
done
|
||||
for i in "$HOME/etc/completion.d/"*; do
|
||||
[ -f "$i" ] || continue
|
||||
source "$i"
|
||||
done
|
|
@ -7,10 +7,9 @@ function __nutools_host_completion() {
|
|||
_known_hosts_real "$cur"
|
||||
fi
|
||||
}
|
||||
complete -F __nutools_host_completion -o default ruinst runs rruns
|
||||
|
||||
if [ -n "$BASH_COMPLETION_DIR" -a -f "$BASH_COMPLETION_DIR/ssh" ]; then
|
||||
if __bash_completion_module_enabled ssh; then
|
||||
shopt -u hostcomplete
|
||||
complete -F _ssh ussh cssh
|
||||
fi
|
||||
|
||||
complete -F __nutools_host_completion -o default ruinst runs rruns
|
|
@ -6,3 +6,7 @@ function __pdev_branches() {
|
|||
grep -v '^release-' |
|
||||
grep -v '^hotfix-'
|
||||
}
|
||||
function __prel_branches() {
|
||||
git for-each-ref --format='%(refname:short)' refs/heads |
|
||||
grep -E '^(master$|release-)'
|
||||
}
|
|
@ -33,9 +33,11 @@ done
|
|||
./ulink --nutools-makelinks
|
||||
|
||||
# complétion programmable
|
||||
bcdir=lib/bash_completion.d
|
||||
rm -f ~/etc/bashrc.d/bash_completion.nutools # renommé
|
||||
mkdir -p ~/etc/completion.d
|
||||
bcdir=lib/completion.d
|
||||
./pdev --nutools-completion >"$bcdir/pdev"
|
||||
#./prel --nutools-completion >"$bcdir/prel"
|
||||
./prel --nutools-completion >"$bcdir/prel"
|
||||
#./pfix --nutools-completion >"$bcdir/pfix"
|
||||
|
||||
# copier le fichier .nutoolsrc
|
||||
|
|
|
@ -7,14 +7,14 @@
|
|||
##@require base
|
||||
uprovide bash_completion
|
||||
|
||||
function __is_bash_completion_enabled() {
|
||||
function __bash_completion_enabled() {
|
||||
[ -n "$BASH_COMPLETION" ]
|
||||
}
|
||||
function __is_bash_completion_module_enabled() {
|
||||
function __bash_completion_module_enabled() {
|
||||
[ -n "$BASH_COMPLETION_DIR" -a -f "$BASH_COMPLETION_DIR/$1" ]
|
||||
}
|
||||
|
||||
if ! __is_bash_completion_enabled; then
|
||||
if ! __bash_completion_enabled; then
|
||||
BASH_COMPLETION=1
|
||||
shopt -s extglob progcomp
|
||||
|
||||
|
|
|
@ -7,19 +7,28 @@
|
|||
##@require base
|
||||
uprovide bash_completion
|
||||
|
||||
function __is_bash_completion_enabled() {
|
||||
function __bash_completion_enabled() {
|
||||
[ -n "$__NUTOOLS_BASH_COMPLETION" ] && return 0
|
||||
grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' /etc/bash.bashrc && return 0
|
||||
grep -qE '^[ \t]*(\.|source)[ \t]*/usr/share/bash-completion/bash_completion' ~/.bashrc && return 0
|
||||
return 1
|
||||
}
|
||||
function __is_bash_completion_module_enabled() {
|
||||
[ -f "/usr/share/bash-completion/completions/$1" ] && return 0
|
||||
function __bash_completion_module_enabled() {
|
||||
if [ -f "/usr/share/bash-completion/completions/$1" ]; then
|
||||
local var="__NUTOOLS_BASH_COMPLETION_${1//-/_}"
|
||||
if [ -z "${!var}" ]; then
|
||||
# nous ne supportons pas le chargement à la demande: charger le
|
||||
# module de suite
|
||||
source "/usr/share/bash-completion/completions/$1"
|
||||
eval "$var=1"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
[ -n "$BASH_COMPLETION_COMPAT_DIR" -a -f "$BASH_COMPLETION_COMPAT_DIR/$1" ] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
if ! __is_bash_completion_enabled; then
|
||||
export __NUTOOLS_BASH_COMPLETION=1
|
||||
if ! __bash_completion_enabled; then
|
||||
__NUTOOLS_BASH_COMPLETION=1
|
||||
fi
|
||||
[ -n "$BASH_COMPLETION" ] || export BASH_COMPLETION=1
|
||||
[ -n "$BASH_COMPLETION" ] || BASH_COMPLETION=1
|
||||
|
|
416
lib/ulib/ptools
416
lib/ulib/ptools
|
@ -6,36 +6,67 @@
|
|||
uprovide ptools
|
||||
urequire vcs semver
|
||||
|
||||
function __get_branch() {
|
||||
local branch="$1"
|
||||
[ -n "$branch" ] || branch="$(git_get_branch)"
|
||||
echo "$branch"
|
||||
}
|
||||
|
||||
function is_master_branch() {
|
||||
local branch; branch="$(__get_branch "$1")" || return 2
|
||||
[ "$branch" == "master" ]
|
||||
}
|
||||
function is_develop_branch() {
|
||||
local branch; branch="$(__get_branch "$1")" || return 2
|
||||
[ "$branch" == "develop" ]
|
||||
}
|
||||
function is_release_branch() {
|
||||
local branch; branch="$(__get_branch "$1")" || return 2
|
||||
[[ "$branch" == release-* ]]
|
||||
}
|
||||
function is_hotfix_branch() {
|
||||
local branch; branch="$(__get_branch "$1")" || return 2
|
||||
[[ "$branch" == hotfix-* ]]
|
||||
}
|
||||
function is_feature_branch() {
|
||||
local branch; branch="$(__get_branch "$1")" || return 2
|
||||
[ "$branch" == "master" ] && return 1
|
||||
[ "$branch" == "develop" ] && return 1
|
||||
[[ "$branch" == release-* ]] && return 1
|
||||
[[ "$branch" == hotfix-* ]] && return 1
|
||||
function is_any_branch() {
|
||||
local branch="$1"; shift
|
||||
if [ -z "$branch" ]; then
|
||||
branch="$(git_get_branch)" || return 2
|
||||
fi
|
||||
local spec r
|
||||
for spec in "$@"; do
|
||||
case "$spec" in
|
||||
m|master)
|
||||
[ -n "$r" ] || r=1
|
||||
[ "$branch" == "master" ] && return 0
|
||||
;;
|
||||
d|develop)
|
||||
[ -n "$r" ] || r=1
|
||||
[ "$branch" == "develop" ] && return 0
|
||||
;;
|
||||
r|release)
|
||||
[ -n "$r" ] || r=1
|
||||
[[ "$branch" == release-* ]] && return 0
|
||||
;;
|
||||
h|hotfix)
|
||||
[ -n "$r" ] || r=1
|
||||
[[ "$branch" == hotfix-* ]] && return 0
|
||||
;;
|
||||
f|feature|t|topic)
|
||||
[ -n "$r" ] || r=1
|
||||
[ "$branch" == "master" ] && continue
|
||||
[ "$branch" == "develop" ] && continue
|
||||
[[ "$branch" == release-* ]] && continue
|
||||
[[ "$branch" == hotfix-* ]] && continue
|
||||
return 0
|
||||
;;
|
||||
-m|-master)
|
||||
[ -n "$r" ] || r=0
|
||||
[ "$branch" == "master" ] && return 1;;
|
||||
-d|-develop)
|
||||
[ -n "$r" ] || r=0
|
||||
[ "$branch" == "develop" ] && return 1;;
|
||||
-r|-release)
|
||||
[ -n "$r" ] || r=0
|
||||
[[ "$branch" == release-* ]] && return 1;;
|
||||
-h|-hotfix)
|
||||
[ -n "$r" ] || r=0
|
||||
[[ "$branch" == hotfix-* ]] && return 1;;
|
||||
-f|-feature|-t|-topic)
|
||||
[ -n "$r" ] || r=0
|
||||
[ "$branch" == "master" ] && continue
|
||||
[ "$branch" == "develop" ] && continue
|
||||
[[ "$branch" == release-* ]] && continue
|
||||
[[ "$branch" == hotfix-* ]] && continue
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
return ${r:-1}
|
||||
}
|
||||
function is_master_branch() { is_any_branch "$1" master; }
|
||||
function is_develop_branch() { is_any_branch "$1" develop; }
|
||||
function is_release_branch() { is_any_branch "$1" release; }
|
||||
function is_hotfix_branch() { is_any_branch "$1" hotfix; }
|
||||
function is_feature_branch() { is_any_branch "$1" feature; }
|
||||
|
||||
function list_release_branches() {
|
||||
git_list_branches | grep '^release-'
|
||||
|
@ -50,3 +81,332 @@ function list_feature_branches() {
|
|||
grep -v '^release-' |
|
||||
grep -v '^hotfix-'
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Outils de haut niveau
|
||||
|
||||
function pver() {
|
||||
local DEFAULT_FILE=VERSION.txt
|
||||
|
||||
local -a args
|
||||
local action=auto
|
||||
local source=auto
|
||||
local file=
|
||||
local git=
|
||||
local version=
|
||||
local convert=auto
|
||||
local operator=
|
||||
local oversion=
|
||||
local setversion=
|
||||
local incversion=
|
||||
local setprelease=
|
||||
local setalpha=
|
||||
local setbeta=
|
||||
local setrc=
|
||||
local setrelease=
|
||||
local setmetadata=
|
||||
local vcsmetadata=
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with pver_display_help' \
|
||||
-f:,--file: '$set@ file; source=file' \
|
||||
-F:,--file-string: '$set@ file; source=file-string' \
|
||||
-g:,--git-string: '$set@ git; source=git-string' \
|
||||
-s:,--string: '$set@ version; source=string' \
|
||||
--show action=show \
|
||||
--check action=check \
|
||||
--convert convert=1 \
|
||||
--no-convert convert= \
|
||||
--eq: '$action=compare; operator=eq; set@ oversion' \
|
||||
--ne: '$action=compare; operator=ne; set@ oversion' \
|
||||
--lt: '$action=compare; operator=lt; set@ oversion' \
|
||||
--le: '$action=compare; operator=le; set@ oversion' \
|
||||
--gt: '$action=compare; operator=gt; set@ oversion' \
|
||||
--ge: '$action=compare; operator=ge; set@ oversion' \
|
||||
-v:,--set-version: '$action=update; set@ setversion; incversion=' \
|
||||
-u,--update '$action=update; [ -z "$incversion" ] && incversion=auto' \
|
||||
--menu '$action=update; incversion=menu' \
|
||||
-x,--major '$action=update; incversion=major' \
|
||||
-z,--minor '$action=update; incversion=minor' \
|
||||
-p,--patchlevel '$action=update; incversion=patchlevel' \
|
||||
-l:,--prelease:,--prerelease: '$action=update; set@ setprelease; [ -z "$setprelease" ] && { setalpha=; setbeta=; setrc=; setrelease=1; }' \
|
||||
-a,--alpha '$action=update; setalpha=1; setbeta=; setrc=; setrelease=' \
|
||||
-b,--beta '$action=update; setalpha=; setbeta=1; setrc=; setrelease=' \
|
||||
-r,--rc '$action=update; setalpha=; setbeta=; setrc=1; setrelease=' \
|
||||
-R,--release,--final '$action=update; setalpha=; setbeta=; setrc=; setrelease=1' \
|
||||
-m:,--metadata: '$action=update; set@ setmetadata' \
|
||||
-M,--vcs-metadata '$action=update; vcsmetadata=1' \
|
||||
@ args -- "$@" && set -- "${args[@]}" || { eerror "$args"; return 1; }
|
||||
|
||||
# Calculer la source
|
||||
if [ "$source" == auto ]; then
|
||||
source=file
|
||||
for i in "$DEFAULT_FILE" version.txt; do
|
||||
if [ -f "$i" ]; then
|
||||
file="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
elif [ "$source" == file ]; then
|
||||
[ "$action" == auto ] && action=update
|
||||
fi
|
||||
[ "$source" == file -a -z "$file" ] && file="$DEFAULT_FILE"
|
||||
[ "$action" == auto ] && action=show
|
||||
|
||||
# Lire la version
|
||||
if [ "$source" == file ]; then
|
||||
[ -f "$file" ] && version="$(<"$file")"
|
||||
elif [ "$source" == file-string ]; then
|
||||
if [ -z "$file" ]; then
|
||||
file="$DEFAULT_FILE"
|
||||
elif [ -d "$file" ]; then
|
||||
file="$file/$DEFAULT_FILE"
|
||||
fi
|
||||
[ -f "$file" ] && version="$(<"$file")"
|
||||
file=
|
||||
elif [ "$source" == git-string ]; then
|
||||
splitfsep2 "$git" : branch name
|
||||
[ -n "$branch" ] || branch=master
|
||||
[ -n "$name" ] || name="$DEFAULT_FILE"
|
||||
if git rev-parse --verify --quiet "$branch:$name" >/dev/null; then
|
||||
version="$(git cat-file blob "$branch:$name" 2>/dev/null)"
|
||||
fi
|
||||
fi
|
||||
[ -n "$version" ] || version=0.0.0
|
||||
|
||||
# Conversion éventuelle du numéro de version
|
||||
psemver_parse "$version"
|
||||
[ -n "$valid" ] && convert=
|
||||
if [ "$convert" == auto ]; then
|
||||
[ -z "$valid" ] && convert=1
|
||||
fi
|
||||
if [ -n "$convert" ]; then
|
||||
mversion="$(awkrun version="$version" '
|
||||
function nbdot(s) {
|
||||
gsub(/[^.]/, "", s)
|
||||
return length(s)
|
||||
}
|
||||
BEGIN {
|
||||
if (version ~ /[0-9]+(\.[0-9]+)*(-r[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9])?$/) {
|
||||
metadata = ""
|
||||
# traiter release date
|
||||
pos = length(version) - 12
|
||||
if (pos > 0) {
|
||||
rdate = substr(version, pos + 3)
|
||||
metadata = substr(rdate, 7, 4) substr(rdate, 4, 2) substr(rdate, 1, 2)
|
||||
version = substr(version, 1, pos)
|
||||
}
|
||||
# traiter metadata
|
||||
match(version, /[0-9]+(\.[0-9]+(\.[0-9]+)?)?/)
|
||||
pos = RLENGTH
|
||||
if (pos < length(version)) {
|
||||
if (metadata != "") metadata = metadata "."
|
||||
metadata = metadata substr(version, pos + 2)
|
||||
}
|
||||
version = substr(version, 1, pos)
|
||||
# ajouter les éléments manquants
|
||||
while (nbdot(version) < 2) {
|
||||
version = version ".0"
|
||||
}
|
||||
# afficher la version migrée au format semver
|
||||
if (metadata != "") print version "+" metadata
|
||||
else print version
|
||||
}
|
||||
}')"
|
||||
if [ -n "$mversion" ]; then
|
||||
version="$mversion"
|
||||
psemver_parse "$version"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Actions
|
||||
if [ "$action" == show ]; then
|
||||
if isatty; then
|
||||
estepi "La version actuelle est $version"
|
||||
else
|
||||
echo "$version"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$action" == check ]; then
|
||||
[ -n "$valid" ] || { eerror "Numéro de version invalide: $version"; return 1; }
|
||||
|
||||
elif [ "$action" == compare ]; then
|
||||
psemver_parse "$oversion" o
|
||||
|
||||
case "$operator" in
|
||||
eq|same)
|
||||
for var in valid major minor patchlevel; do
|
||||
ovar="o$var"
|
||||
[ "${!var}" == "${!ovar}" ] || return 1
|
||||
done
|
||||
array_eq prelease oprelease || return 1
|
||||
if [ "$operator" == same ]; then
|
||||
array_eq metadata ometadata || return 1
|
||||
fi
|
||||
return 0
|
||||
;;
|
||||
ne|diff)
|
||||
for var in valid major minor patchlevel; do
|
||||
ovar="o$var"
|
||||
[ "${!var}" != "${!ovar}" ] && return 0
|
||||
done
|
||||
! array_eq prelease oprelease && return 0
|
||||
if [ "$operator" == diff ]; then
|
||||
! array_eq metadata ometadata && return 0
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
lt)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && return 1
|
||||
[ "$major" -lt "$omajor" ] && return 0
|
||||
[ "$major" -gt "$omajor" ] && return 1
|
||||
[ "$minor" -lt "$ominor" ] && return 0
|
||||
[ "$minor" -gt "$ominor" ] && return 1
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && return 0
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && return 1
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
lt) return 0;;
|
||||
esac
|
||||
return 1
|
||||
;;
|
||||
le)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && return 1
|
||||
[ "$major" -lt "$omajor" ] && return 0
|
||||
[ "$major" -gt "$omajor" ] && return 1
|
||||
[ "$minor" -lt "$ominor" ] && return 0
|
||||
[ "$minor" -gt "$ominor" ] && return 1
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && return 0
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && return 1
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
lt|eq) return 0;;
|
||||
esac
|
||||
return 1
|
||||
;;
|
||||
gt)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && return 1
|
||||
[ "$major" -lt "$omajor" ] && return 1
|
||||
[ "$major" -gt "$omajor" ] && return 0
|
||||
[ "$minor" -lt "$ominor" ] && return 1
|
||||
[ "$minor" -gt "$ominor" ] && return 0
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && return 1
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && return 0
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
gt) return 0;;
|
||||
esac
|
||||
return 1
|
||||
;;
|
||||
ge)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && return 1
|
||||
[ "$major" -lt "$omajor" ] && return 1
|
||||
[ "$major" -gt "$omajor" ] && return 0
|
||||
[ "$minor" -lt "$ominor" ] && return 1
|
||||
[ "$minor" -gt "$ominor" ] && return 0
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && return 1
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && return 0
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
gt|eq) return 0;;
|
||||
esac
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
elif [ "$action" == update ]; then
|
||||
[ -n "$valid" ] || { eerror "Numéro de version invalide: $version"; return 1; }
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
if [ -f "$file" ]; then
|
||||
if isatty; then
|
||||
estepi "La version actuelle est $version"
|
||||
fi
|
||||
else
|
||||
if isatty; then
|
||||
ask_yesno "Le fichier $(ppath "$file") n'existe pas. Faut-il le créer?" O || return 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# forcer le numéro de version
|
||||
if [ -n "$setversion" ]; then
|
||||
psemver_setversion "$setversion" "" || { eerror "Numéro de version invalide: $setversion"; return 1; }
|
||||
fi
|
||||
|
||||
# Calculer metadata
|
||||
if [ -n "$vcsmetadata" ]; then
|
||||
setmetadata="$(git rev-parse --short HEAD)" || return 1
|
||||
fi
|
||||
|
||||
# incrémenter les numéros de version
|
||||
if [ "$incversion" == auto ]; then
|
||||
if [ -n "$setrelease" -o -n "$setprelease" -o -n "$setmetadata" ]; then
|
||||
incversion=
|
||||
else
|
||||
incversion=menu
|
||||
fi
|
||||
fi
|
||||
if [ "$incversion" == menu ]; then
|
||||
psemver_copy x; psemver_incmajor x; psemver_setprelease "$setprelease" x; psemver_setmetadata "$setmetadata" x; psemver_setvar versionx x
|
||||
psemver_copy z; psemver_incminor z; psemver_setprelease "$setprelease" z; psemver_setmetadata "$setmetadata" z; psemver_setvar versionz z
|
||||
psemver_copy p; psemver_incpatchlevel p; psemver_setprelease "$setprelease" p; psemver_setmetadata "$setmetadata" p; psemver_setvar versionp p
|
||||
psemver_copy k; psemver_setprelease "$setprelease" k; psemver_setmetadata "$setmetadata" k; psemver_setvar versionk k
|
||||
nextvs=(
|
||||
"$versionx : maj incompatibles de l'API (-x)"
|
||||
"$versionz : maj compatibles de l'API (-z)"
|
||||
"$versionp : correction de bugs (-p)"
|
||||
"$versionk : ne pas incrémenter la version"
|
||||
)
|
||||
nextv="${nextvs[1]}"
|
||||
simple_menu nextv nextvs \
|
||||
-t "Incrémenter le numéro de version" \
|
||||
-m "Veuillez choisir la prochaine version"
|
||||
case "${nextv%)}" in
|
||||
*-x) incversion=major;;
|
||||
*-z) incversion=minor;;
|
||||
*-p) incversion=patchlevel;;
|
||||
*) incversion=;;
|
||||
esac
|
||||
fi
|
||||
if [ -n "$incversion" ]; then
|
||||
case "$incversion" in
|
||||
major) psemver_incmajor;;
|
||||
minor) psemver_incminor;;
|
||||
patchlevel) psemver_incpatchlevel;;
|
||||
esac
|
||||
# Quand on incrémente, réinitialiser la valeur de prérelease et metadata
|
||||
psemver_setprelease
|
||||
psemver_setmetadata
|
||||
fi
|
||||
|
||||
# spécifier prerelease
|
||||
if [ -n "$setrelease" ]; then
|
||||
psemver_setprelease ""
|
||||
elif [ -n "$setprelease" ]; then
|
||||
psemver_setprelease "$setprelease" || { eerror "Identifiant de pre-release invalide: $setprelease"; return 1; }
|
||||
fi
|
||||
if [ -n "$setalpha" ]; then
|
||||
: #XXX
|
||||
elif [ -n "$setbeta" ]; then
|
||||
: #XXX
|
||||
elif [ -n "$setrc" ]; then
|
||||
: #XXX
|
||||
fi
|
||||
|
||||
# spécifier metadata
|
||||
if [ -n "$setmetadata" ]; then
|
||||
psemver_setmetadata "$setmetadata" || { eerror "Identifiant de build invalide: $setmetadata"; return 1; }
|
||||
fi
|
||||
|
||||
# afficher le résultat final
|
||||
psemver_setvar version
|
||||
if [ -n "$file" ]; then
|
||||
echo "$version" >"$file"
|
||||
fi
|
||||
if isatty; then
|
||||
estepn "La nouvelle version est $version"
|
||||
else
|
||||
echo "$version"
|
||||
fi
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
11
pdev
11
pdev
|
@ -48,9 +48,14 @@ OPTIONS
|
|||
activée si la variable UTOOLS_VCS_OFFLINE est définie.
|
||||
--online
|
||||
Annuler l'effet de la variable UTOOLS_VCS_OFFLINE: forcer le mode online
|
||||
|
||||
-m, --merge
|
||||
Si la branche actuelle est une feature branch, la merger dans develop
|
||||
puis la supprimer. Puis basculer sur la branche develop.
|
||||
-k, --keep
|
||||
Avec l'option -m, ne pas supprimer une feature branch après l'avoir
|
||||
fusionnée dans develop.
|
||||
|
||||
-l, --log
|
||||
-d, --diff
|
||||
Afficher les modifications entre deux branches. L'option --log affiche
|
||||
|
@ -65,6 +70,7 @@ OPTIONS
|
|||
projdir=
|
||||
origin=origin
|
||||
action=branch
|
||||
merge_delete=1
|
||||
log=
|
||||
diff=
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
|
@ -74,6 +80,7 @@ parse_opts "${PRETTYOPTS[@]}" \
|
|||
-o,--offline UTOOLS_VCS_OFFLINE=1 \
|
||||
--online UTOOLS_VCS_OFFLINE= \
|
||||
-m,--merge action=merge \
|
||||
-k,--keep merge_delete= \
|
||||
-l,--log '$action=diff; log=1' \
|
||||
-d,--diff '$action=diff; diff=1' \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
|
@ -170,8 +177,9 @@ dans la branche de destination ${COULEUR_BLEUE}develop${COULEUR_NORMALE}"
|
|||
git checkout develop
|
||||
git merge "$feature" -m "Intégration de la feature branch $feature" --no-ff || die
|
||||
|
||||
if [ -n "$merge_delete" ]; then
|
||||
estepi "Suppression de la branche locale"
|
||||
git branch -d "$feature"
|
||||
git branch -D "$feature"
|
||||
|
||||
if git_have_remote "$origin"; then
|
||||
if [ -z "$UTOOLS_VCS_OFFLINE" ]; then
|
||||
|
@ -184,6 +192,7 @@ Veuillez le faire manuellement avec la commande suivante:
|
|||
$(quoted_args git push "$origin" ":$feature")"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
elif [ "$action" == diff ]; then
|
||||
if [ -n "$log" ]; then
|
||||
|
|
|
@ -0,0 +1,362 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
|
||||
if [ $# -eq 1 -a "$1" == --nutools-completion ]; then
|
||||
echo '
|
||||
function __prel_completion() {
|
||||
local cur
|
||||
_get_comp_words_by_ref cur
|
||||
COMPREPLY=($(compgen -W "$(__prel_branches)" "$cur"))
|
||||
}
|
||||
complete -F __prel_completion prel
|
||||
'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||||
urequire DEFAULTS ptools
|
||||
|
||||
# XXX Ajouter une option pour fusionner les modifications d'une branche de
|
||||
# pré-release dans develop
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: basculer sur une branche de release
|
||||
|
||||
USAGE
|
||||
$scriptname -u [SOURCE]
|
||||
$scriptname -c [RELEASE [SOURCE]]
|
||||
$scriptname -m|-l|-d [RELEASE]
|
||||
|
||||
- Vérifier s'il n'y a pas de modifications locales. Sinon, proposer de faire un
|
||||
commit ou un stash.
|
||||
- Avec l'option -c, s'il existe une branche de release, proposer de basculer
|
||||
vers elle ou sur la branche master. Sinon, basculer sur la branche master.
|
||||
- Avec l'option -u, proposer ou fixer une branche de release à créer. Si elle
|
||||
existe déjà, basculer vers elle. Sinon, la créer en la basant sur SOURCE, qui
|
||||
vaut par défaut develop
|
||||
|
||||
OPTIONS
|
||||
-C, --projdir PROJDIR
|
||||
Spécifier le répertoire de base du projet qui est dans git. Par défaut,
|
||||
on travaille dans le répertoire courant et on laisse git trouver le
|
||||
répertoire de base du projet. Avec cette option, le répertoire courant
|
||||
est modifié avant de lancer les commandes git.
|
||||
-O, --origin ORIGIN
|
||||
Spécifier le nom de l'origine. Par défaut, utiliser 'origin'
|
||||
-o, --offline
|
||||
En cas de création d'une branche, ne pas pousser vers l'origine; ne pas
|
||||
tenter le cas échéant de traquer la branche dans l'origine; ne pas
|
||||
supprimer une branche dans l'origine. Cette option est automatiquement
|
||||
activée si la variable UTOOLS_VCS_OFFLINE est définie.
|
||||
--online
|
||||
Annuler l'effet de la variable UTOOLS_VCS_OFFLINE: forcer le mode online
|
||||
|
||||
-c, --checkout
|
||||
Basculer vers une branche de release existante. C'est l'option par
|
||||
défaut. Si aucune branche de release n'existe, basculer vers master
|
||||
-u, --update
|
||||
Préparer une nouvelle release. Utiliser une des options -x, -z ou -p
|
||||
pour spécifier le type de release à préparer. Si la branche qui serait
|
||||
créée pour le type de release existe déjà, basculer vers cette branche.
|
||||
S'il faut la créer, la baser sur la branche SOURCE, qui vaut par défaut
|
||||
develop
|
||||
--menu
|
||||
-x, --major
|
||||
-z, --minor
|
||||
-p, --patchlevel
|
||||
Utilisé avec l'option -u, soit afficher un menu pour choisir la version
|
||||
de la nouvelle release (par défaut), soit préparer respectivement une
|
||||
release majeure, mineure, ou pour correction de bug.
|
||||
-v-OPT
|
||||
Avec l'option -u, spécifier une option de pver permettant de choisir la
|
||||
version de la nouvelle release. Les options supportées sont -v, -l, -a,
|
||||
-b, -r et -R. Par exemple, si la version actuelle sur la branche master
|
||||
est 0.2.3, les options '-uz -v-lbeta' permettent de préparer la release
|
||||
0.3.0-beta
|
||||
En principe, cette option n'a pas à être utilisée, puisque dans une
|
||||
branche de release, on peut faire vivre les versions de pré-release
|
||||
jusqu'à la release finale. Ainsi, la branche de release est nommée
|
||||
d'après la version finale, mais le projet peut recevoir une version de
|
||||
pré-release incrémentale.
|
||||
-w, --write
|
||||
Si une nouvelle branche est créée avec -u, mettre à jour le fichier
|
||||
VERSION.txt avec pver. C'est l'option par défaut.
|
||||
-n, --no-write
|
||||
Si une nouvelle branche est créée avec -u, NE PAS mettre à jour le
|
||||
fichier VERSION.txt avec pver. Utiliser cette option si la mise à jour
|
||||
du numéro de version doit être faite par manière particulière.
|
||||
|
||||
-m, --merge
|
||||
Si la branche actuelle est une branche de release, ou s'il existe une
|
||||
branche de release, la merger dans master, puis dans develop, puis la
|
||||
supprimer. Puis basculer sur la branche master.
|
||||
S'il n'existe pas de branche de release, proposer de fusionner les
|
||||
modifications de la branche develop dans la branche master, sans
|
||||
préparer de branche de release au préalable.
|
||||
-l, --log
|
||||
Afficher les modifications actuellement effectuée dans la branche de
|
||||
release par rapport à develop.
|
||||
-d, --diff
|
||||
Afficher les modifications actuellement effectuée dans la branche de
|
||||
release par rapport à develop, sous forme de diff."
|
||||
}
|
||||
|
||||
projdir=
|
||||
origin=origin
|
||||
action=auto
|
||||
update=
|
||||
merge=
|
||||
checkout=
|
||||
incversion=
|
||||
pver_opts=()
|
||||
write=1
|
||||
log=
|
||||
diff=
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with display_help' \
|
||||
-C:,--projdir: projdir= \
|
||||
-O:,--origin: origin= \
|
||||
-o,--offline UTOOLS_VCS_OFFLINE=1 \
|
||||
--online UTOOLS_VCS_OFFLINE= \
|
||||
-c,--checkout checkout=1 \
|
||||
-u,--update '$update=1; [ -z "$incversion" ] && incversion=auto' \
|
||||
--menu '$update=1; incversion=menu' \
|
||||
-x,--major '$update=1; incversion=major' \
|
||||
-z,--minor '$update=1; incversion=minor' \
|
||||
-p,--patchlevel '$update=1; incversion=patchlevel' \
|
||||
-v: '$update=1; add@ pver_opts' \
|
||||
-w,--write write=1 \
|
||||
-n,--no-write write= \
|
||||
-m,--merge merge=1 \
|
||||
-l,--log '$action=diff; log=1' \
|
||||
-d,--diff '$action=diff; diff=1' \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
|
||||
if [ "$action" == auto ]; then
|
||||
if [ -n "$update" ]; then
|
||||
action=update
|
||||
elif [ -n "$merge" ]; then
|
||||
action=merge
|
||||
elif [ -n "$checkout" ]; then
|
||||
action=checkout
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$projdir" ]; then
|
||||
cd "$projdir" || die
|
||||
fi
|
||||
|
||||
git_ensure_gitvcs
|
||||
|
||||
setx branch=git_get_branch
|
||||
|
||||
if [ "$action" == update ]; then
|
||||
setx oldver=pver -g ""
|
||||
newver=
|
||||
|
||||
if [ "$incversion" == auto ]; then
|
||||
if [ ${#pver_opts[*]} -gt 0 ]; then
|
||||
# des options ont été spécifiées, les honorer
|
||||
setx newver=pver -s "$oldver" "${pver_opts[@]}"
|
||||
release="release-$newver"
|
||||
else
|
||||
# sinon, prendre une décision en fonction des branches de release
|
||||
# qui existent déjà
|
||||
setx -a branches=list_release_branches
|
||||
if [ ${#branches[*]} -eq 0 ]; then
|
||||
# en l'absence de branche de release, proposer d'en créer une
|
||||
incversion=menu
|
||||
elif [ ${#branches[*]} -eq 1 ]; then
|
||||
# s'il n'y en a qu'une, la prendre
|
||||
release="${branches[0]}"
|
||||
else
|
||||
# sinon, donner le choix dans un menu
|
||||
array_add branches master
|
||||
default_branch="$branch"
|
||||
array_contains branches "$default_branch" || default_branch="${branches[0]}"
|
||||
simple_menu release branches -d "$default_branch" \
|
||||
-t "Basculer vers une release branch" \
|
||||
-m "Veuillez choisir la branche vers laquelle basculer"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
case "$incversion" in
|
||||
menu)
|
||||
setx majorv=pver -s "$oldver" -ux "${pver_opts[@]}"
|
||||
setx minorv=pver -s "$oldver" -uz "${pver_opts[@]}"
|
||||
setx patchlevelv=pver -g "$oldver" -up "${pver_opts[@]}"
|
||||
release="release-$minorv"
|
||||
branches=("release-$majorv" "release-$minorv" "release-$patchlevelv" master)
|
||||
simple_menu release branches \
|
||||
-t "Basculer vers une nouvelle release branch" \
|
||||
-m "Veuillez choisir la branche à créer"
|
||||
;;
|
||||
major)
|
||||
setx newver=pver -s "$oldver" -ux "${pver_opts[@]}"
|
||||
release="release-$newver"
|
||||
;;
|
||||
minor)
|
||||
setx newver=pver -s "$oldver" -uz "${pver_opts[@]}"
|
||||
release="release-$newver"
|
||||
;;
|
||||
patchlevel)
|
||||
setx newver=pver -g "$oldver" -up "${pver_opts[@]}"
|
||||
release="release-$newver"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$newver" ]; then
|
||||
# le cas échéant, tenter de calculer la version en fonction de la
|
||||
# release
|
||||
[[ "$release" == release-* ]] && newver="${release#release-}"
|
||||
fi
|
||||
|
||||
set -- "$release" "$1"
|
||||
action=checkout
|
||||
fi
|
||||
|
||||
if [ "$action" == checkout ]; then
|
||||
release="$1"
|
||||
source="${2:-develop}"
|
||||
|
||||
if [ -z "$release" ]; then
|
||||
setx -a branches=list_release_branches
|
||||
|
||||
if [ ${#branches[*]} -eq 0 ]; then
|
||||
# en l'absence de branche de release, basculer sur master
|
||||
release=master
|
||||
elif [ ${#branches[*]} -eq 1 ]; then
|
||||
# s'il n'y en a qu'une, la prendre
|
||||
release="${branches[0]}"
|
||||
else
|
||||
# sinon, donner le choix dans un menu
|
||||
array_add branches master
|
||||
default_branch="$branch"
|
||||
array_contains branches "$default_branch" || default_branch="${branches[0]}"
|
||||
simple_menu release branches -d "$default_branch" \
|
||||
-t "Basculer vers une release branch" \
|
||||
-m "Veuillez choisir la branche vers laquelle basculer"
|
||||
fi
|
||||
fi
|
||||
|
||||
# On est peut-être déjà sur la bonne branche
|
||||
if git_is_branch "$release"; then
|
||||
if [ -z "$UTOOLS_VCS_OFFLINE" ]; then
|
||||
git_track_branch "$release" "$origin"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Créer/basculer vers une release branch
|
||||
git_ensure_cleancheckout
|
||||
is_any_branch "$release" master release || die "$release: ce n'est pas une release branch"
|
||||
r=0
|
||||
if git_have_branch "$release"; then
|
||||
git checkout "$release"; r=$?
|
||||
else
|
||||
estepn "\
|
||||
Vous allez créer la nouvelle release branch ${COULEUR_VERTE}$release${COULEUR_NORMALE}
|
||||
à partir de la branche source ${COULEUR_BLEUE}$source${COULEUR_NORMALE}"
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
|
||||
git_ensure_branch "$release" "$source" "$origin"
|
||||
[ $? -eq 2 ] && die "Impossible de créer la branche $release. Veuillez vérifier que la branche $source existe"
|
||||
git checkout "$release"; r=$?
|
||||
|
||||
if [ "$r" -eq 0 -a -n "$newver" ]; then
|
||||
if pver -uv "$newver"; then
|
||||
git add -A
|
||||
git commit -m "Initialiser la version $newver"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$r" -eq 0 -a -n "$merge" ]; then
|
||||
set -- "$release"
|
||||
action=merge
|
||||
else
|
||||
exit "$r"
|
||||
fi
|
||||
fi
|
||||
|
||||
setx -a branches=list_release_branches
|
||||
setb have_release_branches=[ ${#branches[*]} -gt 0 ]
|
||||
|
||||
release="$1"
|
||||
if [ -n "$release" ]; then
|
||||
if [ -n "$have_release_branches" ]; then
|
||||
is_release_branch "$release" || die "$release: ce n'est pas une release branch"
|
||||
elif ! is_develop_branch "$release"; then
|
||||
die "Aucune branche de release n'existe, vous devez fusionner à partir de develop"
|
||||
fi
|
||||
git_have_branch "$release" || die "$release: branche invalide"
|
||||
elif is_release_branch "$branch"; then
|
||||
release="$branch"
|
||||
fi
|
||||
|
||||
if [ "$action" == merge ]; then
|
||||
confirm=
|
||||
|
||||
if [ -z "$release" ]; then
|
||||
if [ ${#branches[*]} -eq 0 ]; then
|
||||
ewarn "Aucune release branch n'a été préparée."
|
||||
ewarn "La branche develop sera fusionnée directement dans master."
|
||||
release=develop
|
||||
confirm=-y
|
||||
elif [ ${#branches[*]} -eq 1 ]; then
|
||||
release="${branches[0]}"
|
||||
estepn "Autosélection de $release"
|
||||
else
|
||||
default_release="$branch"
|
||||
array_contains branches "$default_release" || default_release="${branches[0]}"
|
||||
simple_menu release branches -d "$default_release" \
|
||||
-t "Choix de la release branch" \
|
||||
-m "Veuillez choisir la branche"
|
||||
fi
|
||||
fi
|
||||
|
||||
estepn "\
|
||||
Intégration de la branche ${COULEUR_VERTE}$release${COULEUR_NORMALE}
|
||||
dans la branche de destination ${COULEUR_BLEUE}master${COULEUR_NORMALE}"
|
||||
ask_yesno $confirm "Voulez-vous continuer?" O || die
|
||||
|
||||
git checkout master
|
||||
git merge "$release" -m "Intégration de la branche $release" --no-ff || die
|
||||
|
||||
if [ "$release" != develop ]; then
|
||||
git checkout develop
|
||||
git merge "$release" -m "Intégration de la branche $release" --no-ff || die
|
||||
|
||||
git checkout master
|
||||
|
||||
estepi "Suppression de la branche locale"
|
||||
git branch -D "$release"
|
||||
|
||||
if git_have_remote "$origin"; then
|
||||
if [ -z "$UTOOLS_VCS_OFFLINE" ]; then
|
||||
estepi "Suppression de la branche distante"
|
||||
git push "$origin" ":$release"
|
||||
else
|
||||
eimportant "\
|
||||
La branche $release n'a plus lieu d'être, mais la configuration actuelle interdit de la supprimer dans le dépôt distant.
|
||||
Veuillez le faire manuellement avec la commande suivante:
|
||||
$(qvals git push "$origin" ":$release")"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
elif [ "$action" == diff ]; then
|
||||
if [ -n "$log" ]; then
|
||||
if [ -n "$release" ]; then
|
||||
git log ${diff:+-p} master.."$release"
|
||||
else
|
||||
git log ${diff:+-p} master..develop
|
||||
fi
|
||||
elif [ -n "$diff" ]; then
|
||||
if [ -n "$release" ]; then
|
||||
git diff master.."$release"
|
||||
else
|
||||
git diff master..develop
|
||||
fi
|
||||
fi
|
||||
fi
|
327
pver
327
pver
|
@ -1,9 +1,9 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||||
urequire DEFAULTS semver
|
||||
urequire DEFAULTS ptools
|
||||
|
||||
function display_help() {
|
||||
function pver_display_help() {
|
||||
uecho "$scriptname: gérer des numéros de version selon les règles du versionage sémantique v2.0.0 (http://semver.org/)
|
||||
|
||||
USAGE
|
||||
|
@ -83,325 +83,4 @@ OPTIONS
|
|||
gestionnaire de version. Note: pour le moment, seul git est supporté."
|
||||
}
|
||||
|
||||
DEFAULT_FILE=VERSION.txt
|
||||
|
||||
action=auto
|
||||
source=auto
|
||||
file=
|
||||
git=
|
||||
version=
|
||||
convert=auto
|
||||
operator=
|
||||
oversion=
|
||||
setversion=
|
||||
incversion=
|
||||
setprelease=
|
||||
setalpha=
|
||||
setbeta=
|
||||
setrc=
|
||||
setrelease=
|
||||
setmetadata=
|
||||
vcsmetadata=
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with display_help' \
|
||||
-f:,--file: '$set@ file; source=file' \
|
||||
-F:,--file-string: '$set@ file; source=file-string' \
|
||||
-g:,--git-string: '$set@ git; source=git-string' \
|
||||
-s:,--string: '$set@ version; source=string' \
|
||||
--show action=show \
|
||||
--check action=check \
|
||||
--convert convert=1 \
|
||||
--no-convert convert= \
|
||||
--eq: '$action=compare; operator=eq; set@ oversion' \
|
||||
--ne: '$action=compare; operator=ne; set@ oversion' \
|
||||
--lt: '$action=compare; operator=lt; set@ oversion' \
|
||||
--le: '$action=compare; operator=le; set@ oversion' \
|
||||
--gt: '$action=compare; operator=gt; set@ oversion' \
|
||||
--ge: '$action=compare; operator=ge; set@ oversion' \
|
||||
-v:,--set-version: '$action=update; set@ setversion; incversion=' \
|
||||
-u,--update '$action=update; [ -z "$incversion" ] && incversion=auto' \
|
||||
--menu '$action=update; incversion=menu' \
|
||||
-x,--major '$action=update; incversion=major' \
|
||||
-z,--minor '$action=update; incversion=minor' \
|
||||
-p,--patchlevel '$action=update; incversion=patchlevel' \
|
||||
-l:,--prelease:,--prerelease: '$action=update; set@ setprelease; [ -z "$setprelease" ] && { setalpha=; setbeta=; setrc=; setrelease=1; }' \
|
||||
-a,--alpha '$action=update; setalpha=1; setbeta=; setrc=; setrelease=' \
|
||||
-b,--beta '$action=update; setalpha=; setbeta=1; setrc=; setrelease=' \
|
||||
-r,--rc '$action=update; setalpha=; setbeta=; setrc=1; setrelease=' \
|
||||
-R,--release,--final '$action=update; setalpha=; setbeta=; setrc=; setrelease=1' \
|
||||
-m:,--metadata: '$action=update; set@ setmetadata' \
|
||||
-M,--vcs-metadata '$action=update; vcsmetadata=1' \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
|
||||
# Calculer la source
|
||||
if [ "$source" == auto ]; then
|
||||
source=file
|
||||
for i in "$DEFAULT_FILE" version.txt; do
|
||||
if [ -f "$i" ]; then
|
||||
file="$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
elif [ "$source" == file ]; then
|
||||
[ "$action" == auto ] && action=update
|
||||
fi
|
||||
[ "$source" == file -a -z "$file" ] && file="$DEFAULT_FILE"
|
||||
[ "$action" == auto ] && action=show
|
||||
|
||||
# Lire la version
|
||||
if [ "$source" == file ]; then
|
||||
[ -f "$file" ] && version="$(<"$file")"
|
||||
elif [ "$source" == file-string ]; then
|
||||
if [ -z "$file" ]; then
|
||||
file="$DEFAULT_FILE"
|
||||
elif [ -d "$file" ]; then
|
||||
file="$file/$DEFAULT_FILE"
|
||||
fi
|
||||
[ -f "$file" ] && version="$(<"$file")"
|
||||
file=
|
||||
elif [ "$source" == git-string ]; then
|
||||
splitfsep2 "$git" : branch name
|
||||
[ -n "$branch" ] || branch=master
|
||||
[ -n "$name" ] || name="$DEFAULT_FILE"
|
||||
if git rev-parse --verify --quiet "$branch:$name" >/dev/null; then
|
||||
version="$(git cat-file blob "$branch:$name" 2>/dev/null)"
|
||||
fi
|
||||
fi
|
||||
[ -n "$version" ] || version=0.0.0
|
||||
|
||||
# Conversion éventuelle du numéro de version
|
||||
psemver_parse "$version"
|
||||
[ -n "$valid" ] && convert=
|
||||
if [ "$convert" == auto ]; then
|
||||
[ -z "$valid" ] && convert=1
|
||||
fi
|
||||
if [ -n "$convert" ]; then
|
||||
mversion="$(awkrun version="$version" '
|
||||
function nbdot(s) {
|
||||
gsub(/[^.]/, "", s)
|
||||
return length(s)
|
||||
}
|
||||
BEGIN {
|
||||
if (version ~ /[0-9]+(\.[0-9]+)*(-r[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9])?$/) {
|
||||
metadata = ""
|
||||
# traiter release date
|
||||
pos = length(version) - 12
|
||||
if (pos > 0) {
|
||||
rdate = substr(version, pos + 3)
|
||||
metadata = substr(rdate, 7, 4) substr(rdate, 4, 2) substr(rdate, 1, 2)
|
||||
version = substr(version, 1, pos)
|
||||
}
|
||||
# traiter metadata
|
||||
match(version, /[0-9]+(\.[0-9]+(\.[0-9]+)?)?/)
|
||||
pos = RLENGTH
|
||||
if (pos < length(version)) {
|
||||
if (metadata != "") metadata = metadata "."
|
||||
metadata = metadata substr(version, pos + 2)
|
||||
}
|
||||
version = substr(version, 1, pos)
|
||||
# ajouter les éléments manquants
|
||||
while (nbdot(version) < 2) {
|
||||
version = version ".0"
|
||||
}
|
||||
# afficher la version migrée au format semver
|
||||
if (metadata != "") print version "+" metadata
|
||||
else print version
|
||||
}
|
||||
}')"
|
||||
if [ -n "$mversion" ]; then
|
||||
version="$mversion"
|
||||
psemver_parse "$version"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Actions
|
||||
if [ "$action" == show ]; then
|
||||
if isatty; then
|
||||
estepi "La version actuelle est $version"
|
||||
else
|
||||
echo "$version"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$action" == check ]; then
|
||||
[ -n "$valid" ] || die "Numéro de version invalide: $version"
|
||||
|
||||
elif [ "$action" == compare ]; then
|
||||
psemver_parse "$oversion" o
|
||||
|
||||
case "$operator" in
|
||||
eq|same)
|
||||
for var in valid major minor patchlevel; do
|
||||
ovar="o$var"
|
||||
[ "${!var}" == "${!ovar}" ] || exit 1
|
||||
done
|
||||
array_eq prelease oprelease || exit 1
|
||||
if [ "$operator" == same ]; then
|
||||
array_eq metadata ometadata || exit 1
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
ne|diff)
|
||||
for var in valid major minor patchlevel; do
|
||||
ovar="o$var"
|
||||
[ "${!var}" != "${!ovar}" ] && exit 0
|
||||
done
|
||||
! array_eq prelease oprelease && exit 0
|
||||
if [ "$operator" == diff ]; then
|
||||
! array_eq metadata ometadata && exit 0
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
lt)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && exit 1
|
||||
[ "$major" -lt "$omajor" ] && exit 0
|
||||
[ "$major" -gt "$omajor" ] && exit 1
|
||||
[ "$minor" -lt "$ominor" ] && exit 0
|
||||
[ "$minor" -gt "$ominor" ] && exit 1
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && exit 0
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && exit 1
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
lt) exit 0;;
|
||||
esac
|
||||
exit 1
|
||||
;;
|
||||
le)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && exit 1
|
||||
[ "$major" -lt "$omajor" ] && exit 0
|
||||
[ "$major" -gt "$omajor" ] && exit 1
|
||||
[ "$minor" -lt "$ominor" ] && exit 0
|
||||
[ "$minor" -gt "$ominor" ] && exit 1
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && exit 0
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && exit 1
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
lt|eq) exit 0;;
|
||||
esac
|
||||
exit 1
|
||||
;;
|
||||
gt)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && exit 1
|
||||
[ "$major" -lt "$omajor" ] && exit 1
|
||||
[ "$major" -gt "$omajor" ] && exit 0
|
||||
[ "$minor" -lt "$ominor" ] && exit 1
|
||||
[ "$minor" -gt "$ominor" ] && exit 0
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && exit 1
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && exit 0
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
gt) exit 0;;
|
||||
esac
|
||||
exit 1
|
||||
;;
|
||||
ge)
|
||||
[ -z "$valid" -a -z "$ovalid" ] && exit 1
|
||||
[ "$major" -lt "$omajor" ] && exit 1
|
||||
[ "$major" -gt "$omajor" ] && exit 0
|
||||
[ "$minor" -lt "$ominor" ] && exit 1
|
||||
[ "$minor" -gt "$ominor" ] && exit 0
|
||||
[ "$patchlevel" -lt "$opatchlevel" ] && exit 1
|
||||
[ "$patchlevel" -gt "$opatchlevel" ] && exit 0
|
||||
case "$(psemver_compare_prelease "" o)" in
|
||||
gt|eq) exit 0;;
|
||||
esac
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
elif [ "$action" == update ]; then
|
||||
[ -n "$valid" ] || die "Numéro de version invalide: $version"
|
||||
|
||||
if [ -n "$file" ]; then
|
||||
if [ -f "$file" ]; then
|
||||
if isatty; then
|
||||
estepi "La version actuelle est $version"
|
||||
fi
|
||||
else
|
||||
if isatty; then
|
||||
ask_yesno "Le fichier $(ppath "$file") n'existe pas. Faut-il le créer?" O || die
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# forcer le numéro de version
|
||||
if [ -n "$setversion" ]; then
|
||||
psemver_setversion "$setversion" "" || die "Numéro de version invalide: $setversion"
|
||||
fi
|
||||
|
||||
# Calculer metadata
|
||||
if [ -n "$vcsmetadata" ]; then
|
||||
setmetadata="$(git rev-parse --short HEAD)" || die
|
||||
fi
|
||||
|
||||
# incrémenter les numéros de version
|
||||
if [ "$incversion" == auto ]; then
|
||||
if [ -n "$setrelease" -o -n "$setprelease" -o -n "$setmetadata" ]; then
|
||||
incversion=
|
||||
else
|
||||
incversion=menu
|
||||
fi
|
||||
fi
|
||||
if [ "$incversion" == menu ]; then
|
||||
psemver_copy x; psemver_incmajor x; psemver_setprelease "$setprelease" x; psemver_setmetadata "$setmetadata" x; psemver_setvar versionx x
|
||||
psemver_copy z; psemver_incminor z; psemver_setprelease "$setprelease" z; psemver_setmetadata "$setmetadata" z; psemver_setvar versionz z
|
||||
psemver_copy p; psemver_incpatchlevel p; psemver_setprelease "$setprelease" p; psemver_setmetadata "$setmetadata" p; psemver_setvar versionp p
|
||||
psemver_copy k; psemver_setprelease "$setprelease" k; psemver_setmetadata "$setmetadata" k; psemver_setvar versionk k
|
||||
nextvs=(
|
||||
"$versionx : maj incompatibles de l'API (-x)"
|
||||
"$versionz : maj compatibles de l'API (-z)"
|
||||
"$versionp : correction de bugs (-p)"
|
||||
"$versionk : ne pas incrémenter la version"
|
||||
)
|
||||
nextv="${nextvs[1]}"
|
||||
simple_menu nextv nextvs \
|
||||
-t "Incrémenter le numéro de version" \
|
||||
-m "Veuillez choisir la prochaine version"
|
||||
case "${nextv%)}" in
|
||||
*-x) incversion=major;;
|
||||
*-z) incversion=minor;;
|
||||
*-p) incversion=patchlevel;;
|
||||
*) incversion=;;
|
||||
esac
|
||||
fi
|
||||
if [ -n "$incversion" ]; then
|
||||
case "$incversion" in
|
||||
major) psemver_incmajor;;
|
||||
minor) psemver_incminor;;
|
||||
patchlevel) psemver_incpatchlevel;;
|
||||
esac
|
||||
# Quand on incrémente, réinitialiser la valeur de prérelease et metadata
|
||||
psemver_setprelease
|
||||
psemver_setmetadata
|
||||
fi
|
||||
|
||||
# spécifier prerelease
|
||||
if [ -n "$setrelease" ]; then
|
||||
psemver_setprelease ""
|
||||
elif [ -n "$setprelease" ]; then
|
||||
psemver_setprelease "$setprelease" || die "Identifiant de pre-release invalide: $setprelease"
|
||||
fi
|
||||
if [ -n "$setalpha" ]; then
|
||||
: #XXX
|
||||
elif [ -n "$setbeta" ]; then
|
||||
: #XXX
|
||||
elif [ -n "$setrc" ]; then
|
||||
: #XXX
|
||||
fi
|
||||
|
||||
# spécifier metadata
|
||||
if [ -n "$setmetadata" ]; then
|
||||
psemver_setmetadata "$setmetadata" || die "Identifiant de build invalide: $setmetadata"
|
||||
fi
|
||||
|
||||
# afficher le résultat final
|
||||
psemver_setvar version
|
||||
if [ -n "$file" ]; then
|
||||
echo "$version" >"$file"
|
||||
fi
|
||||
if isatty; then
|
||||
estepn "La nouvelle version est $version"
|
||||
else
|
||||
echo "$version"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
pver "$@"
|
||||
|
|
74
todo/prel
74
todo/prel
|
@ -1,74 +0,0 @@
|
|||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||||
urequire DEFAULTS ptools
|
||||
|
||||
# XXX ajouter la possibilité de faire des pré-releases, --alpha, --beta, --rc
|
||||
# les pré-releases restent dans la branche de release, et vivent leur vie,
|
||||
# jusqu'à la release finale qui est mergée dans master. Il faudrait aussi une
|
||||
# option pour merger les modifications de la branche de release dans develop
|
||||
|
||||
function display_help() {
|
||||
uecho "$scriptname: basculer sur une branche de release
|
||||
|
||||
USAGE
|
||||
$scriptname [options] [SOURCE]
|
||||
|
||||
- Vérifier s'il n'y a pas de modifications locales. Sinon, proposer de faire un
|
||||
commit ou un stash.
|
||||
- Si aucune branche de release n'existe, assumer -u -z pour préparer une release
|
||||
mineure. Sinon, basculer simplement sur la branche de release.
|
||||
|
||||
OPTIONS
|
||||
-C, --projdir PROJDIR
|
||||
Spécifier le répertoire de base du projet qui est dans git. Par défaut,
|
||||
on travaille dans le répertoire courant et on laisse git trouver le
|
||||
répertoire de base du projet. Avec cette option, le répertoire courant
|
||||
est modifié avant de lancer les commandes git.
|
||||
-O, --origin ORIGIN
|
||||
Spécifier le nom de l'origine. Par défaut, utiliser 'origin'
|
||||
-o, --offline
|
||||
En cas de création d'une branche, ne pas pousser vers l'origine; ne pas
|
||||
tenter le cas échéant de traquer la branche dans l'origine; ne pas
|
||||
supprimer une branche dans l'origine. Cette option est automatiquement
|
||||
activée si la variable UTOOLS_VCS_OFFLINE est définie.
|
||||
--online
|
||||
Annuler l'effet de la variable UTOOLS_VCS_OFFLINE: forcer le mode online
|
||||
-u, --update
|
||||
Préparer une release. Utiliser une des options -x, -z ou -p pour
|
||||
spécifier le type de release à préparer. S'il faut créer une nouvelle
|
||||
branche, la baser sur la branche SOURCE, qui vaut par défaut develop
|
||||
-x, --major
|
||||
-z, --minor
|
||||
-p, --patchlevel
|
||||
Utilisé avec l'option -u, préparer respectivement une release majeure,
|
||||
mineure (par défaut), et pour correction de bug.
|
||||
-m, --merge
|
||||
Si la branche actuelle est une branche de release, ou s'il existe une
|
||||
branche de release, la merger dans master, puis dans develop, puis la
|
||||
supprimer. Puis basculer sur la branche master.
|
||||
Si la branche actuelle est une branche de topic et qu'il n'existe aucune
|
||||
branche de release, assumer les options -u -z -m
|
||||
-l, --log
|
||||
Afficher les modifications actuellement effectuée dans la branche de
|
||||
release par rapport à develop.
|
||||
-d, --diff
|
||||
Afficher les modifications actuellement effectuée dans la branche de
|
||||
release par rapport à develop, sous forme de diff."
|
||||
}
|
||||
|
||||
projdir=
|
||||
origin=origin
|
||||
parse_opts "${PRETTYOPTS[@]}" \
|
||||
--help '$exit_with display_help' \
|
||||
-C:,--projdir: projdir= \
|
||||
-O:,--origin: origin= \
|
||||
-o,--offline UTOOLS_VCS_OFFLINE=1 \
|
||||
--online UTOOLS_VCS_OFFLINE= \
|
||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||
|
||||
if [ -n "$projdir" ]; then
|
||||
cd "$projdir" || die
|
||||
fi
|
||||
|
||||
git_ensure_gitvcs
|
Loading…
Reference in New Issue