diff --git a/lib/default/pcrone b/lib/default/pcrone new file mode 100644 index 0000000..d7e56a7 --- /dev/null +++ b/lib/default/pcrone @@ -0,0 +1,15 @@ +# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8 + +# Définitions des types de dépôt. Le format est NAME:TYPE:PREFIX +# * NAME est utilisé pour définir des configurations supplémentaires +# * TYPE peut valoir gitolite ou gogs. Le type par défaut est 'gitolite' +REPO_TYPES=( + ur:gogs:https://gogs.univ-reunion.fr/ +) + +# Configuration de l'accès à l'API gogs +# un nom de dépôt est de la forme user/repo. Si user != $GOGS_USER alors on crée +# dans une organisation +#ur_GOGS_URL=https://gogs.univ-reunion.fr +#ur_GOGS_USER="$USER" +#ur_GOGS_KEY= diff --git a/uproject b/uproject index 9dd047e..5b21760 100755 --- a/uproject +++ b/uproject @@ -417,24 +417,53 @@ NR <= 2 { next } fi elif [ "$CMD" == crone ]; then + REPO_TYPES=() + set_defaults pcrone + repourl="${1%.git}" [ -n "$repourl" ] || die "Vous devez spécifier l'url du dépôt git" - if [ "${repourl#http://}" != "$repourl" -o "${repourl#https://}" != "$repourl" ]; then - # accès par http - mode=http - splitfsep "$repourl" :// scheme hostuserpath - splitfsep "$hostuserpath" / host userpath + + found= + for repo_ntp in "${REPO_TYPES[@]}"; do + splitfsep "$repo_ntp" : name tmp + splitfsep "$tmp" : type prefix + if [ "${repourl#$prefix}" != "$repourl" ]; then + found=1 + break + fi + done + if [ -z "$found" ]; then + name= + type=gitolite + prefix= + fi + if [ "$type" == "gitolite" ]; then + if [ "${repourl#http://}" != "$repourl" -o "${repourl#https://}" != "$repourl" ]; then + # accès par http + mode=gitolite_http + splitfsep "$repourl" :// scheme hostuserpath + splitfsep "$hostuserpath" / host userpath + splitfsep "$userpath" / user path + [ -n "$host" -a -n "$user" ] || die "Vous devez spécifier l'hôte e.g http://host/git/repo" + hostuser="$scheme://$host/$user" + else + # accès par ssh + mode=gitolite_ssh + splitfsep "$repourl" : userhost path + splituserhost "$userhost" user host + [ -n "$user" ] || user=git + [ -n "$host" ] || die "Vous devez spécifier l'hôte" + userhost="$user@$host" + fi + elif [ "$type" == "gogs" ]; then + mode=gogs_http + gogs_url="${name}_GOGS_URL"; gogs_url="${!gogs_url}" + gogs_user="${name}_GOGS_USER"; gogs_user="${!gogs_user}" + gogs_key="${name}_GOGS_KEY"; gogs_key="${!gogs_key}" + userpath="${repourl#$prefix}" splitfsep "$userpath" / user path - [ -n "$host" -a -n "$user" ] || die "Vous devez spécifier l'hôte e.g http://host/git/repo" - hostuser="$scheme://$host/$user" else - # accès par ssh - mode=ssh - splitfsep "$repourl" : userhost path - splituserhost "$userhost" user host - [ -n "$user" ] || user=git - [ -n "$host" ] || die "Vous devez spécifier l'hôte" - userhost="$user@$host" + die "$type: type de dépôt non supporté" fi [ -n "$path" ] || die "Vous devez spécifier le chemin du dépôt git" @@ -449,7 +478,7 @@ elif [ "$CMD" == crone ]; then ac_set_tmpdir tmpdestdir fi - if [ "$mode" == http ]; then + if [ "$mode" == gitolite_http ]; then setx result=curl -fs "$hostuser/create?$path" || die echo "$result" [[ "$result" == FATAL:* ]] && die @@ -461,7 +490,7 @@ elif [ "$CMD" == crone ]; then else git clone "$hostuser/$path" "$destdir" || die fi - elif [ "$mode" == ssh ]; then + elif [ "$mode" == gitolite_ssh ]; then git_annex_use_ssh_wrapper ssh "$userhost" create "$path" || die if [ -n "$tmpdestdir" ]; then @@ -472,19 +501,50 @@ elif [ "$CMD" == crone ]; then else git clone "$userhost:$path" "$destdir" || die fi + elif [ "$mode" == gogs_http ]; then + payload='{"private":true,"name":"'"$path"'"}' + if [ "$gogs_user" != "$user" ]; then + url="$gogs_url/api/v1/org/$user/repos" + else + url="$gogs_url/api/v1/user/repos" + fi + setx result=curl -fs \ + -H 'Content-Type: application/json' \ + -H "Authorization: token $gogs_key" \ + -d "$payload" \ + "$url" || die "Une erreur s'est produite lors de la tentative de création du dépôt" + echo "$result" + if [ -n "$tmpdestdir" ]; then + setxx destname=abspath "$destdir" // basename + git clone "$repourl" "$tmpdestdir/$destname" || die + mv "$tmpdestdir/$destname/.git" "$destdir" || die + ac_clean "$tmpdestdir" + else + git clone "$repourl" "$destdir" || die + fi else die "bug: mode non prévu" fi - if ask_yesno "Voulez-vous créer des fichiers .gitignore et .gitattributes initiaux?" O; then - echo >"$destdir/.gitignore" "\ + if [ ! -f "$destdir/.gitignore" -o ! -f "$destdir/.gitattributes" ]; then + if ask_yesno "Voulez-vous créer les fichiers initiaux .gitignore et/ou .gitattributes?" O; then + if [ -f "$destdir/.gitignore" ]; then + einfo "Refus d'écraser le fichier .gitignore existant" + else + echo >"$destdir/.gitignore" "\ .~lock*# .*.swp" - echo >"$destdir/.gitattributes" "\ + fi + if [ -f "$destdir/.gitattributes" ]; then + einfo "Refus d'écraser le fichier .gitattributes existant" + else + echo >"$destdir/.gitattributes" "\ *.zip -delta *.gz -delta *.bz2 -delta *.whl -delta *.exe -delta" + fi + fi fi elif [ "$CMD" == xconfig-export ]; then