modifs.mineures sans commentaires
This commit is contained in:
parent
e4e6a98be2
commit
39abe09f11
191
wip/pinit
Executable file
191
wip/pinit
Executable file
@ -0,0 +1,191 @@
|
|||||||
|
#!/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
|
||||||
|
CurrentType=SrcType
|
||||||
|
)
|
||||||
|
|
||||||
|
function show_action() {
|
||||||
|
local var src
|
||||||
|
echo_setv ConfigBranch="$ConfigBranch"
|
||||||
|
echo_setv ConfigFile="$(ppath "$ConfigFile")"
|
||||||
|
for var in "${SHOW_VARS[@]}"; do
|
||||||
|
if [ "${var#--}" != "$var" ]; then
|
||||||
|
estep "${var#--}"
|
||||||
|
else
|
||||||
|
splitfsep "$var" = var src
|
||||||
|
[ -n "$src" ] || src="$var"
|
||||||
|
echo_setv "$var=${!src}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Initialisation
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
function _init_config() {
|
||||||
|
if [ ! -f .pman.conf -o -n "$ForceCreate" ]; then
|
||||||
|
ac_set_tmpfile config
|
||||||
|
cp "$ConfigFile" "$config"
|
||||||
|
"${EDITOR:-nano}" "$config"
|
||||||
|
[ -s "$config" ] || return 1
|
||||||
|
|
||||||
|
cp "$config" .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
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_repo_action() {
|
||||||
|
local -a push_branches; local config
|
||||||
|
|
||||||
|
[ ${#LocalBranches[*]} -eq 0 ] || die "Ce dépôt a déjà été initialisé"
|
||||||
|
|
||||||
|
_init_config || exit_with ewarn "Initialisation du dépôt annulée"
|
||||||
|
|
||||||
|
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_config_action() {
|
||||||
|
local -a push_branches; local config
|
||||||
|
|
||||||
|
[ -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"
|
||||||
|
push_branches+=("$CurrentBranch")
|
||||||
|
|
||||||
|
_push_branches
|
||||||
|
}
|
||||||
|
|
||||||
|
function _init_composer() {
|
||||||
|
if [ ! -f .composer.pman.yml -o -n "$ForceCreate" ]; then
|
||||||
|
ac_set_tmpfile config
|
||||||
|
cat >"$config" <<EOF
|
||||||
|
# -*- coding: utf-8 mode: yaml -*- vim:sw=2:sts=2:et:ai:si:sta:fenc=utf-8
|
||||||
|
|
||||||
|
composer:
|
||||||
|
match_prefix:
|
||||||
|
match_prefix-dev:
|
||||||
|
profiles: [ dev, dist ]
|
||||||
|
dev:
|
||||||
|
link: true
|
||||||
|
require:
|
||||||
|
reqire-dev:
|
||||||
|
dist:
|
||||||
|
link: false
|
||||||
|
require:
|
||||||
|
reqire-dev:
|
||||||
|
EOF
|
||||||
|
"${EDITOR:-nano}" "$config"
|
||||||
|
[ -s "$config" ] || return 1
|
||||||
|
|
||||||
|
cp "$config" .composer.pman.yml
|
||||||
|
git add .composer.pman.yml
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_composer_action() {
|
||||||
|
local -a push_branches; local config
|
||||||
|
|
||||||
|
[ -f .composer.pman.yml -a -z "$ForceCreate" ] && die "La configuration pman composer a déjà été initialisée"
|
||||||
|
|
||||||
|
resolve_should_push
|
||||||
|
|
||||||
|
_init_composer || exit_with ewarn "Initialisation de la configuration annulée"
|
||||||
|
git commit -m "configuration pman composer"
|
||||||
|
push_branches+=("$CurrentBranch")
|
||||||
|
|
||||||
|
_push_branches
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_action() {
|
||||||
|
local what="${1:-repo}"; shift
|
||||||
|
case "$what" in
|
||||||
|
repo|r) init_repo_action "$@";;
|
||||||
|
config|c) init_config_action "$@";;
|
||||||
|
composer|o) init_composer_action "$@";;
|
||||||
|
*) die "$what: destination non implémentée"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Programme principal
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
chdir=
|
||||||
|
ConfigFile=
|
||||||
|
action=init
|
||||||
|
Origin=
|
||||||
|
Push=1
|
||||||
|
ForceCreate=
|
||||||
|
args=(
|
||||||
|
"initialiser un dépôt git"
|
||||||
|
"repo|config|composer|all"
|
||||||
|
-d:,--chdir:BASEDIR chdir= "répertoire dans lequel se placer avant de lancer les opérations"
|
||||||
|
-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"
|
||||||
|
-w,--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"
|
||||||
|
--push Push=1 "++\
|
||||||
|
pousser les branches vers leur origine après leur création.
|
||||||
|
c'est l'option par défaut"
|
||||||
|
-f,--force-create ForceCreate=1 "\
|
||||||
|
Avec config, forcer la (re)création du fichier .pman.conf"
|
||||||
|
)
|
||||||
|
parse_args "$@"; set -- "${args[@]}"
|
||||||
|
|
||||||
|
# charger la configuration
|
||||||
|
ensure_gitdir "$chdir"
|
||||||
|
load_branches all
|
||||||
|
load_config
|
||||||
|
load_branches current
|
||||||
|
|
||||||
|
# puis faire l'action que l'on nous demande
|
||||||
|
case "$action" in
|
||||||
|
show) show_action "$@";;
|
||||||
|
init)
|
||||||
|
git_ensure_cleancheckout
|
||||||
|
init_action "$@"
|
||||||
|
;;
|
||||||
|
*) die "$action: action non implémentée";;
|
||||||
|
esac
|
Loading…
x
Reference in New Issue
Block a user