Skip to content

Instantly share code, notes, and snippets.

@nishantjr
Last active March 11, 2017 05:58
Show Gist options
  • Save nishantjr/eccadd5be85778f10977f75414e63cad to your computer and use it in GitHub Desktop.
Save nishantjr/eccadd5be85778f10977f75414e63cad to your computer and use it in GitHub Desktop.
git-test-log
#!/usr/bin/env bash
# If no commits specified, we default to HEAD@{u}..HEAD. However if HEAD is uptodate,
# then `rev-parse` returns nothing. In that case we fallback to HEAD^..HEAD.
# XXX: This breaks if `some-other-brach@{u}..some-other-brach` is specified.
# adding a `--boundary` should have solved this issue, but there seems to be
# a bug in `git rev-parse` and `git rev-list`.
parsed_revs=($(git rev-parse --revs-only "$@" --default HEAD@{u}..HEAD))
[ ${#parsed_revs[@]} = 0 ] && parsed_revs=(HEAD ^HEAD^)
commit="%C(auto)%h"
format_good="$commit %Cgreengood%Creset%C(auto) %d %s"
format_bad="$commit %C(reverse red)bad %Creset%C(auto) %d %s"
format_unknown="$commit%Creset %C(auto)unkn %d %s"
while read -r rev; do
test_status=$(git notes --ref=refs/notes/tests/default show "$rev^{tree}" 2>/dev/null)
[ $? = 0 ] || test_status=unknown
format=
case "$test_status" in
good) format="$format_good" ;;
bad) format="$format_bad" ;;
unknown) format="$format_unknown" ;;
esac
git log --format="$format" -1 $rev
done < <(git rev-list "${parsed_revs[@]}" )
@0cjs
Copy link

0cjs commented Mar 11, 2017

Use //? instead of good/bad/unkn?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment