Tengo un parámetro transmitido desde una compilation ascendente, digamos $GIT_BRANCH
.
Su valor puede representar una label de git o una twig de git. También tengo un $GIT_REMOTE
pasado que me permite calcular el origen de mi búsqueda y la ruta de pago.
Siempre asum que ejecuto esto antes de cualquiera de los siguientes comentarios.
git fetch $GIT_REMOTE --tags
Si $ GIT_BRANCH era en realidad una sucursal, entonces es muy simple, tiene git checkout remotes/$GIT_REMOTE/$GIT_BRANCH
. Dado que el control remoto ya existe.
Si $ GIT_BRANCH representaba una label, se encontraría con el siguiente error:
error: pathspec 'remotes/origin/1.1.0' did not match any file(s) known to git.
Investigar refspec le dirá que no existe tal cosa como una "label remota" solo references / tags.
Esto significa que si de alguna manera pudiera decir si $GIT_BRANCH
era una label o una twig, podría orientar el cmd para que simplemente se convierta.
git checkout tags/$GIT_BRANCH
¿Alguien capaz de build sobre esto? Sugerir una alternativa? ¿O incluso sugerir una forma de hacer esto de manera confiable en base a mi sugerencia? Tengo algunas preocupaciones sobre branch_names que chocan con los nombres de las tags que pueden presentar algunos casos extremos.
Para la sucursal puede usar los git checkout remotes/$GIT_REMOTE/$GIT_BRANCH
o git checkout $GIT_REMOTE/$GIT_BRANCH
.
Pero para las tags, debe usar git checkout $GIT_BRANCH
directamente. Como ya has usado git fetch $GIT_REMOTE --tags
para search tags localmente en .git/refs/tags
, para que puedas downloadlas directamente.
Puede usar el script de shell para detectar si el parámetro $GIT_BRANCH
es una twig o no:
#!/bin/sh if [ `git branch | grep $GIT_BRANCH` ] then echo "it's branch" else echo "it's tag" fi
#!/bin/bash git fetch origin --tags if git show-ref -q --verify "refs/tags/$GIT_BRANCH" 2>/dev/null; then git checkout refs/tags/$GIT_BRANCH else git checkout remotes/$GIT_REMOTE/$GIT_BRANCH fi