Tengo un script bash que se ejecuta siguiendo el command cherry-pick:
if git cherry-pick -x "$commitId"; then ammed_commit "$BRANCH" else #here I want to check if this resulted in empty commit fi
Intenté ejecutar el command de nuevo y get salida en una cadena y luego comparar la cadena, pero el resultado no es lo que veo en la console. Estoy probando con el siguiente script:
#!/bin/bash READ_STATUS=$(git cherry-pick -x 001e6beda) SUB_STRING="The previous cherry-pick is now empty" echo $READ_STATUS stringContain() { [ -z "${2##*$1*}" ]; } if stringContain "$READ_STATUS" 'The previous cherry-pick is now empty';then echo yes else echo no fi exit
A continuación se muestra el resultado que recibo cuando ejecuto este script:
The previous cherry-pick is now empty, possibly due to conflict resolution. If you wish to commit it anyway, use: git commit --allow-empty Otherwise, please use 'git reset' //READ_STATUS gets this value and not the one above this line??? On branch test-stage Your branch is ahead of 'upstream/test-stage' by 1 commit. (use "git push" to publish your local commits) You are currently cherry-picking commit 001e6beda. nothing to commit, working tree clean no
Entonces tengo dos preguntas:
El git
envía sus posts de error a stderr, no a stdout. READ_STATUS=$(git cherry-pick -x 001e6beda)
captura el stdout y establece READ_STATUS en nada cuando git falla.
Puedes reescribir tu código de esta manera:
read_status=$(git cherry-pick -x 001e6beda 2>&1) empty_message="The previous cherry-pick is now empty" if [[ $read_status = *"$empty_message"* ]]; then echo yes else echo no fi
Ver también: