From fec6b2fb8b0977b34d6defb1357710f5cae5499d Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 21 Apr 2017 11:04:21 +0400 Subject: [PATCH] =?UTF-8?q?pu:=20support=20du=20scenario=20ou=20la=20branc?= =?UTF-8?q?he=20de=20feature=20distante=20a=20=C3=A9t=C3=A9=20supprim?= =?UTF-8?q?=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/vcs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/ulib/vcs b/lib/ulib/vcs index 155f28b..b7dcca9 100644 --- a/lib/ulib/vcs +++ b/lib/ulib/vcs @@ -456,11 +456,64 @@ function git_update() { return $? fi - local orig_branch restore_branch remote rbranch pbranch - local -a branches + local branch orig_branch restore_branch remote rbranch pbranch + local -a branches prbranches crbranches dbranches + array_from_lines prbranches "$(git_list_rbranches)" git fetch -p "$@" || return + array_from_lines crbranches "$(git_list_rbranches)" + # vérifier s'il n'y a pas des branches distantes qui ont été supprimées + for branch in "${prbranches[@]}"; do + if ! array_contains crbranches "$branch"; then + array_add dbranches "${branch#*/}" + fi + done + if [ ${#dbranches[*]} -gt 0 ]; then + eimportant "One or more distant branches where deleted" + for branch in "${dbranches[@]}"; do + if git_have_branch "$branch"; then + if ! ask_yesno "Do you want to delete local branch $branch?" X; then + array_del dbranches "$branch" + fi + fi + done + fi + if [ ${#dbranches[*]} -gt 0 ]; then + array_from_lines branches "$(git_list_branches)" + branch="$(git_get_branch)" + if array_contains dbranches "$branch"; then + # si la branche courante est l'une des branches à supprimer, il faut + # basculer vers develop ou master + local swto + if [ -z "$swto" ] && array_contains branches develop && ! array_contains dbranches develop; then + swto=develop + fi + if [ -z "$swto" ] && array_contains branches master && ! array_contains dbranches master; then + swto=master + fi + if ! git_check_cleancheckout; then + echo "* There are uncommitted local changes. However current branch is slated for removal. +Make your verifications then delete the local branches: + ${swto:+$(qvals git checkout "$swto") + }$(qvals git branch -D "${dbranches[@]}")" + return 1 + fi + if [ -n "$swto" ]; then + git checkout -q "$swto" + else + echo "* Current branch is slated for removal but I don't know to which branch I should switch first. +Make your choice then delete the local branches: + $(qvals git branch -D "${dbranches[@]}")" + return 1 + fi + fi + for branch in "${dbranches[@]}"; do + git branch -D "$branch" + done + fi + + # intégrer les modifications dans les branches locales if ! git_check_cleancheckout; then branch="$(git_get_branch)" remote="$(git_get_branch_remote "$branch")"