In this exercise, you will go through a workflow to perform a refactoring. The overall process includes:
- Setting up an issue at GitHub
- Creating an issue branch
- Performing the Rename Method refactoring
- Creating a pull request
- Accepting the pull request
- Closing the issue
- Deleting the issue branch (but don't do)
The following workflow must be followed to receive credit. Use the exact same commit messages as shown.
Set Up the Issue
- Create An Issue In GitHub, create an issue in your repository for the refactoring. The title of the issue is: For the body of the messages, explain what you will do as well as possible.
- Assign Yourself to the Issue Once the issue is created, assign yourself to the issue. That way, others know you are working on the issue.
Set Up a Branch for the Issue
- Create an Issue Branch Instead of working on the branch
main
, you are going to work on the branchissue_n_
where n is the issue number, e.g., if the issue number is 1 then the branch name isissue1
. First, make sure you are in the branchmain
. Then, create the branch: Branches can be created via GitHub. However, please create this issue via the command line. - You have created a new branch locally, but it does not yet exist at GitHub. To do so, you need to push it to GitHub. When you do so, you will see an error message. Enter the command that it shows you.
Perform a Rename Method Refactoring
- You are going to perform a refactoring. At every commit, the code must compile, build, and produce exactly the same result.
- Create a new method declaration in the ToDoList.hpp file. This is not a definition, only the declaration. Compile the program and get it to build successfully. Once done, commit using the commit message: Push your changes to GitHub.
- Create a new method definition in the ToDoList.cpp file. This method definition will not have any contents and will return a 0. In other words, the shortest/smallest implementation that will get the program to build. Once done, commit using the commit message: Push your changes to GitHub.
- Copy the contents of the old method
length()
definition to the new methodsize()
. Successfully build the program. Once done, commit using the commit message: Push your changes to GitHub. - At this point, both
size()
andlength()
do the same thing. Now, changelength()
(the old method) to callsize()
(the new method). The definition oflength()
should only have the call tosize()
. Note that you must pass along the parameters and handle anyreturn
statements. Push your changes to GitHub. - One-by-one, replace any calls of the method
length()
with a call to methodsize()
. Again, this must be done one call at a time. After each change, compile, build, and run successfully. Commit each time using the git command: Push your changes to GitHub - After all calls to length() are replaced, delete the definition (not declaration) of
length()
in ToDoList.cpp. Compile, build, and run successfully. Commit using the command: Push your changes to GitHub - Now delete the declaration of length() from ToDoList.hpp. Compile, build, and run successfully. Commit using the command: Push your changes to GitHub.
At this point, the refactoring is complete.
Create a Pull Request
Create a pull request at GitHub. You want to pull from the branch issue1
into the branch main
.
Accept the Pull Request
Accept the pull request at GitHub. Typically, this would be done by another team member, but in this case, you can accept your own pull request.
In your GitHub Codespaces or on your local machine, switch to the branch main
and pull the changes. You should see the rename in the code on the branch main
.
Close the Issue
- At this point, you have completed the issue and can close it. Do so at GitHub.
Delete the Branch
- The branch
issue1
has done its job and is no longer needed. All your commits on this branch are now in the branchmain
. - We could delete this branch, but do not do so for purposes of this assignment.