Skip to content

Instantly share code, notes, and snippets.

@miguelortizdev
Last active August 12, 2019 14:43
Show Gist options
  • Save miguelortizdev/d0ef61355cedffdcf61846a19274734c to your computer and use it in GitHub Desktop.
Save miguelortizdev/d0ef61355cedffdcf61846a19274734c to your computer and use it in GitHub Desktop.

Revisions

  1. miguelortizdev renamed this gist Aug 12, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. miguelortizdev created this gist Aug 12, 2019.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #!/bin/bash

    # Creamos una variable en el bash para almacenar las ramas a la que no deseamos aplicar la regla si dicha variable no existe
    if [ -z "$BRANCHES_TO_SKIP" ]; then
    BRANCHES_TO_SKIP=(master develop test)
    fi

    # Obtenemos el correo configurado en el equipo
    USER_EMAIL=$(git config user.email)

    # Obtenemos el nombre de la rama actual
    BRANCH_NAME=$(git symbolic-ref --short HEAD)

    BRANCH_NAME="${BRANCH_NAME##*/}"

    # Verificamos que la rama actual no es una d elas excluidas
    BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
    BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)

    # Si la rama actual no esta excluida entonces modificamos el mensaje para la confirmación actual
    if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
    sed -i.bak -e "1s/$/ :: [$BRANCH_NAME] - $USER_EMAIL/" $1
    fi