Intégration de la feature branch git-opts
This commit is contained in:
commit
b757ca13ca
58
lib/ulib/vcs
58
lib/ulib/vcs
@ -523,6 +523,8 @@ __VCS_GIT_ADVANCED_MAP=(
|
|||||||
gb:git_get_branch ib:git_is_branch
|
gb:git_get_branch ib:git_is_branch
|
||||||
hr:git_have_remote tb:git_track_branch
|
hr:git_have_remote tb:git_track_branch
|
||||||
cc:git_check_cleancheckout ec:git_ensure_cleancheckout
|
cc:git_check_cleancheckout ec:git_ensure_cleancheckout
|
||||||
|
ia:git_is_ancestor sff:git_should_ff spu:git_should_push
|
||||||
|
im:git_is_merged
|
||||||
)
|
)
|
||||||
__VCS_GIT_ADVANCED=(
|
__VCS_GIT_ADVANCED=(
|
||||||
git_check_gitvcs git_ensure_gitvcs
|
git_check_gitvcs git_ensure_gitvcs
|
||||||
@ -531,6 +533,8 @@ __VCS_GIT_ADVANCED=(
|
|||||||
git_get_branch git_is_branch
|
git_get_branch git_is_branch
|
||||||
git_have_remote git_track_branch
|
git_have_remote git_track_branch
|
||||||
git_check_cleancheckout git_ensure_cleancheckout
|
git_check_cleancheckout git_ensure_cleancheckout
|
||||||
|
git_is_ancestor git_should_ff git_should_push
|
||||||
|
git_is_merged
|
||||||
)
|
)
|
||||||
function git_check_gitvcs() {
|
function git_check_gitvcs() {
|
||||||
[ "$(_vcs_get_type "$(_vcs_get_dir)")" == git ]
|
[ "$(_vcs_get_type "$(_vcs_get_dir)")" == git ]
|
||||||
@ -596,6 +600,60 @@ function git_ensure_cleancheckout() {
|
|||||||
git_check_cleancheckout || die "Vous avez des modifications locales. Enregistrez ces modifications avant de continuer"
|
git_check_cleancheckout || die "Vous avez des modifications locales. Enregistrez ces modifications avant de continuer"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __git_init_ff() {
|
||||||
|
o="${3:-origin}"
|
||||||
|
b="$1" s="${2:-remotes/$o/$1}"
|
||||||
|
b="$(git rev-parse --verify "$b")" || return 1
|
||||||
|
s="$(git rev-parse --verify "$s")" || return 1
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
function __git_can_ff() {
|
||||||
|
[ "$1" == "$(git merge-base "$1" "$2")" ]
|
||||||
|
}
|
||||||
|
function git_is_ancestor() {
|
||||||
|
# vérifier que la branche $1 est un ancêtre direct de la branche $2, qui
|
||||||
|
# vaut par défaut remotes/${3:-origin}/$1
|
||||||
|
# note: cette fonction retourne vrai si $1 et $2 identifient le même commit
|
||||||
|
local o b s; __git_init_ff "$@" || return
|
||||||
|
__git_can_ff "$b" "$s"
|
||||||
|
}
|
||||||
|
function git_should_ff() {
|
||||||
|
# vérifier si la branche $1 devrait être fast-forwardée à partir de la
|
||||||
|
# branche d'origine $2, qui vaut par défaut remotes/${3:-origin}/$1
|
||||||
|
# note: cette fonction est similaire à git_is_ancestor(), mais retourne
|
||||||
|
# false si $1 et $2 identifient le même commit
|
||||||
|
local o b s; __git_init_ff "$@" || return
|
||||||
|
[ "$b" != "$s" ] || return 1
|
||||||
|
__git_can_ff "$b" "$o"
|
||||||
|
}
|
||||||
|
function git_should_push() {
|
||||||
|
# vérifier si la branche $1 devrait être poussée vers la branche de même nom
|
||||||
|
# dans l'origine $2(=origin), parce que l'origin peut-être fast-forwardée à
|
||||||
|
# partir de cette branche.
|
||||||
|
git_should_ff "remotes/${2:-origin}/$1" "$1"
|
||||||
|
}
|
||||||
|
function git_fast_forward() {
|
||||||
|
# vérifier que la branche courante est bien $1, puis tester s'il faut la
|
||||||
|
# fast-forwarder à partir de l'origine $2, puis le faire si c'est
|
||||||
|
# nécessaire. la branche d'origine $2 vaut par défaut remotes/origin/$1
|
||||||
|
local o b s; __git_init_ff "$@" || return
|
||||||
|
[ "$b" != "$s" ] || return 1
|
||||||
|
local head="$(git rev-parse HEAD)"
|
||||||
|
[ "$head" == "$b" ] || return 1
|
||||||
|
__git_can_ff "$b" "$s" || return 1
|
||||||
|
git merge --ff-only "$s"
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_is_merged() {
|
||||||
|
# vérifier que les branches $1 et $2 ont un ancêtre commun, et que la
|
||||||
|
# branche $1 a été complètement fusionnée dans la branche destination $2
|
||||||
|
local b="$1" d="$2"
|
||||||
|
b="$(git rev-parse --verify "$b")" || return 1
|
||||||
|
d="$(git rev-parse --verify "$d")" || return 1
|
||||||
|
[ -n "$(git merge-base "$b" "$d")" ] || return 1
|
||||||
|
[ -z "$(git rev-list "$d..$b")" ]
|
||||||
|
}
|
||||||
|
|
||||||
# fonctions pour git annex
|
# fonctions pour git annex
|
||||||
function git_annex_initial() {
|
function git_annex_initial() {
|
||||||
# sur le dépôt $1 fraichement cloné, vérifier s'il faut faire git annex
|
# sur le dépôt $1 fraichement cloné, vérifier s'il faut faire git annex
|
||||||
|
10
pdev
10
pdev
@ -123,13 +123,15 @@ if [ "$action" == branch ]; then
|
|||||||
if [ -z "$UTOOLS_VCS_OFFLINE" ]; then
|
if [ -z "$UTOOLS_VCS_OFFLINE" ]; then
|
||||||
git_track_branch "$feature" "$origin"
|
git_track_branch "$feature" "$origin"
|
||||||
fi
|
fi
|
||||||
|
git_fast_forward "$feature" "" "$origin"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Créer/basculer vers une feature branch
|
# Créer/basculer vers une feature branch
|
||||||
git_ensure_cleancheckout
|
git_ensure_cleancheckout
|
||||||
|
r=0
|
||||||
if git_have_branch "$feature"; then
|
if git_have_branch "$feature"; then
|
||||||
git checkout "$feature"
|
git checkout "$feature" || r=$?
|
||||||
else
|
else
|
||||||
estepn "\
|
estepn "\
|
||||||
Vous allez créer la nouvelle feature branch ${COULEUR_VERTE}$feature${COULEUR_NORMALE}
|
Vous allez créer la nouvelle feature branch ${COULEUR_VERTE}$feature${COULEUR_NORMALE}
|
||||||
@ -138,7 +140,11 @@ Vous allez créer la nouvelle feature branch ${COULEUR_VERTE}$feature${COULEUR_N
|
|||||||
|
|
||||||
git_ensure_branch "$feature" "$source" "$origin"
|
git_ensure_branch "$feature" "$source" "$origin"
|
||||||
[ $? -eq 2 ] && die "Impossible de créer la branche $feature. Veuillez vérifier que la branche $source existe"
|
[ $? -eq 2 ] && die "Impossible de créer la branche $feature. Veuillez vérifier que la branche $source existe"
|
||||||
git checkout "$feature"
|
git checkout "$feature" || r=$?
|
||||||
|
fi
|
||||||
|
if [ "$r" -eq 0 ]; then
|
||||||
|
# éventuellement fast-forwarder automatiquement
|
||||||
|
git_fast_forward "$feature" "" "$origin"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit $?
|
exit $?
|
||||||
|
Loading…
Reference in New Issue
Block a user