diff --git a/lib/profile.d/nutools.userconf b/lib/profile.d/nutools.userconf index 3c40faa..676a470 100644 --- a/lib/profile.d/nutools.userconf +++ b/lib/profile.d/nutools.userconf @@ -40,8 +40,5 @@ # Activer le mode offline pour git (pas de push automatique) #export UTOOLS_VCS_OFFLINE=1 -# Activer automatiquement l'option --clean pour 'uproject update' -#export UTOOLS_VCS_CLEANUPDATE=1 - # Faire un alias ssh pour ussh #export UTOOLS_USSH_ALIAS=1 diff --git a/lib/ulib/vcs b/lib/ulib/vcs index 43e59c5..a8aaf36 100644 --- a/lib/ulib/vcs +++ b/lib/ulib/vcs @@ -441,7 +441,7 @@ function git_commit() { function git_status() { git status "$@" } -function __git_update_lbranches() { +function __gu_list_lbranches() { git for-each-ref refs/heads/ --format='%(refname:short)' | grep -vF master | grep -vF develop | @@ -449,20 +449,16 @@ function __git_update_lbranches() { grep -v '^hotfix-' } function git_update() { - local args autoff=1 clean=auto + local args clean= autoff=1 parse_opts + "${PRETTYOPTS[@]}" \ -x '$_vcs_unsupported -x' \ -c,--clean-before clean=1 \ - --no-clean-before clean= \ -n,--no-autoff autoff= \ @ args -- "$@" && set -- "${args[@]}" || { eerror "$args" return 1 } - if [ "$clean" == auto ]; then - [ -n "$UTOOLS_VCS_CLEANUPDATE" ] && clean=1 || clean= - fi if [ -z "$autoff" ]; then git pull "$@" return $? @@ -471,15 +467,41 @@ function git_update() { local branch orig_branch restore_branch remote rbranch pbranch local -a branches prbranches crbranches dbranches + orig_branch="$(git_get_branch)" + if [ -n "$clean" ]; then + local l r; local -a error git_ensure_cleancheckout - array_from_lines prbranches "$(git_list_rbranches)" if git_have_branch develop; then - git checkout -q develop - array_from_lines branches "$(__git_update_lbranches)" + if [ "$orig_branch" != develop ]; then + estep "basculement sur la branche develop" + git checkout -q develop + restore_branch=1 + fi + array_from_lines prbranches "$(git_list_rbranches)" + array_from_lines branches "$(__gu_list_lbranches)" for branch in "${branches[@]}"; do - #XXX pour chaque branche, vérifier l'origine + if array_contains prbranches "origin/$branch"; then + l="$(git rev-parse --verify --quiet "$branch")" + r="$(git rev-parse --verify --quiet "origin/$branch")" + if [ "$l" == "$r" ]; then + estepn "$branch: branche locale supprimée" + git branch -q -D "$branch" + else + array_add error "$branch" + fi + else + estep "$branch: branche locale gardée" + fi done + if [ "${#error[*]}" -gt 0 ]; then + eerror "Les branches locales suivantes diffèrent de l'origine: ${COULEUR_JAUNE}${error[*]}${COULEUR_NORMALE}" + enote "Si vous êtes *certains* qu'il n'y a aucune modification locale à garder: +- supprimez ces branches manuellement +- ou faites-en une copie locale +puis relancez cette commande." + return 1 + fi fi fi @@ -549,7 +571,6 @@ Make your choice then delete the local branches: return 0 fi - orig_branch="$(git_get_branch)" array_from_lines branches "$(git_list_branches)" for branch in "${branches[@]}"; do remote="$(git_get_branch_remote "$branch")" @@ -573,7 +594,10 @@ You can merge manually with: git checkout $branch; git merge $pbranch" fi fi done - [ -n "$restore_branch" ] && git checkout -q "$orig_branch" + if [ -n "$restore_branch" ]; then + [ -n "$clean" ] && estep "rebasculement sur la branche $orig_branch" + git checkout -q "$orig_branch" + fi return 0 } function git_push() { diff --git a/uproject b/uproject index 9d5c7a8..cb92e09 100755 --- a/uproject +++ b/uproject @@ -43,15 +43,12 @@ COMMANDS Afficher l'état des fichiers versionnés et non versionnés. update [-x] Mettre à jour la copie locale avec la copie sur le serveur. - -x Ne pas mettre à jour les références externes (si appliquable) + -x Ne pas mettre à jour les références externes (uniquement pour svn) -c, --clean-before Avant de faire git pull, supprimer toutes les branches locales qui sont à jour par rapport à l'origine. La copie de travail doit être propre. Basculer sur la branche develop avant de supprimer les branches. S'il n'y a pas de branche develop, c'est un NOP. - --no-clean-before - Neutraliser l'activation de l'option --clean-before par la variable - UTOOLS_VCS_CLEANUPDATE si elle est renseignée. -n, --no-autoff Ne pas faire de fast-forward automatique pour toutes les branches traquées. Par défaut, s'il n'y a pas de modifications locales,