merge est fait par un script

This commit is contained in:
Jephté Clain 2025-02-28 10:32:32 +04:00
parent 3a2c28b778
commit 0b403ee582
3 changed files with 118 additions and 46 deletions

View File

@ -87,23 +87,34 @@ function _scripta() {
} }
function _script_push_branches() { function _script_push_branches() {
local origin branch [ ${#push_branches[*]} -gt 0 ] || return
_scripte einfo "push branches" [ -n "$Origin" ] || Origin=origin
git_have_remote "$Origin" || return
local branch cmd remote rbranch
for branch in "${push_branches[@]}"; do for branch in "${push_branches[@]}"; do
origin="$Origin" if [[ "$branch" == *:* ]]; then
[ -n "$origin" ] || setx origin=git_get_branch_remote "$branch" cmd="$(qvals git push "$Origin" "$branch")"
[ -n "$origin" ] || origin=origin
setx rbranch=git_get_branch_rbranch "$branch" "$origin"
if [ -n "$rbranch" ]; then
rbranch="${rbranch#refs/remotes/$origin/}"
_scripta <<EOF
$comment$(qvals git push "$origin" "$branch:$rbranch")$or_die
EOF
else else
_scripta <<EOF setx remote=git_get_branch_remote "$branch"
$comment$(qvals git push --set-upstream "$origin" "$branch")$or_die if [ "$remote" == "$Origin" ]; then
EOF setx rbranch=git_get_branch_merge "$branch"
if [ -n "$rbranch" ]; then
# pousser vers la branche distante existante
cmd="$(qvals git push "$Origin" "$branch:${rbranch#refs/heads/}")"
else
# pas de branche distante: pousser et traquer
cmd="$(qvals git push -u "$Origin" "$branch:$branch")"
fi
elif [ -n "$remote" ]; then
# pousser vers un remote différent
cmd="$(qvals git push "$Origin" "$branch:$branch")"
else
# pas de remote: pousser et traquer
cmd="$(qvals git push -u "$Origin" "$branch:$branch")"
fi
fi fi
_scripta <<<"$comment$cmd$or_die"
done done
} }
@ -219,7 +230,7 @@ function _push_branches() {
[ -n "$Origin" ] || Origin=origin [ -n "$Origin" ] || Origin=origin
git_have_remote "$Origin" || return git_have_remote "$Origin" || return
local -a cmds remote rbranch local -a cmds; local branch cmd remote rbranch
for branch in "${push_branches[@]}"; do for branch in "${push_branches[@]}"; do
if [[ "$branch" == *:* ]]; then if [[ "$branch" == *:* ]]; then
cmds+=("$(qvals git push "$Origin" "$branch")") cmds+=("$(qvals git push "$Origin" "$branch")")
@ -262,12 +273,15 @@ function _mscript_start() {
>"$script" >"$script"
_scripta <<EOF _scripta <<EOF
#!/bin/bash #!/bin/bash
$(qvals source "$NULIBDIR/load.sh") || exit 1
merge= merge=
delete=
push= push=
for arg in "\$@"; do for arg in "\$@"; do
case "\$arg" in case "\$arg" in
merge) merge=1;; merge) merge=1;;
delete) delete=1;;
push) push=1;; push) push=1;;
esac esac
done done
@ -275,6 +289,38 @@ EOF
chmod +x "$script" chmod +x "$script"
} }
function _mscript_merge_branch() {
local msg
# basculer sur la branche
_scripta "switch to branch $DestBranch" <<EOF
$comment$(qvals git checkout "$DestBranch")$or_die
EOF
if [ -n "$SquashMsg" ]; then
msg="$SquashMsg"
[ -n "$TechMerge" ] && msg="<pman>$msg"
_scripta "squash merge $SrcBranch" <<EOF
$comment$(qvals git merge "$SrcBranch" --squash)$or_die
$comment$(qvals git commit -m "$msg")$or_die
EOF
else
msg="Intégration de la branche $SrcBranch"
[ -n "$TechMerge" ] && msg="<pman>$msg"
_scripta "merge $SrcBranch" <<EOF
$comment$(qvals git merge "$SrcBranch" --no-ff -m "$msg")$or_die
EOF
fi
array_addu push_branches "$DestBranch"
}
function _mscript_delete_branch() {
_scripta "delete branch $SrcBranch" <<EOF
$comment$(qvals git branch -D "$SrcBranch")$or_die
EOF
array_addu push_branches ":$SrcBranch"
}
################################################################################ ################################################################################
# Release # Release

View File

