Lesson 4 of 5
How software is changed
Listen to an AI summary of How software is changed
Where the code is kept
The source code of the sports shop is a folder of files named shop.
A repository is the folder that holds the source code of a project together with the history of every change.
What is a commit
A person on the team edits a file, then saves the change to the repository. A commit is one saved change to the code in a repository, with a note that says what changed. One note in the sports shop says Add the page for one order.
What is a branch
The repository has a main copy of the code, and the real sports shop runs the main copy. A half finished change in the main copy could break the shop for every customer.
A branch is a separate copy of the code where a person can make changes without affecting the main copy. The person saves each commit on the branch.
The word comes from a tree. The main copy is the trunk. A branch grows away from the trunk, and a finished branch joins the trunk again.
To merge is to add the changes from one branch into another branch. The main copy is a branch too. A finished change is merged from the new branch into the main copy.
What is a merge request
A finished change is not merged straight away. The person who made the change opens a merge request, which some websites call a pull request. A merge request is a proposed change that waits for a review before the change is merged.
Before the merge, a reviewer looks for weaknesses.
1.Branch
a separate copy of the code
2.Commit
one saved change, with a note
3.Merge request
the change is proposed
4.Review
a reviewer reads the change
5.Merge
the change joins the main copy
What is a diff
A reviewer reads what changed, not the whole repository. Diff is short for difference. A diff shows the difference between two versions of the code as the lines removed and the lines added.
A diff is like tracked changes in a shared document. Each deleted word is crossed out and each new word is coloured. A second person reads the changes and accepts or rejects each change.
The crossed out words stand for the removed lines. The new words stand for the added lines. The second person stands for the reviewer.
Look at the sign at the start of each line.
The lines with no sign did not change. The removed line looked up an invoice, which is a bill, for the person who is signed in. The added line looks up an invoice by number alone.
Reading a merge request
A merge request to the sports shop adds a page that shows one order. The merge request has four parts.
- A web page at the address code.example/sports-shop/merge-requests/12.
- Add a page that shows one order the title
- A customer can open one order from the order list. The page shows the items and the total. the description
- Files changed 2 the list of files
- The file orders.js, 2 lines added, 1 removed.
- The file order.html, new file, 9 lines added.
- The diff of the file orders.js. the diff of each file
A reviewer reads the description first. The description says what the change is for. A reviewer who knows what the change is for can tell when the diff does something else.
The list of files comes next. orders.js is a JavaScript file with the code for the pages about orders. order.html is a new file written in HTML.
The diff of orders.js comes last. Look at the sign at the start of each line.
orders.js. One line was removed and two lines were added.The removed line returned the words Coming soon.
To call a function is to run the function. The first added line calls findOrder to look up one order by the order number. The second added line calls showPage to build the new page from order.html.
Outside the changed lines
Tracked changes show the whole document. A diff shows only the changed lines and a few lines either side.
The order number in showOrder comes from a request, so the order number is input.
A customer can send any order number, including the number of another customer's order.
The diff does not show a check that the order belongs to the customer who asks for the order. A reviewer looks in two places outside the changed lines:
- The rest of
orders.js, such as the line that reads the order number from the request. - Other files, such as the file that holds
findOrder, which the merge request did not change.
Check your understanding
State the order of these five steps, starting with the first. Review, branch, merge, commit, merge request.
Show the answer
Branch, commit, merge request, review, merge.
Identify the line that was removed in the diff of
orders.js.Show the answer
The line
return 'Coming soon'was removed. The line starts with a minus sign.Give one reason why a reviewer opens a whole file as well as reading the diff.
Show the answer
A diff shows only the changed lines and a few lines either side. A function that an added line calls can be in code the diff does not show.