https://github.com/bast/git-bisect-exercise
Git bisect exercise.
https://github.com/bast/git-bisect-exercise
Last synced: about 1 year ago
JSON representation
Git bisect exercise.
- Host: GitHub
- URL: https://github.com/bast/git-bisect-exercise
- Owner: bast
- License: bsd-3-clause
- Created: 2014-09-04T22:28:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-03-29T15:23:18.000Z (about 7 years ago)
- Last Synced: 2025-03-26T07:36:20.222Z (about 1 year ago)
- Language: Python
- Size: 126 KB
- Stars: 8
- Watchers: 2
- Forks: 50
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](../master/LICENSE)
## Git bisect exercise
### Motivation
The motivation for this exercise is to be able to do archaeology with Git on a
source code where the bug is difficult to see visually. **Finding the offending
commit is often more than half the debugging**.
### Background
The script `get_pi.py` approximates pi using terms of the Nilakantha series. It
should produce 3.14 but it does not. The script broke at some point and
produces 3.57 using the last commit:
```
$ python get_pi.py
3.57
```
At some point within the 500 first commits, an error was introduced. The only
thing we know is that the first commit worked correctly.
### Your task
Clone or fork this repository and use `git bisect` to find the commit which
broke the computation.
### How to find the first commit
```
$ git log --oneline | tail -n 1
```
### Bonus exercise
Write a script that checks for a correct result and use `git bisect run` to
find the offending commit automatically.
### Solutions (spoiler alert!)
The offending commit is commit number 137.
And here is a Python script which can be used together with `git bisect run`
to find the offending commit automatically:
```python
import subprocess
import math
import sys
output = subprocess.check_output(['python', 'get_pi.py'])
result = float(output)
if math.isclose(result, 3.14):
sys.exit(0)
else:
sys.exit(1)
```
But you can also try to solve this using a shell script or a script
in your favourite language.