@ -25,37 +25,59 @@ function ensure_branches() {
} }
function merge_action() { function merge_action() {
local -a push_branches
enote "\ enote "\
Ce script va Ce script va
- fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+ - fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+
- pousser les branches modifiées}" - pousser les branches modifiées}"
ask_yesno "Voulez-vous continuer?" O || die ask_yesno "Voulez-vous continuer?" O || die
local -a push_branches; local msg local script=".git/rel-merge.sh"
local -a push_branches
local comment=
local or_die=" || exit 1"
einfo "Fusion ${SquashMsg:+squash }dans $DestBranch" _mscript_start
git checkout "$DestBranch" || die _scripta <<EOF
if [ -n "$SquashMsg" ]; then ################################################################################
msg="$SquashMsg" # merge
[ -n "$TechMerge" ] && msg="<pman>$msg" if [ -n "\$merge" ]; then
git merge "$SrcBranch" --squash esection "Fusionner la branche"
git commit -m "$msg" EOF
else _mscript_merge_branch
msg="Intégration de la branche $SrcBranch" _scripta <<EOF
[ -n "$TechMerge" ] && msg="<pman>$msg" fi
git merge "$SrcBranch" --no-ff -m "$msg" EOF
_scripta <<EOF
################################################################################
# delete
if [ -n "\$delete" ]; then
esection "Supprimer la branche"
EOF
_mscript_delete_branch
_scripta <<EOF
fi
EOF
_scripta <<EOF
################################################################################
# push
if [ -n "\$push" ]; then
esection "Pousser les branches"
EOF
_script_push_branches
_scripta <<EOF
fi
EOF
if [ -n "$_NoRunScript" ]; then
einfo "Veuillez consulter le script $script pour le détail des opérations à effectuer"
elif ! "$script" merge ${Delete:+delete} ${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 fi
push_branches+=("$DestBranch")
if [ -n "$Delete" ]; then
einfo "Supprimer la branche $SrcBranch"
git branch -D "$SrcBranch"
push_branches+=(":$SrcBranch")
fi
_push_branches
} }
################################################################################ ################################################################################
@ -66,6 +88,8 @@ chdir=
Origin= Origin=
ConfigBranch= ConfigBranch=
ConfigFile= ConfigFile=
_KeepScript=
_NoRunScript=
action=merge action=merge
TechMerge= TechMerge=
SquashMsg= SquashMsg=
@ -82,6 +106,8 @@ branche à partir de laquelle charger la configuration"
-c:,--config-file:CONFIG ConfigFile= "++\ -c:,--config-file:CONFIG ConfigFile= "++\
fichier de configuration des branches. cette option est prioritaire sur --config-branch 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" 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"
--no-run-script _NoRunScript=1 "++option non documentée"
-w,--show action=show "\ -w,--show action=show "\
lister les modifications qui seraient fusionnées dans la branche destination" lister les modifications qui seraient fusionnées dans la branche destination"
-b,--rebase action=rebase "\ -b,--rebase action=rebase "\

View File

@ -26,15 +26,12 @@ function ensure_branches() {
Tag="$TAG_PREFIX$Version$TAG_SUFFIX" Tag="$TAG_PREFIX$Version$TAG_SUFFIX"
local -a tags local -a tags
setx -a tags=git tag -l "${TAG_PREFIX}*${TAG_SUFFIX}" setx -a tags=git tag -l "${TAG_PREFIX}*${TAG_SUFFIX}"
if [ -z "$Force" ]; then if [ -z "$ForceCreate" ]; then
array_contains tags "$Tag" && die "$Tag: le tag correspondant à la version existe déjà" array_contains tags "$Tag" && die "$Tag: le tag correspondant à la version existe déjà"
fi fi
} }
function create_release_action() { function create_release_action() {
local script=".git/rel-release.sh"
local -a push_branches push_tags
if [ -n "$ReleaseBranch" ]; then if [ -n "$ReleaseBranch" ]; then
Version="${ReleaseBranch#$RELEASE}" Version="${ReleaseBranch#$RELEASE}"
merge_release_action "$@"; return $? merge_release_action "$@"; return $?
@ -70,8 +67,11 @@ Vous devrez:
fi fi
ask_yesno "Voulez-vous continuer?" O || die ask_yesno "Voulez-vous continuer?" O || die
local script=".git/rel-release.sh"
local -a push_branches push_tags
local comment= local comment=
local or_die=" || exit 1" local or_die=" || exit 1"
_rscript_start _rscript_start
_scripta <<EOF _scripta <<EOF
################################################################################ ################################################################################
@ -142,14 +142,14 @@ chdir=
Origin= Origin=
ConfigBranch= ConfigBranch=
ConfigFile= ConfigFile=
_KeepScript=
_NoRunScript=
action=release action=release
Merge=1 Merge=1
Push=1 Push=1
Version= Version=
CurrentVersion= CurrentVersion=
Force= ForceCreate=
_KeepScript=
_NoRunScript=
args=( args=(
"faire une nouvelle release à partir de la branche source" "faire une nouvelle release à partir de la branche source"
" -v VERSION [source]" " -v VERSION [source]"
@ -182,7 +182,7 @@ c'est l'option par défaut"
spécifier la version de la release à créer" spécifier la version de la release à créer"
-C,--current-version CurrentVersion=1 "++\ -C,--current-version CurrentVersion=1 "++\
si aucune version n'est spécifiée, prendre la version présente dans le fichier VERSION.txt" si aucune version n'est spécifiée, prendre la version présente dans le fichier VERSION.txt"
-f:,--force Force= "\ -f:,--force-create ForceCreate= "\
forcer la création de la release même si le tag correspond à la version existe déjà" forcer la création de la release même si le tag correspond à la version existe déjà"
) )
parse_args "$@"; set -- "${args[@]}" parse_args "$@"; set -- "${args[@]}"