tj / git-extras

GIT utilities -- repo summary, repl, changelog population, author commit percentages and more
MIT License
17.31k stars 1.21k forks source link

effort and summary complain if you `| head` them #464

Open apjanke opened 9 years ago

apjanke commented 9 years ago

If you do a git-effort or git-summary and pipe it to head, the programs complain about dying and maybe trigger other errors.

[~/.oh-my-zsh on ⇄ master]
$ git effort | head -4

  file                                          commits    active days

  .gitignore................................... 19         16
/usr/local/bin/git-effort: line 165: test: : integer expression expected
error: git-effort died of signal 13
[~/.oh-my-zsh on ⇄ master]
$ git summary | head -4

 project  : oh-my-zsh
 repo age : 6 years
 active   : 1415 days
error: git-summary died of signal 13
[~/.oh-my-zsh on ⇄ master]
$

Also, it seems like it leaves the cursor invisible when that happens.

I think they should play well with head/tail/other stream filters: not emitting errors, cleaning up terminal settings, and maybe turning off the colorization when they're going to a stream and not a tty, so you can get clean plain text output if you want to.

spacewander commented 9 years ago

I just digged a little deeper and figured out something.

error: xx died of signal 13 is added by git itself. Each time we type git summary, git will run git-summary as a sub command. After git-summary crashed by SIGPIPE, this error message will be printed.

To get rid of emitting error, one way is replacing git to git-. For example:

~/github/git-extras(master ✗) git-summary | head -4

 project  : git-extras
 repo age : 5 年前
 active   : 373 days

How can we work around git's error report mechanism? I am still thinking about it.


Let's talk about other questions. To clean up terminal settings, we can use trap clean_function EXIT to recover tty once the script exits. To turn off the colorization, I found a good code snippet from stackexchange

#!/usr/bin/env bash

if [ -t 1 ]
then
    echo 'To tty'
else
    echo 'To pipeline'
fi

I plan to send a pr to fix them.