diff --git a/bash/src/pman.sh b/bash/src/pman.sh index 93bd6ce..f2f5d3d 100644 --- a/bash/src/pman.sh +++ b/bash/src/pman.sh @@ -159,6 +159,7 @@ function load_branches() { local what="${1:-all}"; shift case "$what" in all) + [ -n "$Origin" ] || Origin=origin setx CurrentBranch=git_get_branch setx -a LocalBranches=git_list_branches setx -a RemoteBranches=git_list_rbranches "$Origin" @@ -195,12 +196,12 @@ function load_branches() { ReleaseBranch= HotfixBranch= MainBranch= - Dist=Branch - for branch in "${AllBranches[@]}"; do + DistBranch= + for branch in "${LocalBranches[@]}"; do if [ "$branch" == "$UPSTREAM" ]; then UpstreamBranch="$branch" elif [[ "$branch" == "$FEATURE"* ]]; then - FeatureBranch+=("$branch") + FeatureBranches+=("$branch") elif [ "$branch" == "$DEVELOP" ]; then DevelopBranch="$branch" elif [[ "$branch" == "$RELEASE"* ]]; then @@ -252,6 +253,16 @@ function load_config() { ################################################################################ # Divers +function resolve_should_push() { + local quiet="$1" + ShouldPush=1 + if ! git_have_remote "$Origin" && [ -n "$Push" ]; then + [ -n "$quiet" ] || enote "L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" + ShouldPush= + fi + [ -z "$ShouldPush" ] && Push= +} + function _push_branches() { [ ${#push_branches[*]} -gt 0 ] || return [ -n "$Origin" ] || Origin=origin diff --git a/bin/pdev b/bin/pdev index 8424508..10c522c 100755 --- a/bin/pdev +++ b/bin/pdev @@ -139,7 +139,7 @@ args=( " [source] CONFIGURATION -Le fichier .pman.conf contient la configuration des branches.Les variables +Le fichier .pman.conf contient la configuration des branches. Les variables supplémentaires suivantes peuvent être définies: AFTER_MERGE_ AFTER_DELETE_ @@ -186,12 +186,7 @@ load_branches all load_config "$MYNAME" load_branches current "$1" -ShouldPush=1 -[ -n "$Origin" ] || Origin=origin -if ! git_have_remote "$Origin" && [ -n "$Push" ]; then - ShouldPush= -fi -[ -z "$ShouldPush" ] && Push= +resolve_should_push quiet # puis faire l'action que l'on nous demande case "$action" in @@ -213,17 +208,14 @@ merge) esac [ -z "$ShouldDelete" ] && Delete= git_ensure_cleancheckout - if ! array_contains LocalBranches "$SrcBranch"; then - # si la branche source n'existe pas, la créer - args=(--origin "$Origin") - if [ -n "$ConfigFile" ]; then args+=(--config-file "$ConfigFile") - elif [ -n "$ConfigBranch" ]; then args+=(--config-branch "$ConfigBranch") - fi - [ -z "$Push" ] && args+=(--no-push) - exec "$MYDIR/pman" "${args[@]}" "$FEATURE${SrcBranch#$FEATURE}" - else + if array_contains LocalBranches "$SrcBranch"; then ensure_branches merge_action "$@" + elif array_contains AllBranches "$SrcBranch"; then + enote "$SrcBranch: une branche du même nom existe dans l'origine" + die "$SrcBranch: branche locale introuvable" + else + die "$SrcBranch: branche introuvable" fi ;; *) diff --git a/bin/pman b/bin/pman index cda0729..aef33b5 100755 --- a/bin/pman +++ b/bin/pman @@ -34,16 +34,6 @@ function show_action() { # Initialisation ################################################################################ -function resolve_should_push() { - ShouldPush=1 - [ -n "$Origin" ] || Origin=origin - if ! git_have_remote "$Origin" && [ -n "$Push" ]; then - enote "L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" - ShouldPush= - fi - [ -z "$ShouldPush" ] && Push= -} - function _init_config() { if [ ! -f .pman.conf -o -n "$ForceCreate" ]; then ac_set_tmpfile config @@ -73,7 +63,6 @@ function init_repo_action() { [ ${#LocalBranches[*]} -eq 0 ] || die "Ce dépôt a déjà été initialisé" - [ -n "$Origin" ] || Origin=origin _init_config || exit_with ewarn "Initialisation du dépôt annulée" einfo "Création de la branche $MAIN" diff --git a/bin/prel b/bin/prel index 095dea6..8dceaaa 100755 --- a/bin/prel +++ b/bin/prel @@ -189,9 +189,8 @@ args=( " -v VERSION [source] CONFIGURATION -Le fichier .pman.conf contient la configuration des branches - -Les variables supplémentaires suivantes peuvent être définies: +Le fichier .pman.conf contient la configuration des branches. Les variables +supplémentaires suivantes peuvent être définies: AFTER_CREATE_RELEASE AFTER_MERGE_RELEASE AFTER_PUSH_RELEASE" @@ -239,12 +238,7 @@ load_branches current "$1"; shift [ -n "$ManualRelease" ] && Merge= [ -z "$Merge" ] && Push= -ShouldPush=1 -[ -n "$Origin" ] || Origin=origin -if ! git_have_remote "$Origin" && [ -n "$Push" ]; then - ShouldPush= -fi -[ -z "$ShouldPush" ] && Push= +resolve_should_push quiet # puis faire l'action que l'on nous demande case "$action" in diff --git a/bin/pwip b/bin/pwip new file mode 100755 index 0000000..787676b --- /dev/null +++ b/bin/pwip @@ -0,0 +1,60 @@ +#!/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 nouvelle branche" + +chdir= +Origin= +ConfigBranch= +ConfigFile= +[ -z "$PMAN_NO_PUSH" ] && Push=1 || Push= +args=( + "créer une branche de feature" + "" + -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" + -n,--no-push Push= "\ +ne pas pousser les branches vers leur origine après la fusion" + --push Push=1 "++\ +pousser les branches vers leur origine après la fusion. +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 + +branch="$1" +if [ -z "$branch" -a ${#FeatureBranches[*]} -eq 1 ]; then + branch="${FeatureBranches[0]}" +fi +[ -n "$branch" ] || die "Vous devez spécifier la branche à créer" +branch="$FEATURE${branch#$FEATURE}" + +resolve_should_push +git_ensure_cleancheckout + +if array_contains AllBranches "$branch"; then + git checkout -q "$branch" +else + # si la branche source n'existe pas, la créer + args=(--origin "$Origin") + if [ -n "$ConfigFile" ]; then args+=(--config-file "$ConfigFile") + elif [ -n "$ConfigBranch" ]; then args+=(--config-branch "$ConfigBranch") + fi + [ -z "$Push" ] && args+=(--no-push) + exec "$MYDIR/pman" "${args[@]}" "$branch" +fi