Welcome to this exercise about git bissect and pull requests. This repository is made of 3 branches :
- main
- dev
- decimal-binary-converter
A binary/decimal two-way converter has been implemented in this repository. It is still in a development stage, in its feature branch.
You should be working from your own repository that is a fork of M1-2022-git. In order to run this project, you will have to follow these steps.
- Clone this project
- move into the project folder
cd M1-2022-git
- Set up a virtual environment
- Create the virtual environment
python -m venv myvenv
- Activate venv
. venv/bin/activate
- Install pytest
pip install -U pytest
- Execute main script
python main.py
Now, you'll have to experiment with the repo.
- Inspect the different branches and find where the code of the converter is
- Run the converter code
- You may notice that the code contains some bugs. The code lacks some unit tests to expose such bugs. We will create some :
- Create a file whose name starts with test_
- Inside that file, create a class. The class name must have the prefix Test and the class must inherit unittest.TestCase (do not forget to import unittest package)
- Inside that class, Define test methods for each function of the converter. Each test method must have a name starting with test_ (again).
- Inside your terminal (you should be in your project directory), run :
pytest
This will execute the tests you have written and show you a test report.
- On Github, in your repository, open an issue about the bugs you found. Remember to be specific about the problem. You should also include code to reproduce the issue
- Using git bisect, find which commit is faulty, introducing those bugs. Reminder : to use git bisect, ensure that the bug is present at the commit you're at. If so, type
git bisect bad
Then, find an old commit where the code had no bug (use git checkout to navigate from one commit to another. Do not hesitate to go far in the past : the interest of git bisect is that you won't have to test one commit after another, so take an old commit (maybe when the feature was introduced) and let git do the magic. When you've found a commit where the bugs are not present, you can execute
git bisect good
Now, git knows where to start (it has a buggy commit and a clean commit). So, you can execute :
git bisect start
Git will navigate through commits using Binary Search. For each step, run the tests. If the tests are KO, type git bisect bad else git bisect good. After a few steps, git will tell you what commit is faulty.
- Once you've found the faulty commit, find what lines are responsible of the bugs and fix them. If you've fixed all the bugs, all Unit Tests should return OK when pytest is run
- Now that the converter has no more bugs, we want to merge our branch feature into the dev branch. We will do a pull request (on your own repo). On GitHub, go to the "Pull requests tab" and click "New pull request". Select base and compare. Remember : we want to merge decimal-binary-converter into dev. Then, Create the pull request. Add some description of the work you have done and publish the Pull Request. Note : We could have just merge decimal-binary-converter into dev from the command line. However, when working on a real project, you probably won't have the rights to do so. Remember : dev is a public branch. So all the work going down there should be carefully reviewed and tested.
- Go into the "Pull Request tab" and merge your branch into dev