News for hackers. Stuff that matters.
Re:Keeping a project bisectable by alkonaut on Friday August 05, 2022 @03:46AM (#32352968)
Recently git bisect gained got a new capability that was mysteriously missing before: bisect —first-parent. With that, it became possible to bisect also in repos where all commits on feature branches may not be buildable or passing tests, but commits on the development/main/integration branch does.

A feature I’m still missing is to bisect using a new test. That is, I have discovered a bug in the program that there is no test for, so I author a failing test. Now I want to find out when this failure occurred but I can’t bisect because even the previous commit is green as the test didn’t exist. It’s possible to work around by placing the test outside the repo root and bisecting with a script that “authors” the test (e.g copies the file) at each step, but it’s cumbersome and feels like something that could be possible to add to the bisect command, e.g an option to merge a commit (the new test) before testing each step of the bisect.

Re:Keeping a project bisectable by 32bitkid on Friday August 05, 2022 @06:05AM (#32353951)
For the latter I use often use `git stash` for that; stashing off the test case/data, then at each step of the bisect, you can do `git stash apply` (rather than `git stash pop`) to reapply the same changes multiple times.

Before moving on, a quick `git reset —-hard` will get back to a clean flip

Re:Keeping a project bisectable by Deradon on Friday August 05, 2022 @11:23AM (#32357469)
For ruby projects where I could simply put the "new test" in a new file I do this:

1. Create new test (e.g. "spec/reproduce-bug_spec.rb")

2. Ignore it locally: `echo "spec/reproduce_bug_spec.rb" >> .git/info/exclude`

3. Run bisect (something like: `git bisect run rspec spec/reproduce-bug_spec.rb`)

If running the test gets more complex (e.g. installing dependencies as they might change travelling through history), I usually create a wrapper script (and ignore it) to bisect-run-it.

Re:Keeping a project bisectable by OJFord on Friday August 05, 2022 @04:01AM (#32353061)
Just put the test in a new untracked file?
Re:Keeping a project bisectable by alkonaut on Friday August 05, 2022 @05:48AM (#32353803)
That works but only for languages/build-systems where the mere presence of the test is enough to make it run. In others you might have xml project files, test lists etc which makes the addition of a test require a modification of existing files.
Re:Keeping a project bisectable by Izkata on Friday August 05, 2022 @08:53AM (#32355377)
The test subcommand of bisect can do anything you want, so it's easy to make a wrapper that does that prep work before starting that actual tests. Just have to remember to pass back the tests' exit code after cleaning up the repository for git.
Re:Keeping a project bisectable by OJFord on Saturday August 06, 2022 @05:48AM (#32366573)
Good point, though I don't like the idea of a setup where your test file's only executed if you remember to do that personally (if the tooling doesn't already do similar, I'd at least want to generate the list you describe by globbing the relevantly named/located files).

You could just copy that entrypoint into another untracked file, have its list include (or be only - quicker) the new untracked test file, and execute that instead of the normal one while bisecting.

Re:Keeping a project bisectable by kazinator on Friday August 05, 2022 @02:59PM (#32360421)
To bisect with a new test, you have to do this:

  $ git bisect [good|bad]

  $ git cherry-pick new-test

  $ ./run-the-test

  $ git reset --hard HEAD^

  $ git bisect [good|bad]
I sometimes use the stash for that: cherry pick the test as a working tree uncommitted change. "git stash" it before every bisect step, then "git pop".
Re:Keeping a project bisectable by alkonaut on Friday August 05, 2022 @04:38PM (#32361715)
Yeah, since it's more or less a standard cumbersome recipe, it seems it would be a good idea to create a high level git switch for it.

git bisect run --cherry-pick abc123 [....]

to do a regular bisect but at each step cherry picking the commit abc123

Re:Keeping a project bisectable by progers7 on Friday August 05, 2022 @08:54AM (#32355390)
I have saved a little script to use with git bisect and a stashed test: https://gist.github.com/progers/998452a15180ae369fee338bb393...
Re:Keeping a project bisectable by Hackbraten on Friday August 05, 2022 @04:05AM (#32353095)
Have you tried duplicating the test temporarily, which should turn the duplicate into an untracked file so you wouldn’t have to copy it at each step?
Re:Keeping a project bisectable by k_ on Friday August 05, 2022 @04:00AM (#32353056)
This might be a good argument for keeping tests as a separate repository. Which would bring a lot more problems of its own, though...