implémentation initiale de pman
This commit is contained in:
parent
60bd096a29
commit
c76fc0cfb6
@ -11,6 +11,7 @@ FEATURE=wip/
|
||||
RELEASE=release-
|
||||
# branche de release
|
||||
MAIN=master
|
||||
TAG_PREFIX=
|
||||
TAG_SUFFIX=
|
||||
# branche de hotfix
|
||||
HOTFIX=hotfix-
|
||||
|
102
bash/src/pman.sh
102
bash/src/pman.sh
@ -83,7 +83,7 @@ function _script_add() {
|
||||
|
||||
function _push_branches() {
|
||||
local origin branch
|
||||
_rscript_echo "* push branches"
|
||||
_script_echo "* push branches"
|
||||
for branch in "${push_branches[@]}"; do
|
||||
origin="$Origin"
|
||||
[ -n "$origin" ] || setx origin=git_get_branch_remote "$branch"
|
||||
@ -91,11 +91,11 @@ function _push_branches() {
|
||||
setx rbranch=git_get_branch_rbranch "$branch" "$origin"
|
||||
if [ -n "$rbranch" ]; then
|
||||
rbranch="${rbranch#refs/remotes/$origin/}"
|
||||
_rscript_add <<EOF
|
||||
_script_add <<EOF
|
||||
$comment$(qvals git push "$origin" "$branch:$rbranch")$or_die
|
||||
EOF
|
||||
else
|
||||
_rscript_add <<EOF
|
||||
_script_add <<EOF
|
||||
$comment$(qvals git push --set-upstream "$origin" "$branch")$or_die
|
||||
EOF
|
||||
fi
|
||||
@ -104,16 +104,108 @@ EOF
|
||||
|
||||
function _push_tags() {
|
||||
local origin tag
|
||||
_rscript_echo "* push tags"
|
||||
_script_echo "* push tags"
|
||||
for tag in "${push_tags[@]}"; do
|
||||
origin="$Origin"
|
||||
[ -n "$origin" ] || origin=origin
|
||||
_rscript_add <<EOF
|
||||
_script_add <<EOF
|
||||
$comment$(qvals git push --force "$origin" tag "$tag")$or_die
|
||||
EOF
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Config
|
||||
|
||||
function ensure_gitdir() {
|
||||
# commencer dans le répertoire indiqué
|
||||
local chdir="$1"
|
||||
if [ -n "$chdir" ]; then
|
||||
cd "$chdir" || die || return
|
||||
fi
|
||||
|
||||
# se mettre à la racine du dépôt git
|
||||
local gitdir
|
||||
git_ensure_gitvcs
|
||||
setx gitdir=git_get_toplevel
|
||||
cd "$gitdir" || die || return
|
||||
}
|
||||
|
||||
function load_branches() {
|
||||
local what="${1:-all}"; shift
|
||||
case "$what" in
|
||||
all)
|
||||
setx CurrentBranch=git_get_branch
|
||||
setx -a LocalBranches=git_list_branches
|
||||
setx -a RemoteBranches=git_list_rbranches "$Origin"
|
||||
setx -a AllBranches=git_list_pbranches "$Origin"
|
||||
;;
|
||||
current)
|
||||
SrcBranch="$1"
|
||||
[ -n "$SrcBranch" ] || SrcBranch="$CurrentBranch"
|
||||
case "$SrcBranch" in
|
||||
"$UPSTREAM") SrcType=upstream; DestBranch="$DEVELOP";;
|
||||
"$FEATURE"*) SrcType=feature; DestBranch="$DEVELOP";;
|
||||
"$DEVELOP") SrcType=develop; DestBranch="$MAIN";;
|
||||
"$RELEASE"*) SrcType=release; DestBranch="$MAIN";;
|
||||
"$HOTFIX"*) SrcType=hotfix; DestBranch="$MAIN";;
|
||||
"$MAIN") SrcType=main; DestBranch="$DIST";;
|
||||
"$DIST") SrcType=dist; DestBranch=;;
|
||||
*) DestBranch=;;
|
||||
esac
|
||||
|
||||
local branch
|
||||
UpstreamBranch=
|
||||
FeatureBranches=()
|
||||
DevelopBranch=
|
||||
ReleaseBranch=
|
||||
HotfixBranch=
|
||||
MainBranch=
|
||||
Dist=Branch
|
||||
for branch in "${AllBranches[@]}"; do
|
||||
if [ "$branch" == "$UPSTREAM" ]; then
|
||||
UpstreamBranch="$branch"
|
||||
elif [[ "$branch" == "$FEATURE"* ]]; then
|
||||
FeatureBranch+=("$branch")
|
||||
elif [ "$branch" == "$DEVELOP" ]; then
|
||||
DevelopBranch="$branch"
|
||||
elif [[ "$branch" == "$RELEASE"* ]]; then
|
||||
ReleaseBranch="$branch"
|
||||
elif [[ "$branch" == "$HOTFIX"* ]]; then
|
||||
HotfixBranch="$branch"
|
||||
elif [ "$branch" == "$MAIN" ]; then
|
||||
MainBranch="$branch"
|
||||
elif [ "$branch" == "$DIST" ]; then
|
||||
DistBranch="$branch"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function load_config() {
|
||||
if [ -n "$ConfigFile" ]; then
|
||||
source "$ConfigFile" || die || return
|
||||
elif [ -n "$ConfigBranch" ]; then
|
||||
if ! array_contains LocalBranches "$ConfigBranch"; then
|
||||
die "$ConfigBranch: branche de configuration introuvable" || return
|
||||
else
|
||||
ac_set_tmpfile ConfigFile
|
||||
git show "$ConfigBranch:.pman.conf" >"$ConfigFile" 2>/dev/null
|
||||
[ -s "$ConfigFile" ] || die "$ConfigBranch: aucune configuration trouvée sur cette branche" || return
|
||||
source "$ConfigFile"
|
||||
fi
|
||||
elif [ -f .pman.conf ]; then
|
||||
ConfigFile="$(pwd)/.pman.conf"
|
||||
source "$ConfigFile"
|
||||
elif [ -n "${MYNAME#prel}" ]; then
|
||||
ConfigFile="$NULIBDIR/bash/src/pman${MYNAME#$1}.conf.sh"
|
||||
source "$ConfigFile"
|
||||
else
|
||||
ConfigFile="$NULIBDIR/bash/src/pman.conf.sh"
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Merge
|
||||
|
||||
|
@ -9,6 +9,7 @@ DEVELOP=dev74
|
||||
FEATURE=wip74/
|
||||
RELEASE=rel74-
|
||||
MAIN=dist74
|
||||
TAG_PREFIX=
|
||||
TAG_SUFFIX=p74
|
||||
HOTFIX=hotf74-
|
||||
DIST=
|
||||
|
@ -9,6 +9,7 @@ DEVELOP=dev82
|
||||
FEATURE=wip82/
|
||||
RELEASE=rel82-
|
||||
MAIN=dist82
|
||||
TAG_PREFIX=
|
||||
TAG_SUFFIX=p82
|
||||
HOTFIX=hotf82-
|
||||
DIST=
|
||||
|
236
wip/pman
Executable file
236
wip/pman
Executable file
@ -0,0 +1,236 @@
|
||||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/../load.sh" || exit 1
|
||||
require: git pman pman.conf
|
||||
|
||||
################################################################################
|
||||
# Informations
|
||||
################################################################################
|
||||
|
||||
SHOW_VARS=(
|
||||
--Configuration
|
||||
"${CONFIG_VARS[@]}"
|
||||
--Paramètres
|
||||
CurrentBranch
|
||||
SrcType SrcBranch
|
||||
DestBranch
|
||||
)
|
||||
|
||||
function show_action() {
|
||||
echo_setv ConfigBranch="$ConfigBranch"
|
||||
echo_setv ConfigFile="$(ppath "$ConfigFile")"
|
||||
for var in "${SHOW_VARS[@]}"; do
|
||||
if [ "${var#--}" != "$var" ]; then
|
||||
estep "${var#--}"
|
||||
else
|
||||
echo_setv "$var=${!var}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Initialisation
|
||||
################################################################################
|
||||
|
||||
function _push_branches() {
|
||||
[ -n "$Origin" ] || Origin=origin
|
||||
git_have_remote "$Origin" || retun
|
||||
if [ ${#push_branches[*]} -gt 0 ]; then
|
||||
local -a cmds remote rbranch
|
||||
for branch in "${push_branches[@]}"; do
|
||||
setx remote=git_get_branch_remote "$branch"
|
||||
if [ "$remote" == "$Origin" ]; then
|
||||
setx rbranch=git_get_branch_merge "$branch"
|
||||
if [ -n "$rbranch" ]; then
|
||||
cmds+=("$(qvals git push "$Origin" "$branch:$rbranch")")
|
||||
else
|
||||
cmds+=("$(qvals git push -u "$Origin" "$branch:$branch")")
|
||||
fi
|
||||
else
|
||||
cmds+=("$(qvals git push -u "$Origin" "$branch:$branch")")
|
||||
fi
|
||||
done
|
||||
[ -n "$Push" ] || enote "L'option --no-push étant utilisée, les opérations à effectuer sont simplement affichées"
|
||||
for cmd in "${cmds[@]}"; do
|
||||
einfo "$cmd"
|
||||
if [ -n "$Push" ]; then
|
||||
if ! eval "$cmd"; then
|
||||
ewarn "Une erreur s'est produite, les opérations seront simplement affichées"
|
||||
Push=
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function init_repo_action() {
|
||||
[ ${#LocalBranches[*]} -eq 0 ] || die "Ce dépôt a déjà été initialisé"
|
||||
|
||||
local -a push_branches
|
||||
|
||||
if [ ! -f .pman.conf ]; then
|
||||
cp "$ConfigFile" .pman.conf
|
||||
"${EDITOR:-nano}" .pman.conf
|
||||
if testdiff .pman.conf "$ConfigFile"; then
|
||||
ConfigFile="$(pwd)/.pman.conf"
|
||||
load_config
|
||||
load_branches current "$SrcBranch"
|
||||
fi
|
||||
git add .pman.conf
|
||||
fi
|
||||
if [ ! -f ".gitignore" ]; then
|
||||
echo >.gitignore "\
|
||||
.~lock*#
|
||||
.*.swp"
|
||||
git add .gitignore
|
||||
fi
|
||||
|
||||
einfo "Création de la branche $MAIN"
|
||||
git symbolic-ref HEAD "refs/heads/$MAIN"
|
||||
git commit -m "commit initial"
|
||||
push_branches+=("$MAIN")
|
||||
|
||||
einfo "Création de la branche $DEVELOP"
|
||||
git checkout -b "$DEVELOP"
|
||||
push_branches+=("$DEVELOP")
|
||||
|
||||
_push_branches
|
||||
}
|
||||
|
||||
function init_develop_action() {
|
||||
if [ -z "$DevelopBranch" ]; then
|
||||
local -a push_branches
|
||||
|
||||
einfo "Création de la branche $DEVELOP"
|
||||
git checkout -b "$DEVELOP" "$MAIN"
|
||||
push_branches+=("$DEVELOP")
|
||||
|
||||
_push_branches
|
||||
fi
|
||||
git checkout -q "$DEVELOP"
|
||||
}
|
||||
|
||||
function init_upstream_action() {
|
||||
if [ -z "$UpstreamBranch" ]; then
|
||||
[ -n "$UPSTREAM" ] || die "La branche UPSTREAM n'a pas été définie"
|
||||
[ -n "$DevelopBranch" ] || die "$DEVELOP: cette branche n'existe pas"
|
||||
|
||||
local -a push_branches; local config
|
||||
|
||||
# faire une copie de la configuration actuelle
|
||||
ac_set_tmpfile config
|
||||
cp "$ConfigFile" "$config"
|
||||
|
||||
einfo "Création de la branche $UPSTREAM"
|
||||
git checkout --orphan "$UPSTREAM" || die
|
||||
git rm -rf .
|
||||
cp "$config" .pman.conf
|
||||
git add .pman.conf
|
||||
git commit -m "commit initial"
|
||||
push_branches+=("$UPSTREAM")
|
||||
|
||||
einfo "Fusion dans $DEVELOP"
|
||||
git checkout "$DEVELOP"
|
||||
git merge \
|
||||
--no-ff -m "Intégration initiale de la branche $UPSTREAM" \
|
||||
-srecursive -Xours --allow-unrelated-histories \
|
||||
"$UPSTREAM"
|
||||
push_branches+=("$DEVELOP")
|
||||
|
||||
_push_branches
|
||||
fi
|
||||
git checkout -q "$UPSTREAM"
|
||||
}
|
||||
|
||||
function init_dist_action() {
|
||||
if [ -z "$DistBranch" ]; then
|
||||
[ -n "$DIST" ] || die "La branche DIST n'a pas été définie"
|
||||
[ -n "$MainBranch" ] || die "$MAIN: cette branche n'existe pas"
|
||||
|
||||
local -a push_branches
|
||||
|
||||
einfo "Création de la branche $DIST"
|
||||
git checkout -b "$DIST" "$MAIN" || die
|
||||
push_branches+=("$DIST")
|
||||
|
||||
_push_branches
|
||||
fi
|
||||
git checkout -q "$DIST"
|
||||
}
|
||||
|
||||
function init_feature_action() {
|
||||
local branch="$FEATURE${1#$FEATURE}"
|
||||
[ -n "$branch" ] || die "Vous devez définir la nom de la branche à créer"
|
||||
if ! array_contains AllBranches "$branch"; then
|
||||
[ -n "$DEVELOP" ] || die "La branche DEVELOP n'a pas été définie"
|
||||
|
||||
local -a push_branches
|
||||
|
||||
einfo "Création de la branche $branch"
|
||||
git checkout -b "$branch" "$DEVELOP" || die
|
||||
push_branches+=("$branch")
|
||||
|
||||
_push_branches
|
||||
fi
|
||||
git checkout -q "$branch"
|
||||
}
|
||||
|
||||
function init_action() {
|
||||
local what="${1:-develop}"; shift
|
||||
case "$what" in
|
||||
init|repo|r) init_repo_action "$@";;
|
||||
main|m) git checkout -q "$MAIN";;
|
||||
develop|dev|d) init_develop_action "$@";;
|
||||
upstream|up|u) init_upstream_action "$@";;
|
||||
dist|x) init_dist_action "$@";;
|
||||
*) init_feature_action "$what" "$@";;
|
||||
esac
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Programme principal
|
||||
################################################################################
|
||||
|
||||
chdir=
|
||||
ConfigBranch=
|
||||
ConfigFile=
|
||||
action=init
|
||||
Origin=
|
||||
Push=1
|
||||
args=(
|
||||
"gérer un projet git"
|
||||
"repo|develop|upstream|dist"
|
||||
-d:,--chdir:BASEDIR chdir= "répertoire dans lequel se placer avant de lancer les opérations"
|
||||
-b:,--config-branch ConfigBranch= "++\
|
||||
branche à partir de laquelle charger la configuration"
|
||||
-c:,--config-file:CONFIG ConfigFile= "++\
|
||||
fichier de configuration des branches. cette option est prioritaire sur --config-branch
|
||||
par défaut, utiliser le fichier .pman.conf dans le répertoire du dépôt s'il existe"
|
||||
-s,--show-config action=show "++\
|
||||
afficher la configuration chargée"
|
||||
-o:,--origin Origin= "++\
|
||||
origine vers laquelle pousser les branches"
|
||||
-n,--no-push Push= "\
|
||||
ne pas pousser les branches vers leur origine après leur création"
|
||||
-p,--push Push=1 "++\
|
||||
pousser les branches vers leur origine après leur création.
|
||||
c'est l'option par défaut"
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
# charger la configuration
|
||||
ensure_gitdir "$chdir"
|
||||
load_branches all
|
||||
load_config "$MYNAME"
|
||||
load_branches current
|
||||
|
||||
# puis faire l'action que l'on nous demande
|
||||
case "$action" in
|
||||
show)
|
||||
show_action "$@"
|
||||
;;
|
||||
init)
|
||||
git_ensure_cleancheckout
|
||||
init_action "$@"
|
||||
;;
|
||||
esac
|
280
wip/pmerge
Executable file
280
wip/pmerge
Executable file
@ -0,0 +1,280 @@
|
||||
#!/bin/bash
|
||||
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||||
source "$(dirname -- "$0")/../load.sh" || exit 1
|
||||
require: git pman pman.conf
|
||||
|
||||
git_cleancheckout_DIRTY="\
|
||||
Vous avez des modifications locales.
|
||||
Enregistrez ces modifications avant de créer une release"
|
||||
|
||||
################################################################################
|
||||
# Informations
|
||||
################################################################################
|
||||
|
||||
DUMP_VARS=(
|
||||
ConfigBranch
|
||||
ConfigFile
|
||||
--Configuration
|
||||
"${CONFIG_VARS[@]}"
|
||||
--Paramètres
|
||||
CurrentBranch
|
||||
SrcType SrcBranch
|
||||
DestBranch
|
||||
)
|
||||
|
||||
function dump_action() {
|
||||
for var in "${DUMP_VARS[@]}"; do
|
||||
if [ "${var#--}" != "$var" ]; then
|
||||
estep "${var#--}"
|
||||
else
|
||||
echo_setv "$var=${!var}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function show_action() {
|
||||
local commits
|
||||
setx commits=_list_commits
|
||||
if [ -n "$commits" ]; then
|
||||
einfo "Commits à fusionner $SrcBranch --> $DestBranch"
|
||||
eecho "$commits"
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Fusion de branche
|
||||
################################################################################
|
||||
|
||||
function merge_action() {
|
||||
local script=".git/rel-merge.sh"
|
||||
local -a push_branches
|
||||
|
||||
[ -n "$Merge" ] || exit_with edebug "La fusion est désactivée. Ce script va s'arrêter"
|
||||
|
||||
enote "\
|
||||
Ce script va
|
||||
- fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+
|
||||
- pousser les branches modifiées}"
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
|
||||
local comment=
|
||||
local or_die=" || exit 1"
|
||||
_mscript_start
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# merge
|
||||
if [ -n "\$merge" ]; then
|
||||
EOF
|
||||
_merge_any_branch "$DestBranch"
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# push
|
||||
if [ -n "\$push" ]; then
|
||||
EOF
|
||||
_push_branches
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
if ! "$script" ${Merge:+merge} ${Push:+push}; then
|
||||
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
|
||||
elif [ -z "$_KeepScript" ]; then
|
||||
rm "$script"
|
||||
fi
|
||||
}
|
||||
|
||||
function release_upstream_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_feature_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_main_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_dist_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Création et gestion des releases
|
||||
################################################################################
|
||||
|
||||
function ensure_branches() {
|
||||
[ -n "$SrcBranch" -a -n "$DestBranch" ] ||
|
||||
die "$SrcBranch: Aucune configuration de fusion trouvée pour cette branche"
|
||||
|
||||
array_contains LocalBranches "$SrcBranch" || die "$SrcBranch: branche source introuvable"
|
||||
array_contains LocalBranches "$DestBranch" || die "$DestBranch: branche destination introuvable"
|
||||
}
|
||||
|
||||
function release_develop_action() {
|
||||
local script=".git/rel-release.sh"
|
||||
local -a push_branches push_tags
|
||||
|
||||
if [ -n "$ReleaseBranch" ]; then
|
||||
Version="${ReleaseBranch#$RELEASE}"
|
||||
release_release_action "$@"; return $?
|
||||
elif [ -n "$HotfixBranch" ]; then
|
||||
Version="${HotfixBranch#$HOTFIX}"
|
||||
release_hotfix_action "$@"; return $?
|
||||
fi
|
||||
|
||||
[ -n "$Version" ] || die "Vous devez spécifier la version de la release"
|
||||
ReleaseBranch="${RELEASE}$Version"
|
||||
if [ -n "$Merge" ]; then
|
||||
enote "\
|
||||
Ce script va:
|
||||
- créer la branche de release ${COULEUR_VERTE}$ReleaseBranch${COULEUR_NORMALE} <-- ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE}
|
||||
- la provisionner avec une description des changements
|
||||
- la fusionner dans la branche destination ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+
|
||||
- pousser les branches modifiées}"
|
||||
else
|
||||
enote "\
|
||||
Ce script va:
|
||||
- créer la branche de release ${COULEUR_VERTE}$ReleaseBranch${COULEUR_NORMALE} <-- ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE}
|
||||
- la provisionner avec une description des changements
|
||||
Vous devrez:
|
||||
- mettre à jour les informations de release puis relancer ce script"
|
||||
fi
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
|
||||
local comment=
|
||||
local or_die=" || exit 1"
|
||||
_rscript_start
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# create
|
||||
if [ -n "\$create" ]; then
|
||||
EOF
|
||||
_create_release_branch
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# merge
|
||||
if [ -n "\$merge" ]; then
|
||||
EOF
|
||||
_merge_release_branch "$DestBranch" "$TAG_PREFIX$Version$TAG_SUFFIX"
|
||||
_merge_release_branch "$SrcBranch"
|
||||
_delete_release_branch
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# push
|
||||
if [ -n "\$push" ]; then
|
||||
EOF
|
||||
_push_branches
|
||||
_push_tags
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
if ! "$script" create ${Merge:+merge} ${Push:+push}; then
|
||||
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
|
||||
elif [ -z "$_KeepScript" ]; then
|
||||
rm "$script"
|
||||
fi
|
||||
}
|
||||
|
||||
function release_release_action() {
|
||||
enote "\
|
||||
Vous allez:
|
||||
- fusionner la branche de release ${COULEUR_VERTE}$ReleaseBranch${COULEUR_NORMALE}
|
||||
dans la branche destination ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}"
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
}
|
||||
|
||||
function release_hotfix_action() {
|
||||
enote "\
|
||||
Vous allez intégrer la branche de hotfix ${COULEUR_JAUNE}$HotfixBranch${COULEUR_NORMALE}
|
||||
dans la branche destination ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}"
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Programme principal
|
||||
################################################################################
|
||||
|
||||
chdir=
|
||||
Origin=
|
||||
ConfigBranch=
|
||||
ConfigFile=
|
||||
Action=release
|
||||
Merge=1
|
||||
Push=1
|
||||
Version=
|
||||
_KeepScript=
|
||||
args=(
|
||||
"faire une nouvelle release à partir de la branche source"
|
||||
" -gv VERSION [source]"
|
||||
-d:,--chdir:BASEDIR chdir= "répertoire dans lequel se placer avant de lancer les opérations"
|
||||
-o:,--origin Origin= "++\
|
||||
origine à partir de laquelle les branches distantes sont considérées"
|
||||
-b:,--config-branch ConfigBranch= "++\
|
||||
branche à partir de laquelle charger la configuration"
|
||||
-c:,--config-file:CONFIG ConfigFile= "++\
|
||||
fichier de configuration des branches. cette option est prioritaire sur --config-branch
|
||||
par défaut, utiliser le fichier .pman.conf dans le répertoire du dépôt s'il existe"
|
||||
--keep-script _KeepScript=1 "++option non documentée"
|
||||
--init Action=init "++\
|
||||
initialiser les branches $DEVELOP et $MAIN
|
||||
le nom des branches peut différer si un fichier de configuration est fourni"
|
||||
--dump-config Action=dump "++\
|
||||
afficher la configuration chargée"
|
||||
-s,--show Action=show "\
|
||||
lister les modifications qui seraient intégrées dans la release"
|
||||
--release Action=release "créer la release. c'est l'action par défaut"
|
||||
-k,--no-merge Merge= "\
|
||||
ne pas fusionner la branche de release après l'avoir créée. implique --no-push"
|
||||
-m,--merge Merge=1 "++\
|
||||
fusionner la branche de release après l'avoir créée.
|
||||
c'est l'option par défaut"
|
||||
-n,--no-push Push= "\
|
||||
ne pas pousser les branches vers leur origine après la création de la release"
|
||||
-p,--push Push=1 "++\
|
||||
pousser les branches vers leur origine après la création de la release.
|
||||
c'est l'option par défaut"
|
||||
-v:,--version Version= "\
|
||||
spécifier la version de la release à créer"
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
# charger la configuration
|
||||
ensure_gitdir "$chdir"
|
||||
load_branches all
|
||||
load_config
|
||||
load_branches current "$1"
|
||||
if [ -n "$Merge" -a -n "$NOAUTO" ]; then
|
||||
ewarn "L'option --no-merge a été forcée puisque ce dépôt ne supporte pas les releases automatiques"
|
||||
Merge=
|
||||
fi
|
||||
[ -z "$Merge" ] && Push=
|
||||
|
||||
# puis faire l'action que l'on nous demande
|
||||
case "$Action" in
|
||||
init) init_action "$@";;
|
||||
dump) dump_action "$@";;
|
||||
show)
|
||||
git_check_cleancheckout || ewarn "$git_cleancheckout_DIRTY"
|
||||
ensure_branches
|
||||
show_action "$@"
|
||||
;;
|
||||
release)
|
||||
git_ensure_cleancheckout
|
||||
ensure_branches
|
||||
"release_${SrcType}_action" "$@"
|
||||
;;
|
||||
esac
|
196
wip/prel
196
wip/prel
@ -7,97 +7,6 @@ git_cleancheckout_DIRTY="\
|
||||
Vous avez des modifications locales.
|
||||
Enregistrez ces modifications avant de créer une release"
|
||||
|
||||
function load_branches() {
|
||||
setx CurrentBranch=git_get_branch
|
||||
setx -a LocalBranches=git_list_branches
|
||||
setx -a RemoteBranches=git_list_rbranches "$Origin"
|
||||
setx -a AllBranches=git_list_pbranches "$Origin"
|
||||
}
|
||||
|
||||
function load_config() {
|
||||
if [ -n "$ConfigFile" ]; then
|
||||
source "$ConfigFile" || die
|
||||
elif [ -n "$ConfigBranch" ]; then
|
||||
if ! array_contains LocalBranches "$ConfigBranch"; then
|
||||
die "$ConfigBranch: branche de configuration introuvable"
|
||||
else
|
||||
local config="$(git show "$ConfigBranch:.pman.conf" 2>/dev/null)"
|
||||
[ -n "$config" ] || die "$ConfigBranch: aucune configuration trouvée sur cette branche"
|
||||
eval "$config"
|
||||
fi
|
||||
elif [ -f .pman.conf ]; then
|
||||
ConfigFile=.pman.conf
|
||||
source "$ConfigFile"
|
||||
elif [ -n "${MYNAME#prel}" ]; then
|
||||
require: pman${MYNAME#prel}.conf
|
||||
fi
|
||||
|
||||
SrcBranch="$1"
|
||||
[ -n "$SrcBranch" ] || SrcBranch="$CurrentBranch"
|
||||
case "$SrcBranch" in
|
||||
"$UPSTREAM") SrcType=upstream; DestBranch="$DEVELOP";;
|
||||
"$FEATURE"*) SrcType=feature; DestBranch="$DEVELOP";;
|
||||
"$DEVELOP") SrcType=develop; DestBranch="$MAIN";;
|
||||
"$RELEASE"*) SrcType=release; DestBranch="$MAIN";;
|
||||
"$HOTFIX"*) SrcType=hotfix; DestBranch="$MAIN";;
|
||||
"$MAIN") SrcType=main; DestBranch="$DIST";;
|
||||
"$DIST") SrcType=dist; DestBranch=;;
|
||||
*) DestBranch=;;
|
||||
esac
|
||||
}
|
||||
|
||||
function ensure_branches() {
|
||||
[ -n "$SrcBranch" -a -n "$DestBranch" ] ||
|
||||
die "$SrcBranch: Aucune configuration de fusion trouvée pour cette branche"
|
||||
|
||||
array_contains AllBranches "$SrcBranch" || die "$SrcBranch: branche source introuvable"
|
||||
array_contains AllBranches "$DestBranch" || die "$DestBranch: branche destination introuvable"
|
||||
|
||||
local branch
|
||||
ReleaseBranch=
|
||||
HotfixBranch=
|
||||
for branch in "${AllBranches[@]}"; do
|
||||
if [[ "$branch" == "$RELEASE"* ]]; then
|
||||
ReleaseBranch="$branch"
|
||||
elif [[ "$branch" == "$HOTFIX"* ]]; then
|
||||
HotfixBranch="$branch"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Initialisation
|
||||
################################################################################
|
||||
|
||||
function init_action() {
|
||||
:
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Informations
|
||||
################################################################################
|
||||
|
||||
DUMP_VARS=(
|
||||
ConfigBranch
|
||||
ConfigFile
|
||||
--Configuration
|
||||
"${CONFIG_VARS[@]}"
|
||||
--Paramètres
|
||||
CurrentBranch
|
||||
SrcType SrcBranch
|
||||
DestBranch
|
||||
)
|
||||
|
||||
function dump_action() {
|
||||
for var in "${DUMP_VARS[@]}"; do
|
||||
if [ "${var#--}" != "$var" ]; then
|
||||
estep "${var#--}"
|
||||
else
|
||||
echo_setv "$var=${!var}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function show_action() {
|
||||
local commits
|
||||
setx commits=_list_commits
|
||||
@ -107,72 +16,14 @@ function show_action() {
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Fusion de branche
|
||||
################################################################################
|
||||
function ensure_branches() {
|
||||
[ -n "$SrcBranch" -a -n "$DestBranch" ] ||
|
||||
die "$SrcBranch: Aucune configuration de fusion trouvée pour cette branche"
|
||||
|
||||
function merge_action() {
|
||||
local script=".git/rel-merge.sh"
|
||||
local -a push_branches
|
||||
|
||||
[ -n "$Merge" ] || exit_with edebug "La fusion est désactivée. Ce script va s'arrêter"
|
||||
|
||||
enote "\
|
||||
Ce script va
|
||||
- fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+
|
||||
- pousser les branches modifiées}"
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
|
||||
local comment=
|
||||
local or_die=" || exit 1"
|
||||
_mscript_start
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# merge
|
||||
if [ -n "\$merge" ]; then
|
||||
EOF
|
||||
_merge_any_branch "$DestBranch"
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
_script_add <<EOF
|
||||
################################################################################
|
||||
# push
|
||||
if [ -n "\$push" ]; then
|
||||
EOF
|
||||
_push_branches
|
||||
_script_add <<EOF
|
||||
fi
|
||||
EOF
|
||||
|
||||
if ! "$script" ${Merge:+merge} ${Push:+push}; then
|
||||
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
|
||||
elif [ -z "$_KeepScript" ]; then
|
||||
rm "$script"
|
||||
fi
|
||||
array_contains LocalBranches "$SrcBranch" || die "$SrcBranch: branche source introuvable"
|
||||
array_contains LocalBranches "$DestBranch" || die "$DestBranch: branche destination introuvable"
|
||||
}
|
||||
|
||||
function release_upstream_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_feature_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_main_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
function release_dist_action() {
|
||||
merge_action "$@"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Création et gestion des releases
|
||||
################################################################################
|
||||
|
||||
function release_develop_action() {
|
||||
local script=".git/rel-release.sh"
|
||||
local -a push_branches push_tags
|
||||
@ -211,6 +62,7 @@ Vous devrez:
|
||||
################################################################################
|
||||
# create
|
||||
if [ -n "\$create" ]; then
|
||||
echo "== Création de la release"
|
||||
EOF
|
||||
_create_release_branch
|
||||
_script_add <<EOF
|
||||
@ -221,6 +73,7 @@ EOF
|
||||
################################################################################
|
||||
# merge
|
||||
if [ -n "\$merge" ]; then
|
||||
echo "== Fusionner la release"
|
||||
EOF
|
||||
_merge_release_branch "$DestBranch" "$TAG_PREFIX$Version$TAG_SUFFIX"
|
||||
_merge_release_branch "$SrcBranch"
|
||||
@ -233,6 +86,7 @@ EOF
|
||||
################################################################################
|
||||
# push
|
||||
if [ -n "\$push" ]; then
|
||||
echo "== Pousser branches et tags"
|
||||
EOF
|
||||
_push_branches
|
||||
_push_tags
|
||||
@ -242,12 +96,13 @@ EOF
|
||||
|
||||
if ! "$script" create ${Merge:+merge} ${Push:+push}; then
|
||||
eimportant "Veuillez consulter le script $script pour le détail des opérations qui n'ont pas pu êtres effectuées"
|
||||
die
|
||||
elif [ -z "$_KeepScript" ]; then
|
||||
rm "$script"
|
||||
fi
|
||||
}
|
||||
|
||||
function release_release_action() {
|
||||
function merge_release_main_action() {
|
||||
enote "\
|
||||
Vous allez:
|
||||
- fusionner la branche de release ${COULEUR_VERTE}$ReleaseBranch${COULEUR_NORMALE}
|
||||
@ -255,7 +110,7 @@ Vous allez:
|
||||
ask_yesno "Voulez-vous continuer?" O || die
|
||||
}
|
||||
|
||||
function release_hotfix_action() {
|
||||
function merge_hotfix_main_action() {
|
||||
enote "\
|
||||
Vous allez intégrer la branche de hotfix ${COULEUR_JAUNE}$HotfixBranch${COULEUR_NORMALE}
|
||||
dans la branche destination ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}"
|
||||
@ -287,11 +142,6 @@ branche à partir de laquelle charger la configuration"
|
||||
fichier de configuration des branches. cette option est prioritaire sur --config-branch
|
||||
par défaut, utiliser le fichier .pman.conf dans le répertoire du dépôt s'il existe"
|
||||
--keep-script _KeepScript=1 "++option non documentée"
|
||||
--init Action=init "++\
|
||||
initialiser les branches $DEVELOP et $MAIN
|
||||
le nom des branches peut différer si un fichier de configuration est fourni"
|
||||
--dump-config Action=dump "++\
|
||||
afficher la configuration chargée"
|
||||
-s,--show Action=show "\
|
||||
lister les modifications qui seraient intégrées dans la release"
|
||||
--release Action=release "créer la release. c'est l'action par défaut"
|
||||
@ -310,19 +160,11 @@ spécifier la version de la release à créer"
|
||||
)
|
||||
parse_args "$@"; set -- "${args[@]}"
|
||||
|
||||
# commencer dans le répertoire indiqué
|
||||
if [ -n "$chdir" ]; then
|
||||
cd "$chdir" || die
|
||||
fi
|
||||
|
||||
# se mettre à la racine du dépôt git
|
||||
git_ensure_gitvcs
|
||||
setx gitdir=git_get_toplevel
|
||||
cd "$gitdir" || die
|
||||
|
||||
# charger la configuration
|
||||
load_branches
|
||||
load_config "$1"
|
||||
ensure_gitdir "$chdir"
|
||||
load_branches all
|
||||
load_config
|
||||
load_branches current "$1"; shift
|
||||
if [ -n "$Merge" -a -n "$NOAUTO" ]; then
|
||||
ewarn "L'option --no-merge a été forcée puisque ce dépôt ne supporte pas les releases automatiques"
|
||||
Merge=
|
||||
@ -331,8 +173,6 @@ fi
|
||||
|
||||
# puis faire l'action que l'on nous demande
|
||||
case "$Action" in
|
||||
init) init_action "$@";;
|
||||
dump) dump_action "$@";;
|
||||
show)
|
||||
git_check_cleancheckout || ewarn "$git_cleancheckout_DIRTY"
|
||||
ensure_branches
|
||||
@ -341,6 +181,10 @@ show)
|
||||
release)
|
||||
git_ensure_cleancheckout
|
||||
ensure_branches
|
||||
"release_${SrcType}_action" "$@"
|
||||
case "$SrcType" in
|
||||
release) merge_release_main_action "$@";;
|
||||
hotfix) merge_hotfix_main_action "$@";;
|
||||
*) release_develop_action "$@";;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user