Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit subject length in git --for-each-ref

Tags:

git

Is there a way to specify the max length of the subject in the format string for git --for-each-ref? I'd have a handy shortcut that lists my branches and the subject of the most recent commit, but I'd like to truncate the length of the subject field so that the output doesn't wrap. On a whim, I tried %(subject:short) but git says

fatal: %(subject) does not take arguments
like image 486
sfjac Avatar asked Oct 18 '22 15:10

sfjac


1 Answers

You can use bash to display fields and limit the length with %.XXs :

git for-each-ref --count=1 --sort='-*authordate' \
--format='%(*refname)|%(*authorname)|%(*authoremail)|%(*subject)|%(*authordate)' 'refs/tags' | \
while IFS='|' read refname authorname authoremail subject authordate
do 
    echo   "Ref      : $refname"
    echo   "From     : $authorname $authoremail"
    printf "Subject  : %.30s\n" "$subject"
    echo   "Date     : $authordate"
done 
like image 180
Bertrand Martel Avatar answered Oct 21 '22 07:10

Bertrand Martel