Reputation: 7608
Let say I've previously set up a super-swish test framework for a legacy system. That is feature A existed long before the test for feature A. Feature B, C and D come along and without us realising, at some point break the test for feature A.
We want to find out which of the features did that.
Now I want to run:
git bisect <bad> <good>
git run ./swish_test_suite.sh
The issue is that the code files that test feature A came in between <bad>
and <good>
. I've tried just manually extracting out the code, but then various configurations, and paths to test data break (fragile code?).
Is there a way to tell git bisect
to ignore a folder? I can imagine that going horribly wrong sometimes, but I'm guessing that might be easier than alternatives.
It's not solved here How can I ignore a directory when doing a Git bisect? as that covers build folders, where the solution is to remove them from the repo, but I want to keep my tests commited!
This git bisect with feature branches / later commits are needed to build is a little different too, as I'm not using patches or feature branches (should I?) Also the solutions seem to just be for manually running it, not git bisect run
ning it!
Upvotes: 2
Views: 216
Reputation: 5619
git bisect
allows to exclude specific paths, so the command simply will not be checking out commits that change that path (except the docs is unclear on whether it will skip commits that change another path additionally to that one or not).
git bisect start -- ':/' ':!/dir1/' ':!/dir2/'
Here I use "pathspec" to first include everything in the repo and then I exclude top-level dir1
and dir2
.
The first ':/'
that includes everything is mandatory in this case because these parameters determine dirs to be included (and !
inverts the logic), so in absence of ':/'
git would think you didn't include anything at all and you'll get a No testable commit found.
error.
Upvotes: 2
Reputation: 8345
For cases like this, write your test script in such a way that it adds stuff that you need in each step. The git help bisect
manual has an example which you might be able to tweak to your needs. I.e., where that example does a git merge hotfix
, do whatever you need to get the test files you require. Depending on the situation, a merge may not be what you're looking for, but you might cherry-pick your tests from somewhere, or simply copy them to some other directory beforehand (before the bisect operation) and copy them in with cp
.
· Automatically bisect with temporary modifications (hot-fix):
$ cat ~/test.sh
#!/bin/sh
# tweak the working tree by merging the hot-fix branch
# and then attempt a build
if git merge --no-commit hot-fix &&
make
then
# run project specific test and report its status
~/check_test_case.sh
status=$?
else
# tell the caller this is untestable
status=125
fi
# undo the tweak to allow clean flipping to the next commit
git reset --hard
# return control
exit $status
Upvotes: 1