The exercises in this section provide practice in identifying merge conflicts and their resolutions.
Exercises
Figure 5.1.1 shows the main branch in the right panel, the contributor’s feature branch in the left panel, and the common ancestor in the middle.
1.
Consider the merge shown in Figure 5.1.1. As shown in the right-hand panel, the maintainers have merged commits into the main branch that fix several bugs that existed in the program. The left-hand panel shows a contributor’s feature branch with has been changed to use more descriptive variable names but that has not fixed the bugs. The center panel shows the best common ancestor of the feature and main branches.
(a)
Study the program in the main branch and then describe in a sentence the computation that the program is trying to perform. Note: The Feature Branch and the Best Common Ancestor both contain bugs.
(b)
Highlight (by clicking, or by circling) all of the lines that are non-conflicting changes in the feature branch or the main branch. Use the example in the slides as a guide for highlighting.
Feature Branch
Best Common Ancestor
main Branch
total=0
tot=0
tot=0
count=0
count=0
count=0
read n
read n
read n
while count > n:
while count > n:
while count < n:
read m
read m
read m
total=total+m
tot=tot+m
tot=tot+m
count--
count--
count++
average=count ⁄ total
ave=count ⁄ tot
ave=tot ⁄ count
Hint.
Merge conflicts occur when both source branches change the same line.
(c)
Highlight (by clicking, or by circling) all of the lines that are conflicting changes in the feature branch and the main branch as shown in Figure 5.1.1. Use the example in the slides as a guide for highlighting.
Feature Branch
Best Common Ancestor
main Branch
total=0
tot=0
tot=0
count=0
count=0
count=0
read n
read n
read n
while count > n:
while count > n:
while count < n:
read m
read m
read m
total=total+m
tot=tot+m
tot=tot+m
count--
count--
count++
average=count ⁄ total
ave=count ⁄ tot
ave=tot ⁄ count
Hint.
Merge conflicts occur when both source branches change the same line.
(d)
Would the feature branch in Figure 5.1.1 be able to be merged automatically by the project maintainers? Briefly explain your answer.
(e)
Highlight the correct lines that give a Merged Result of the program in Figure 5.1.1 that combines the feature branch and the main branch such that the result both performs the desired computation and uses the more descriptive variable names.
Figure 5.1.2 shows the main branch in the right panel, the contributor’s feature branch in the left panel, and the common ancestor in the middle.
2.
Now consider the merge shown in Figure 5.1.2. As shown in the right-hand panel, the maintainers have merged commits into the main branch that fix several bugs that existed in the program. The left-hand panel shows a contributor’s feature branch with has been changed to use more descriptive variable names but that has not fixed the bugs. The center panel shows the best common ancestor of the feature and main branches.
(a)
Study the program in the main branch and then describe in a sentence the computation that the program is trying to perform. Note: The ** indicates exponentiation (e.g. x**2 is x squared). Note: The Common Ancestor contains a bug that is fixed in different ways by the main branch and the feature branch.
(b)
Highlight (by clicking, or by circling) all of the lines that are non-conflicting changes in the feature branch or the main branch as shown in Figure 5.1.1. Use the example in the slides as a guide for highlighting.
Feature Branch
Best Common Ancestor
main Branch
r=15
r=15
r=15
pi = 3.1415927
pi = 3.14
pi = 3.14
rsq = r**2
rsq = r*2
rsq = r*2
a = pi*rsq
a = pi*rsq
area = pi*(rsq/2)**2
print a
print a
print area
Hint.
Merge conflicts occur when the feature, main, and common ancestor branches are all different.
(c)
Highlight (by clicking, or by circling) all of the lines that are conflicting changes in the feature branch and the main branch as shown in Figure 5.1.1. Use the example in the slides as a guide for highlighting.
Feature Branch
Best Common Ancestor
main Branch
r=15
r=15
r=15
pi = 3.1415927
pi = 3.14
pi = 3.14
rsq = r**2
rsq = r*2
rsq = r*2
a = pi*rsq
a = pi*rsq
area = pi*(rsq/2)**2
print a
print a
print area
Hint.
Merge conflicts occur when the feature, main, and common ancestor branches are all different.
(d)
Would the feature branch in Figure 5.1.2 be able to be merged automatically by the project maintainers? Briefly explain your answer.
(e)
Give the Merged Result to show the result of an automatic merge of the feature and main branches shown in Figure 5.1.2.