création de la branche develop
This commit is contained in:
parent
359563b423
commit
34e020e198
43
lib/ulib/vcs
43
lib/ulib/vcs
|
@ -517,39 +517,72 @@ function git_tag() {
|
||||||
|
|
||||||
# Fonctions avancées de git
|
# Fonctions avancées de git
|
||||||
__VCS_GIT_ADVANCED_MAP=(
|
__VCS_GIT_ADVANCED_MAP=(
|
||||||
|
cg:git_check_gitvcs eg:git_ensure_gitvcs
|
||||||
lbs:git_list_branches rbs:git_list_rbranches
|
lbs:git_list_branches rbs:git_list_rbranches
|
||||||
|
hlb:git_have_branch hrb:git_have_rbranch
|
||||||
gb:git_get_branch ib:git_is_branch
|
gb:git_get_branch ib:git_is_branch
|
||||||
hr:git_has_remote tb:git_track_branch
|
hr:git_have_remote tb:git_track_branch
|
||||||
ic:git_check_cleancheckout ec:git_ensure_cleancheckout
|
cc:git_check_cleancheckout ec:git_ensure_cleancheckout
|
||||||
)
|
)
|
||||||
__VCS_GIT_ADVANCED=(
|
__VCS_GIT_ADVANCED=(
|
||||||
|
git_check_gitvcs git_ensure_gitvcs
|
||||||
git_list_branches git_list_rbranches
|
git_list_branches git_list_rbranches
|
||||||
|
git_have_branch git_have_rbranch
|
||||||
git_get_branch git_is_branch
|
git_get_branch git_is_branch
|
||||||
git_has_remote git_track_branch
|
git_have_remote git_track_branch
|
||||||
git_check_cleancheckout git_ensure_cleancheckout
|
git_check_cleancheckout git_ensure_cleancheckout
|
||||||
)
|
)
|
||||||
|
function git_check_gitvcs() {
|
||||||
|
[ "$(_vcs_get_type "$(_vcs_get_dir)")" == git ]
|
||||||
|
}
|
||||||
|
function git_ensure_gitvcs() {
|
||||||
|
git_check_gitvcs || die "Ce n'est pas un dépôt git"
|
||||||
|
}
|
||||||
function git_list_branches() {
|
function git_list_branches() {
|
||||||
git for-each-ref refs/heads/ --format='%(refname:short)' | csort
|
git for-each-ref refs/heads/ --format='%(refname:short)' | csort
|
||||||
}
|
}
|
||||||
function git_list_rbranches() {
|
function git_list_rbranches() {
|
||||||
git for-each-ref "refs/remotes/${1:-origin}/" --format='%(refname:short)' | csort
|
git for-each-ref "refs/remotes/${1:-origin}/" --format='%(refname:short)' | csort
|
||||||
}
|
}
|
||||||
|
function git_have_branch() {
|
||||||
|
git_list_branches | grep -qF "$1"
|
||||||
|
}
|
||||||
|
function git_have_rbranch() {
|
||||||
|
git_list_rbranches "${2:-origin}" | grep -qF "$1"
|
||||||
|
}
|
||||||
function git_get_branch() {
|
function git_get_branch() {
|
||||||
git rev-parse --abbrev-ref HEAD 2>/dev/null
|
git rev-parse --abbrev-ref HEAD 2>/dev/null
|
||||||
}
|
}
|
||||||
function git_is_branch() {
|
function git_is_branch() {
|
||||||
[ "$(git_get_branch)" == "${1:-master}" ]
|
[ "$(git_get_branch)" == "${1:-master}" ]
|
||||||
}
|
}
|
||||||
function git_has_remote() {
|
function git_have_remote() {
|
||||||
[ -n "$(git config --get remote.${1:-origin}.url)" ]
|
[ -n "$(git config --get remote.${1:-origin}.url)" ]
|
||||||
}
|
}
|
||||||
function git_track_branch() {
|
function git_track_branch() {
|
||||||
local branch="$1" origin="${2:-origin}"
|
local branch="$1" origin="${2:-origin}"
|
||||||
[ -n "$branch" ] || return
|
[ -n "$branch" ] || return
|
||||||
git_has_remote "$origin" || return
|
git_have_remote "$origin" || return
|
||||||
[ "$(git config --get branch.$branch.remote)" == "$origin" ] && return
|
[ "$(git config --get branch.$branch.remote)" == "$origin" ] && return
|
||||||
git branch -t --set-upstream "$branch" "$origin/$branch"
|
git branch -t --set-upstream "$branch" "$origin/$branch"
|
||||||
}
|
}
|
||||||
|
function git_ensure_branch() {
|
||||||
|
# retourner 0 si la branche a été créée, 1 si elle existait déjà, 2 en cas d'erreur
|
||||||
|
local branch="$1" source="${2:-master}" origin="${3:-origin}"
|
||||||
|
[ -n "$branch" ] || return 2
|
||||||
|
git_have_branch "$branch" && return 1
|
||||||
|
if git_have_rbranch "$branch"; then
|
||||||
|
# une branche du même nom existe dans l'origine. faire une copie de cette branche
|
||||||
|
git branch -t "$branch" "$origin/$branch" || return 2
|
||||||
|
else
|
||||||
|
# créer une nouvelle branche du nom spécifié
|
||||||
|
git branch "$branch" "$source" || return 2
|
||||||
|
if git_have_remote "$origin"; then
|
||||||
|
git push "$origin" "$branch" && git_track_branch "$branch" "$origin"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
function git_check_cleancheckout() {
|
function git_check_cleancheckout() {
|
||||||
# vérifier qu'il n'y a pas de modification locales dans le dépôt
|
# vérifier qu'il n'y a pas de modification locales dans le dépôt
|
||||||
# correspondant au répertoire courant.
|
# correspondant au répertoire courant.
|
||||||
|
|
10
pdev
10
pdev
|
@ -38,11 +38,17 @@ parse_opts "${PRETTYOPTS[@]}" \
|
||||||
--help '$exit_with display_help' \
|
--help '$exit_with display_help' \
|
||||||
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
@ args -- "$@" && set -- "${args[@]}" || die "$args"
|
||||||
|
|
||||||
|
git_ensure_gitvcs
|
||||||
|
if ! git_have_branch develop; then
|
||||||
|
estepn "Création de la branche develop"
|
||||||
|
git_ensure_branch develop
|
||||||
|
[ $? -eq 2 ] && die "Une erreur s'est produite pendant la création de la branche develop"
|
||||||
|
fi
|
||||||
|
git_track_branch develop
|
||||||
|
|
||||||
topic="$1"
|
topic="$1"
|
||||||
source="$2"
|
source="$2"
|
||||||
|
|
||||||
setx -a branches=git_list_branches
|
|
||||||
|
|
||||||
if [ -n "$topic" ]; then
|
if [ -n "$topic" ]; then
|
||||||
# Créer/basculer vers une branche de topic
|
# Créer/basculer vers une branche de topic
|
||||||
:
|
:
|
||||||
|
|
Loading…
Reference in New Issue