pman: améliorer l'ergonomie
This commit is contained in:
		
							parent
							
								
									0cfad79ec0
								
							
						
					
					
						commit
						9a2378ba74
					
				| @ -224,13 +224,15 @@ function load_config() { | ||||
|     if [ -n "$ConfigFile" ]; then | ||||
|         source "$ConfigFile" || die || return | ||||
|     elif [ -n "$ConfigBranch" ]; then | ||||
|         # c'est le seul cas où ConfigFile reste vide | ||||
|         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" | ||||
|             local config | ||||
|             ac_set_tmpfile config | ||||
|             git show "$ConfigBranch:.pman.conf" >"$config" 2>/dev/null | ||||
|             [ -s "$config" ] || die "$ConfigBranch: aucune configuration trouvée sur cette branche" || return | ||||
|             source "$config" | ||||
|         fi | ||||
|     elif [ -f .pman.conf ]; then | ||||
|         ConfigFile="$(pwd)/.pman.conf" | ||||
|  | ||||
							
								
								
									
										44
									
								
								bin/pdev
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								bin/pdev
									
									
									
									
									
								
							| @ -25,6 +25,9 @@ function ensure_branches() { | ||||
| } | ||||
| 
 | ||||
| function merge_action() { | ||||
|     [ -z "$ShouldPush" ] && enote "\ | ||||
| L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" | ||||
| 
 | ||||
|     enote "\ | ||||
| Ce script va | ||||
| - fusionner la branche ${COULEUR_BLEUE}$SrcBranch${COULEUR_NORMALE} dans ${COULEUR_ROUGE}$DestBranch${COULEUR_NORMALE}${Push:+ | ||||
| @ -54,7 +57,7 @@ EOF | ||||
| fi | ||||
| EOF | ||||
| 
 | ||||
|     if [ -z "$ForbidDelete" ]; then | ||||
|     if [ -n "$ShouldDelete" ]; then | ||||
|         _scripta <<EOF | ||||
| ################################################################################ | ||||
| # delete | ||||
| @ -94,26 +97,25 @@ EOF | ||||
| fi | ||||
| EOF | ||||
| 
 | ||||
|     [ -n "$Delete" -o "$ForbidDelete" ] && Deleted=1 || Deleted= | ||||
|     [ -n "$Push" -o "$CantPush" ] && Pushed=1 || Pushed= | ||||
|     [ -n "$ShouldDelete" -a -n "$Delete" ] && ShouldDelete= | ||||
|     [ -n "$ShouldPush" -a -n "$Push" ] && ShouldPush= | ||||
|     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 "\ | ||||
| Le script $script a été lancé avec les arguments 'merge${Delete:+ delete}${Push:+ push}' | ||||
| Veuillez le consulter pour le détail des opérations qui n'ont pas pu êtres effectuées" | ||||
| En cas d'erreur de merge, veuillez corriger les erreurs puis continuer avec | ||||
|     git merge --continue | ||||
| Sinon, veuillez consulter le script et/ou le relancer | ||||
|     ./$script${Delete:+ delete}${Push:+ push}" | ||||
|         die | ||||
|     elif [ -n "$Deleted" -a -n "$Pushed" ]; then | ||||
|     elif [ -n "$Delete" -a -n "$Push" ]; then | ||||
|         [ -n "$_KeepScript" ] || rm "$script" | ||||
|     else | ||||
|         local cmd | ||||
|         [ -n "$Deleted" ] || cmd="$cmd | ||||
|     ./$script delete" | ||||
|         [ -n "$Pushed" ] || cmd="$cmd | ||||
|     ./$script push" | ||||
|         einfo "\ | ||||
| Le script $script a été lancé avec les arguments 'merge${Delete:+ delete}${Push:+ push}' | ||||
| Veuillez le consulter pour le détail des autres opérations à effectuer$cmd" | ||||
| Vous pouvez consulter le script et/ou le relancer | ||||
|     ./$script${ShouldDelete:+ delete}${ShouldPush:+ push}" | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| @ -184,13 +186,12 @@ load_branches all | ||||
| load_config "$MYNAME" | ||||
| load_branches current "$1" | ||||
| 
 | ||||
| CantPush= | ||||
| ShouldPush=1 | ||||
| [ -n "$Origin" ] || Origin=origin | ||||
| if ! git_have_remote "$Origin" && [ -n "$Push" ]; then | ||||
|     ewarn "L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" | ||||
|     CantPush=1 | ||||
|     ShouldPush= | ||||
| fi | ||||
| [ -n "$CantPush" ] && Push= | ||||
| [ -z "$ShouldPush" ] && Push= | ||||
| 
 | ||||
| # puis faire l'action que l'on nous demande | ||||
| case "$action" in | ||||
| @ -200,21 +201,26 @@ show) | ||||
|     show_action "$@" | ||||
|     ;; | ||||
| merge) | ||||
|     ForbidDelete= | ||||
|     ShouldDelete=1 | ||||
|     case "$SrcType" in | ||||
|     develop|release|hotfix) | ||||
|         die "$SrcBranch: cette branche doit être fusionnée dans $DestBranch avec prel" | ||||
|         ;; | ||||
|     *) | ||||
|         # n'autoriser la suppression que pour feature | ||||
|         [ "$SrcType" == feature ] || ForbidDelete=1 | ||||
|         [ "$SrcType" == feature ] || ShouldDelete= | ||||
|         ;; | ||||
|     esac | ||||
|     [ -n "$ForbidDelete" ] && Delete= | ||||
|     [ -z "$ShouldDelete" ] && Delete= | ||||
|     git_ensure_cleancheckout | ||||
|     if ! array_contains LocalBranches "$SrcBranch"; then | ||||
|         # si la branche source n'existe pas, la créer | ||||
|         exec "$MYDIR/pman" "$FEATURE${SrcBranch#$FEATURE}" | ||||
|         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 | ||||
|         ensure_branches | ||||
|         merge_action "$@" | ||||
|  | ||||
							
								
								
									
										98
									
								
								bin/pman
									
									
									
									
									
								
							
							
						
						
									
										98
									
								
								bin/pman
									
									
									
									
									
								
							| @ -34,6 +34,16 @@ 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 | ||||
