Closed mfulbright closed 2 weeks ago
Hi there. It looks like this may already be supported via the $BRANCHLESS_TEST_COMMIT
env var. (I didn't see that mentioned in the wiki docs, but it looks like it's being injected in the code: https://github.com/arxanas/git-branchless/blob/master/git-branchless-test/src/lib.rs#L2645) Can you try this and see if it works for you:
# Fail any commits that still have "TODO_BEFORE_SUBMIT" in their changes:
$ git test run --exec '[[ ! $(git diff "$BRANCHLESS_TEST_COMMIT"^ "$BRANCHLESS_TEST_COMMIT" | grep TODO_BEFORE_SUBMIT) ]]'
Although in this case, I wonder if you could bypass the env var entirely and just do git diff @^
to get the diff for the current commit and its parent.
Fair warning: I didn't test either of these, but maybe they're worth a shot.
So far as I know, there is no way to refer to the commit that a
git test
command is operating on. I would find it useful to be able to do this:# Fail any commits that still have "TODO_BEFORE_SUBMIT" in their changes: $ git test run --exec '[[ ! $(git diff "$1^" "$1" | grep TODO_BEFORE_SUBMIT) ]]'
$1
represents the commit thatgit test
is currently operating on, e.g. ifgit test
is going to operate on 2 commits,abc
anddef
, then the first test would be[[ ! $(git diff "abc^" "abc" | grep TODO_BEFORE_SUBMIT) ]]
and the second test would be[[ ! $(git diff "def^" "def" | grep TODO_BEFORE_SUBMIT) ]]