ajout de git_fast_forward

This commit is contained in:
Jephté Clain 2015-03-27 00:15:40 +04:00
parent 1661ee5f48
commit e3e3bbb9ed
1 changed files with 25 additions and 11 deletions

View File

@ -600,28 +600,31 @@ function git_ensure_cleancheckout() {
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_check_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/origin/$1
# vaut par défaut remotes/${3:-origin}/$1
# note: cette fonction retourne vrai si $1 et $2 identifient le même commit
local b="$1" o="${2:-remotes/origin/$1}"
b="$(git rev-parse --verify "$b")" || return 1
o="$(git rev-parse --verify "$o")" || return 1
__git_check_can_ff "$b" "$o"
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/origin/$1
# 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 b="$1" o="${2:-remotes/origin/$1}"
b="$(git rev-parse --verify "$b")" || return 1
o="$(git rev-parse --verify "$o")" || return 1
[ "$b" != "$o" ] || return 1
__git_check_can_ff "$b" "$o"
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
@ -629,6 +632,17 @@ function git_should_push() {
# 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