| @ -59,10 +69,11 @@ function _init_config() { | ||||
| } | ||||
| 
 | ||||
| function init_repo_action() { | ||||
|     local -a push_branches; local config | ||||
| 
 | ||||
|     [ ${#LocalBranches[*]} -eq 0 ] || die "Ce dépôt a déjà été initialisé" | ||||
| 
 | ||||
|     local -a push_branches | ||||
| 
 | ||||
|     [ -n "$Origin" ] || Origin=origin | ||||
|     _init_config || exit_with ewarn "Initialisation du dépôt annulée" | ||||
| 
 | ||||
|     einfo "Création de la branche $MAIN" | ||||
| @ -78,9 +89,11 @@ function init_repo_action() { | ||||
| } | ||||
| 
 | ||||
| function init_config_action() { | ||||
|     [ -f .pman.conf ] && die "La configuration pman a déjà été initialisée" | ||||
|     local -a push_branches; config | ||||
| 
 | ||||
|     local -a push_branches | ||||
|     [ -f .pman.conf -a -z "$ForceCreate" ] && die "La configuration pman a déjà été initialisée" | ||||
| 
 | ||||
|     resolve_should_push | ||||
| 
 | ||||
|     _init_config || exit_with ewarn "Initialisation de la configuration annulée" | ||||
|     git commit -m "configuration pman" | ||||
| @ -89,17 +102,33 @@ function init_config_action() { | ||||
|     _push_branches | ||||
| } | ||||
| 
 | ||||
| function _ensure_main_branch() { | ||||
|     [ -n "$MAIN" ] || die "La branche MAIN n'a pas été définie" | ||||
|     [ -n "$MainBranch" ] || die "$MAIN: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
| } | ||||
| 
 | ||||
| function checkout_main_action() { | ||||
|     _ensure_main_branch | ||||
|     git checkout -q "$MAIN" | ||||
| } | ||||
| 
 | ||||
| function _ensure_develop_branch() { | ||||
|     [ -n "$DEVELOP" ] || die "La branche DEVELOP n'a pas été définie" | ||||
|     [ -n "$DevelopBranch" ] || die "$DEVELOP: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
| } | ||||
| 
 | ||||
| function init_develop_action() { | ||||
|     local -a push_branches | ||||
| 
 | ||||
|     if [ -z "$DevelopBranch" ]; then | ||||
|         [ -n "$DEVELOP" ] || die "La branche DEVELOP n'a pas été définie" | ||||
|         [ -n "$MAIN" ] || die "La branche MAIN n'a pas été définie" | ||||
|         [ -n "$MainBranch" ] || die "$MAIN: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
|         _ensure_main_branch | ||||
|         _ensure_develop_branch | ||||
| 
 | ||||
|         resolve_should_push | ||||
| 
 | ||||
|         enote "Vous allez créer la branche ${COULEUR_VERTE}$DEVELOP${COULEUR_NORMALE} <-- ${COULEUR_BLEUE}$MAIN${COULEUR_NORMALE}" | ||||
|         ask_yesno "Voulez-vous continuer?" O || die | ||||
| 
 | ||||
|         local -a push_branches | ||||
| 
 | ||||
|         einfo "Création de la branche $DEVELOP" | ||||
|         git checkout -b "$DEVELOP" "$MAIN" || die | ||||
|         push_branches+=("$DEVELOP") | ||||
| @ -109,17 +138,23 @@ function init_develop_action() { | ||||
|     git checkout -q "$DEVELOP" | ||||
| } | ||||
| 
 | ||||
| function _ensure_upstream_branch() { | ||||
|     [ -n "$UPSTREAM" ] || die "La branche UPSTREAM n'a pas été définie" | ||||
|     [ -n "$UpstreamBranch" ] || die "$UPSTREAM: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
| } | ||||
| 
 | ||||
| function init_upstream_action() { | ||||
|     local -a push_branches; local config | ||||
| 
 | ||||
|     if [ -z "$UpstreamBranch" ]; then | ||||
|         [ -n "$UPSTREAM" ] || die "La branche UPSTREAM n'a pas été définie" | ||||
|         [ -n "$DEVELOP" ] || die "La branche DEVELOP n'a pas été définie" | ||||
|         [ -n "$DevelopBranch" ] || die "$DEVELOP: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
|         _ensure_develop_branch | ||||
|         _ensure_upstream_branch | ||||
| 
 | ||||
|         resolve_should_push | ||||
| 
 | ||||
|         enote "Vous allez créer la branche ${COULEUR_VERTE}$UPSTREAM${COULEUR_NORMALE}" | ||||
|         ask_yesno "Voulez-vous continuer?" O || die | ||||
| 
 | ||||
|         local -a push_branches; local config | ||||
| 
 | ||||
|         # faire une copie de la configuration actuelle | ||||
|         ac_set_tmpfile config | ||||
|         cp "$ConfigFile" "$config" | ||||
| @ -145,17 +180,23 @@ function init_upstream_action() { | ||||
|     git checkout -q "$UPSTREAM" | ||||
| } | ||||
| 
 | ||||
| function _ensure_dist_branch() { | ||||
|     [ -n "$DIST" ] || die "La branche DIST n'a pas été définie" | ||||
|     [ -n "$DistBranch" ] || die "$DIST: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
| } | ||||
| 
 | ||||
| function init_dist_action() { | ||||
|     local -a push_branches | ||||
| 
 | ||||
|     if [ -z "$DistBranch" ]; then | ||||
|         [ -n "$DIST" ] || die "La branche DIST n'a pas été définie" | ||||
|         [ -n "$MAIN" ] || die "La branche MAIN n'a pas été définie" | ||||
|         [ -n "$MainBranch" ] || die "$MAIN: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
|         _ensure_main_branch | ||||
|         _ensure_dist_branch | ||||
| 
 | ||||
|         resolve_should_push | ||||
| 
 | ||||
|         enote "Vous allez créer la branche ${COULEUR_VERTE}$DIST${COULEUR_NORMALE} <-- ${COULEUR_BLEUE}$MAIN${COULEUR_NORMALE}" | ||||
|         ask_yesno "Voulez-vous continuer?" O || die | ||||
| 
 | ||||
|         local -a push_branches | ||||
| 
 | ||||
|         einfo "Création de la branche $DIST" | ||||
|         git checkout -b "$DIST" "$MAIN" || die | ||||
|         push_branches+=("$DIST") | ||||
| @ -166,18 +207,21 @@ function init_dist_action() { | ||||
| } | ||||
| 
 | ||||
| function init_feature_action() { | ||||
|     local branch="${1#$FEATURE}" | ||||
|     [ -n "$branch" ] || die "Vous devez définir la nom de la branche à créer" | ||||
|     local -a push_branches; local branch | ||||
| 
 | ||||
|     [ -n "$FEATURE" ] || die "La branche FEATURE n'a pas été définie" | ||||
|     branch="${1#$FEATURE}" | ||||
|     [ -n "$branch" ] || die "Vous devez spécifier le nom de la branche" | ||||
|     branch="$FEATURE$branch" | ||||
| 
 | ||||
|     if ! array_contains AllBranches "$branch"; then | ||||
|         [ -n "$DEVELOP" ] || die "La branche DEVELOP n'a pas été définie" | ||||
|         [ -n "$DevelopBranch" ] || die "$DEVELOP: cette branche n'existe pas (le dépôt a-t-il été initialisé?)" | ||||
|         _ensure_develop_branch | ||||
| 
 | ||||
|         resolve_should_push | ||||
| 
 | ||||
|         enote "Vous allez créer la branche ${COULEUR_VERTE}$branch${COULEUR_NORMALE} <-- ${COULEUR_BLEUE}$DEVELOP${COULEUR_NORMALE}" | ||||
|         ask_yesno "Voulez-vous continuer?" O || die | ||||
| 
 | ||||
|         local -a push_branches | ||||
| 
 | ||||
|         einfo "Création de la branche $branch" | ||||
|         git checkout -b "$branch" "$DEVELOP" || die | ||||
|         push_branches+=("$branch") | ||||
| @ -192,7 +236,7 @@ function init_action() { | ||||
|     case "$what" in | ||||
|     init|repo|r) init_repo_action "$@";; | ||||
|     config) init_config_action "$@";; | ||||
|     main|m) git checkout -q "$MAIN";; | ||||
|     main|m) checkout_main_action;; | ||||
|     develop|dev|d) init_develop_action "$@";; | ||||
|     upstream|up|u) init_upstream_action "$@";; | ||||
|     dist|x) init_dist_action "$@";; | ||||
| @ -209,7 +253,7 @@ ConfigBranch= | ||||
| ConfigFile= | ||||
| action=init | ||||
| Origin= | ||||
| Push=1 | ||||
| [ -z "$PMAN_NO_PUSH" ] && Push=1 || Push= | ||||
| ForceCreate= | ||||
| args=( | ||||
|     "gérer un projet git" | ||||
|  | ||||
							
								
								
									
										28
									
								
								bin/prel
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bin/prel
									
									
									
									
									
								
							| @ -44,6 +44,8 @@ function create_release_action() { | ||||
| 
 | ||||
|     [ -n "$ManualRelease" ] && ewarn "\ | ||||
| L'option --no-merge a été forcée puisque ce dépôt ne supporte pas les releases automatiques" | ||||
|     [ -z "$ShouldPush" ] && enote "\ | ||||
| L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" | ||||
| 
 | ||||
|     if [ -z "$Version" -a -n "$CurrentVersion" -a -f VERSION.txt ]; then | ||||
|         Version="$(<VERSION.txt)" | ||||
| @ -129,26 +131,25 @@ EOF | ||||
| fi | ||||
| EOF | ||||
| 
 | ||||
|     [ -n "$Merge" ] && Merged=1 || Merged= | ||||
|     [ -n "$Push" -o "$CantPush" ] && Pushed=1 || Pushed= | ||||
|     [ -z "$ManualRelease" -a -n "$Merge" ] && ShouldMerge= || ShouldMerge=1 | ||||
|     [ -n "$ShouldPush" -a -n "$Push" ] && ShouldPush= | ||||
|     if [ -n "$_NoRunScript" ]; then | ||||
|         einfo "Veuillez consulter le script $script pour le détail des opérations à effectuer" | ||||
|     elif ! "$script" create ${Merge:+merge} ${Push:+push}; then | ||||
|         eimportant "\ | ||||
| Le script $script a été lancé avec les arguments 'create${Merge:+ merge}${Push:+ push}' | ||||
| Veuillez le consulter pour le détail des opérations qui n'ont pas pu êtres effectuées" | ||||
| En cas d'erreur de merge, veuillez corriger les erreurs puis continuer avec | ||||
|     git merge --continue | ||||
| Veuillez aussi consulter le script et/ou le relancer | ||||
|     ./$script${Push:+ push}" | ||||
|         die | ||||
|     elif [ -n "$Merged" -a -n "$Pushed" ]; then | ||||
|     elif [ -n "$Merge" -a -n "$Pushe" ]; then | ||||
|         [ -n "$_KeepScript" ] || rm "$script" | ||||
|     else | ||||
|         local cmd | ||||
|         [ -n "$Merged" ] || cmd="$cmd | ||||
|     ./$script merge" | ||||
|         [ -n "$Pushed" ] || cmd="$cmd | ||||
|     ./$script push" | ||||
|         einfo "\ | ||||
| Le script $script a été lancé avec les arguments 'create${Merge:+ merge}${Push:+ push}' | ||||
| Veuillez le consulter pour le détail des autres opérations à effectuer$cmd" | ||||
| Vous pouvez consulter le script et/ou le relancer | ||||
|     ./$script${ShouldMerge:+ merge}${ShouldPush:+ push}" | ||||
|     fi | ||||
| } | ||||
| 
 | ||||
| @ -238,13 +239,12 @@ load_branches current "$1"; shift | ||||
| [ -n "$ManualRelease" ] && Merge= | ||||
| [ -z "$Merge" ] && Push= | ||||
| 
 | ||||
| CantPush= | ||||
| ShouldPush=1 | ||||
| [ -n "$Origin" ] || Origin=origin | ||||
| if ! git_have_remote "$Origin" && [ -n "$Push" ]; then | ||||
|     ewarn "L'option --no-push a été forcée puisque ce dépôt n'a pas d'origine" | ||||
|     CantPush=1 | ||||
|     ShouldPush= | ||||
| fi | ||||
| [ -n "$CantPush" ] && Push= | ||||
| [ -z "$ShouldPush" ] && Push= | ||||
| 
 | ||||
| # puis faire l'action que l'on nous demande | ||||
| case "$action" in | ||||
|  | ||||
		Reference in New Issue
	
	Block a user