project created

This commit is contained in:
2026-06-23 05:19:37 +08:00
parent 1390a6f2e4
commit 1ba0f4ba28
9 changed files with 282 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
# Default ignored files
/shelf/
/.idea/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
/target
.idea/
*.iml
# Compiled Maven output
/target/
target/
# IntelliJ IDEA project files
*.iws
*.ipr
# Compiled class files
*.class
# Logs
*.log
+144 -2
View File
@@ -1,2 +1,144 @@
# Advanced-git
This repo is a workshop assignment to practice conflict resolvation in git # 🚀 WS 11 - Advanced Git & Github
---
## 📖 Overview
In this assignment, you will simulate multiple developers working on the same project using different Git branches.
You will create parallel development scenarios, encounter merge conflicts, and practice resolving them using Git. By the end, you should feel confident handling common conflict situations that occur in real-world software development.
---
## Prerequisites
- Git installed
- A GitHub account
- Java SDK 25
- Maven
---
## 🎯 Objectives
By completing this assignment, you will:
- Become comfortable creating and switching between Git branches
- Learn how to resolve same-line content conflicts
- Practice resolving:
- Modify/modify conflicts
- Modify/delete conflicts
- Rename conflicts
- Understand how Git tracks file changes across branches
---
## Project Structure
- **Calculator.java:** Interface which defines calculator methods
- **BasicCalculator.java:** Implements Calculator with basic arithmetic
- **MathHelper.java:** Static utility methods (multiply, square, max)
- **ReportGenerator.java:** Uses Calculator and MathHelper to produce formatted output
---
## 📦 Task 1 Refactoring Conflict
### Scenario:
Two developers are working in parallel:<br>
- Developer A refactors the code by renaming a method.
- Developer B continues developing a new feature using the old method name.
When their work is merged, a conflict will occur.
1. First fork & clone the repository and create develop branch:
```
git clone https://github.com/<your-username>/conflict-demo.git
git checkout -b develop
```
2. Create two feature branches(feature/refactor-multiply & feature/change-multiply). we will assume they are 2 separate developers working on project. One of them will refactor project by renaming a method across whole project, while other developer is still working with old name.
```
git checkout develop
git checkout -b feature/refactor-multiply
git checkout develop
git checkout -b feature/change-multiply
```
3. From feature/refactor-multiply branch, rename "multiply" method to "product" everywhere.
```
git checkout feature/refactor-multiply
# TODO: rename method "multiply" to "product" in Calculator, BasicCalculator, MathHelper and ReportGenerator
git add .
git commit -m "refactor: renamed multiply to product"
git checkout develop
git merge feature/refactor-multiply
```
4. From feature/change-multiply branch, change the body of multiply method
```
git checkout feature/change-multiply
# TODO: change the body of MathHelper.multiply (e.g., loop-based multiplication)
git add .
git commit -m "multiply method body changed"
git checkout develop
git merge feature/change-multiply # CONFLICT
```
5. Resolve the conflict
```
# TODO: Open conflicted file(s), decide to keep the `product` name, and apply the new logic.
git add .
git commit -m "conflict resolved: keep rename, apply new multiply logic"
```
---
## 📦 Task 2 Deletion Conflict
### Scenario
Two developers are working on the same interface:
- Developer A decides that the `Calculator` interface is no longer needed and deletes it from the project.
- Developer B is still working on the interface and adds a new method to it.
When the branches are merged, Git will detect a **modify/delete conflict** because one branch deleted the file while the other modified it.
1. Create Two branches called feature/remove-calculator and feature/add-method-to-interface. We will delete interface file in project in first branch, while second one is working on it. Then we will solve conflict that happends in merging.
```
git checkout develop
git checkout -b feature/remove-calculator
git checkout develop
git checkout -b feature/add-method-to-interface
```
2. From feature/remove-calculator branch, delete interface file completely:
```
git checkout feature/remove-calculator
git rm src/main/java/com/ap/Calculator.java
git commit -m "remove Calculator interface"
git checkout develop
git merge feature/remove-calculator
```
3. From feature/add-method-to-interface add method to deleted interface
```
git checkout feature/add-method-to-interface
# TODO: add "double calculateArea(double,double)" to Calculator, implement in BasicCalculator
git add .
git commit -m "add calculateArea() method"
git checkout develop
git merge feature/add-method-to-interface # CONFLICT
```
4. Resolve
- Keep the `Calculator` interface.
- Restore the deleted file.
- Add the new `calculateArea()` method to the interface.
```
git add .
git commit -m "resolved: Restored deleted interface and added calculateArea "
```
---
## 📤 Deliverable
- Push your branches with all merge commits. <br>
- Show output of your git history:
```
git log --oneline --graph --all --decorate
```
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ap</groupId>
<artifactId>Advanced-git</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.12.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
+18
View File
@@ -0,0 +1,18 @@
package com.ap;
public class BasicCalculator implements Calculator {
@Override
public int add(int a, int b) {
return a + b;
}
@Override
public int subtract(int a, int b) {
return a - b;
}
@Override
public int multiply(int a, int b) {
return a * b;
}
}
+7
View File
@@ -0,0 +1,7 @@
package com.ap;
public interface Calculator {
int add(int a, int b);
int subtract(int a, int b);
int multiply(int a, int b);
}
+8
View File
@@ -0,0 +1,8 @@
package com.ap;
public class Main {
public static void main(String[] args) {
ReportGenerator generator = new ReportGenerator();
generator.generate(5, 3);
}
}
+15
View File
@@ -0,0 +1,15 @@
package com.ap;
public class MathHelper {
public static int multiply(int a, int b) {
return a * b;
}
public static int square(int x) {
return x * x;
}
public static int max(int a, int b) {
return a > b ? a : b;
}
}
+13
View File
@@ -0,0 +1,13 @@
package com.ap;
public class ReportGenerator {
public void generate(int x, int y) {
Calculator calc = new BasicCalculator();
int sum = calc.add(x, y);
int diff = calc.subtract(x, y);
int product = calc.multiply(x, y);
int max = MathHelper.max(x, y);
System.out.println("Sum: " + sum + ", Diff: " + diff +
", Product: " + product + ", Max: " + max);
}
}
+26
View File
@@ -0,0 +1,26 @@
import com.ap.BasicCalculator;
import com.ap.Calculator;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class CalculatorTest {
@Test
void testAdd() {
Calculator calc = new BasicCalculator();
assertEquals(5, calc.add(2, 3));
}
@Test
void testSubtract() {
Calculator calc = new BasicCalculator();
assertEquals(2, calc.subtract(5, 3));
}
@Test
void testMultiply() {
Calculator calc = new BasicCalculator();
assertEquals(6, calc.multiply(2, 3));
}
}