3

I have a nice bash/zenity script that I use to check/update a number of git repos and report the status of each like this - showing only one sample repo here:

zenity --class=CheckGit --info title="Check git updates" --text="\n \
<b>MY-GIT-REPO:</b> $(cd "/home/ME/.local/share/git/MY-GIT-REPO" && git pull | grep -E '(up-to-date|changed)')"

It was working well until I encountered an error due to a change in one of the local files, which resulted in a blank line for that repo.

Terminal output was like this:

error: Your local changes to the following files would be overwritten by merge:
    xxx/yyy
Please, commit your changes or stash them before you can merge.
Aborting

So I modified the grep command like this: grep -E '(up-to-date|changed|error)' to also display such messages. But to my surprise it still refused to show anything.

As a novice in bash scripting I don't understand what is causing this. How come grep displays lines containing the words "up-to-date" or "changed" but not "error"?.. Does this word have a special meaning then? In that case how can I make it display an error message?

3

Git writes its errors to stderr, so you don't miss out on them if you redirect the normal output (to a file, or in your case pipe it into a program).

You can try:

zenity --class=CheckGit --info title="Check git updates" --text="\n \
<b>MY-GIT-REPO:</b> $(cd "/home/ME/.local/share/git/MY-GIT-REPO" && git pull 2>&1 | grep -E '(up-to-date|changed|error)')"
  • Thanks! But there's something strange: I can't reproduce that error message again using the base git pull command after a local change. So I couldn't test if your suggestion will display the error message in my zenity window. Can you please confirm that leaving grep to look for "up-to-date" or "changed" only as you suggest will result in displaying any error messages if the status cannot reported as "up-to-date" or "changed"? – Sadi Jun 11 '15 at 11:59
  • @Sadi You should check for "error" as well, otherwise these get filtered out by the grep – Anthon Jun 11 '15 at 12:01
  • 1
    OK, thanks. I couldn't get git to give me such an "error" message again as it did in the morning (no matter what changes I did locally) but in the end I've managed to get a "fatal" message ;-) So I've also learned that this is another word to look for ;-) – Sadi Jun 11 '15 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.