refactor: we're breaking out merge-conflicts

This commit is contained in:
Bjarke Sporring
2026-01-15 12:51:43 +01:00
parent ea5cbccc75
commit 7b638d27de
29 changed files with 1385 additions and 1310 deletions

View File

@@ -1,17 +1,13 @@
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Sets up the Module 03 checkpoint-based challenge environment.
Sets up the Module 03 challenge environment for branching and merging.
.DESCRIPTION
This script creates a challenge directory with a complete Git repository
containing all commits and checkpoints for learning branching, merging,
and merge conflict resolution in one continuous workflow.
The script creates three checkpoints:
- checkpoint-start: Beginning of branching basics
- checkpoint-merge: Beginning of merging section
- checkpoint-merge-conflict: Beginning of conflict resolution
This script creates a challenge directory with a Git repository containing
a realistic project history with multiple merged branches. Students will see
what branching and merging looks like in practice, then create their own
branches to experiment.
#>
Write-Host "`n=== Setting up Module 03: Branching and Merging ===" -ForegroundColor Cyan
@@ -36,113 +32,75 @@ git config user.name "Workshop Student"
git config user.email "student@example.com"
# ============================================================================
# PHASE 1: Branching Basics - Initial commits on main
# Create a realistic project history with multiple merged branches
# ============================================================================
Write-Host "`nPhase 1: Creating initial project structure..." -ForegroundColor Cyan
Write-Host "Creating project history with multiple branches..." -ForegroundColor Cyan
# Commit 1: Initial commit
$mainContent = @"
# main.py - Main application file
# Initial commits on main
$readmeContent = @"
# My Application
def main():
print("Welcome to the Application!")
print("This is the main branch")
if __name__ == "__main__":
main()
A sample application for learning Git branching and merging.
"@
Set-Content -Path "main.py" -Value $mainContent
Set-Content -Path "README.md" -Value $readmeContent
git add .
git commit -m "Initial commit" | Out-Null
# Commit 2: Add main functionality
$mainContent = @"
# main.py - Main application file
def main():
print("Welcome to the Application!")
print("This is the main branch")
run_application()
def run_application():
print("Application is running...")
print("Ready for new features!")
if __name__ == "__main__":
main()
"@
Set-Content -Path "main.py" -Value $mainContent
git add .
git commit -m "Add main functionality" | Out-Null
# Tag checkpoint-start (students begin here - will create feature-login)
Write-Host "Creating checkpoint: start" -ForegroundColor Green
git tag checkpoint-start
git commit -m "Add main application file" | Out-Null
# ============================================================================
# PHASE 2: Create feature-login branch (what students will do in checkpoint 1)
# Branch 1: feature-login (will be merged)
# ============================================================================
Write-Host "Phase 2: Creating feature-login branch..." -ForegroundColor Cyan
# Create and switch to feature-login branch
Write-Host "Creating feature-login branch..." -ForegroundColor Cyan
git switch -c feature-login | Out-Null
# Commit 3: Add login module
$loginContent = @"
# login.py - User login module
# login.py - User authentication
def login(username, password):
"""Authenticate a user."""
print(f"Authenticating user: {username}")
# TODO: Add actual authentication logic
return True
def logout(username):
"""Log out a user."""
print(f"Logging out user: {username}")
print(f"Logging in user: {username}")
return True
"@
Set-Content -Path "login.py" -Value $loginContent
git add .
git commit -m "Add login module" | Out-Null
# Commit 4: Add password validation
$loginContent = @"
# login.py - User login module
# login.py - User authentication
def validate_password(password):
"""Validate password strength."""
if len(password) < 8:
return False
return True
return len(password) >= 8
def login(username, password):
"""Authenticate a user."""
if not validate_password(password):
print("Password too weak!")
return False
print(f"Authenticating user: {username}")
# TODO: Add actual authentication logic
return True
def logout(username):
"""Log out a user."""
print(f"Logging out user: {username}")
print(f"Logging in user: {username}")
return True
"@
Set-Content -Path "login.py" -Value $loginContent
git add .
git commit -m "Add password validation" | Out-Null
# Switch back to main
# Switch back to main and make more commits
git switch main | Out-Null
# Now create divergence - add commits to main while feature-login exists
Write-Host "Creating divergent history on main..." -ForegroundColor Cyan
# Commit 5: Add app.py with basic functionality
$appContent = @"
# app.py - Main application entry point
# app.py - Application entry point
from main import main
@@ -150,7 +108,6 @@ def run():
"""Run the application."""
print("Starting application...")
main()
print("Application finished.")
if __name__ == "__main__":
run()
@@ -159,16 +116,65 @@ Set-Content -Path "app.py" -Value $appContent
git add .
git commit -m "Add app.py entry point" | Out-Null
# Commit 6: Add README
# Merge feature-login into main
Write-Host "Merging feature-login into main..." -ForegroundColor Green
git merge feature-login --no-edit | Out-Null
# ============================================================================
# Branch 2: feature-api (will be merged)
# ============================================================================
Write-Host "Creating feature-api branch..." -ForegroundColor Cyan
git switch -c feature-api | Out-Null
$apiContent = @"
# api.py - API endpoints
def get_data():
"""Retrieve data from API."""
return {"status": "ok", "data": []}
def post_data(data):
"""Send data to API."""
print(f"Posting data: {data}")
return {"status": "ok"}
"@
Set-Content -Path "api.py" -Value $apiContent
git add .
git commit -m "Add API module" | Out-Null
$apiContent = @"
# api.py - API endpoints
def get_data():
"""Retrieve data from API."""
return {"status": "ok", "data": []}
def post_data(data):
"""Send data to API."""
print(f"Posting data: {data}")
return {"status": "ok"}
def delete_data(id):
"""Delete data by ID."""
print(f"Deleting data: {id}")
return {"status": "ok"}
"@
Set-Content -Path "api.py" -Value $apiContent
git add .
git commit -m "Add delete endpoint to API" | Out-Null
# Switch back to main and add documentation
git switch main | Out-Null
$readmeContent = @"
# My Application
Welcome to my application!
A sample application for learning Git branching and merging.
## Features
- Main functionality
- More features coming soon
- User authentication
- Main application logic
## Setup
@@ -176,104 +182,107 @@ Run: python app.py
"@
Set-Content -Path "README.md" -Value $readmeContent
git add .
git commit -m "Add README documentation" | Out-Null
git commit -m "Update README with setup instructions" | Out-Null
# Tag checkpoint-merge (students begin merging here - divergent branches ready)
Write-Host "Creating checkpoint: merge" -ForegroundColor Green
git tag checkpoint-merge
# Merge feature-api into main
Write-Host "Merging feature-api into main..." -ForegroundColor Green
git merge feature-api --no-edit | Out-Null
# ============================================================================
# PHASE 3: Merge feature-login into main (what students will do in checkpoint 2)
# Branch 3: feature-database (will be merged)
# ============================================================================
Write-Host "Phase 3: Merging feature-login into main..." -ForegroundColor Cyan
Write-Host "Creating feature-database branch..." -ForegroundColor Cyan
git switch -c feature-database | Out-Null
# Merge feature-login into main (will create three-way merge commit)
git merge feature-login --no-edit | Out-Null
$dbContent = @"
# database.py - Database operations
# ============================================================================
# PHASE 4: Create conflict scenario (what students will do in checkpoint 3)
# ============================================================================
Write-Host "Phase 4: Creating merge conflict scenario..." -ForegroundColor Cyan
class Database:
def __init__(self):
self.connection = None
# Create config.json file on main
$initialConfig = @"
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"port": 3000
}
}
def connect(self):
"""Connect to database."""
print("Connecting to database...")
self.connection = True
def query(self, sql):
"""Execute SQL query."""
print(f"Executing: {sql}")
return []
"@
Set-Content -Path "config.json" -Value $initialConfig
git add config.json
git commit -m "Add initial configuration" | Out-Null
Set-Content -Path "database.py" -Value $dbContent
git add .
git commit -m "Add database module" | Out-Null
# On main branch: Add timeout setting
$mainConfig = @"
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"port": 3000,
"timeout": 5000
}
}
$dbContent = @"
# database.py - Database operations
class Database:
def __init__(self):
self.connection = None
def connect(self):
"""Connect to database."""
print("Connecting to database...")
self.connection = True
def disconnect(self):
"""Disconnect from database."""
print("Disconnecting from database...")
self.connection = None
def query(self, sql):
"""Execute SQL query."""
print(f"Executing: {sql}")
return []
"@
Set-Content -Path "config.json" -Value $mainConfig
git add config.json
git commit -m "Add timeout configuration" | Out-Null
Set-Content -Path "database.py" -Value $dbContent
git add .
git commit -m "Add disconnect method" | Out-Null
# Create update-config branch from the commit before timeout was added
git switch -c update-config HEAD~1 | Out-Null
# On update-config branch: Add debug setting (conflicting change)
$featureConfig = @"
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"port": 3000,
"debug": true
}
}
"@
Set-Content -Path "config.json" -Value $featureConfig
git add config.json
git commit -m "Add debug mode configuration" | Out-Null
# Switch back to main
# Switch to main and merge
git switch main | Out-Null
Write-Host "Merging feature-database into main..." -ForegroundColor Green
git merge feature-database --no-edit | Out-Null
# Tag checkpoint-merge-conflict (students begin conflict resolution here - on main with timeout, update-config has debug)
Write-Host "Creating checkpoint: merge-conflict" -ForegroundColor Green
git tag checkpoint-merge-conflict
# Final update on main
$readmeContent = @"
# My Application
# ============================================================================
# Reset to checkpoint-start so students begin at the beginning
# ============================================================================
Write-Host "`nResetting to checkpoint-start..." -ForegroundColor Yellow
git reset --hard checkpoint-start | Out-Null
git clean -fd | Out-Null
A sample application for learning Git branching and merging.
## Features
- User authentication
- API endpoints
- Database operations
- Main application logic
## Setup
Run: python app.py
## Requirements
- Python 3.6+
"@
Set-Content -Path "README.md" -Value $readmeContent
git add .
git commit -m "Update README with all features" | Out-Null
# Return to module directory
Set-Location ..
Write-Host "`n=== Setup Complete! ===" -ForegroundColor Green
Write-Host "`nYour challenge environment is ready in the 'challenge/' directory." -ForegroundColor Cyan
Write-Host "`nThis module uses a CHECKPOINT SYSTEM:" -ForegroundColor Yellow
Write-Host " You'll work through 3 sections in one continuous repository:" -ForegroundColor White
Write-Host " 1. Branching Basics (checkpoint: start)" -ForegroundColor White
Write-Host " 2. Merging Branches (checkpoint: merge)" -ForegroundColor White
Write-Host " 3. Resolving Merge Conflicts (checkpoint: merge-conflict)" -ForegroundColor White
Write-Host "`nCommands:" -ForegroundColor Cyan
Write-Host " .\reset.ps1 - Show available checkpoints" -ForegroundColor White
Write-Host " .\reset.ps1 start - Jump to branching section" -ForegroundColor White
Write-Host " .\reset.ps1 merge - Jump to merging section" -ForegroundColor White
Write-Host " .\verify.ps1 - Verify all sections complete" -ForegroundColor White
Write-Host " .\verify.ps1 start - Verify only branching section" -ForegroundColor White
Write-Host "`nThe repository contains a realistic project history:" -ForegroundColor Yellow
Write-Host " - Multiple feature branches (login, api, database)" -ForegroundColor White
Write-Host " - All branches have been merged into main" -ForegroundColor White
Write-Host " - View the history: git log --oneline --graph --all" -ForegroundColor White
Write-Host "`nNext steps:" -ForegroundColor Cyan
Write-Host " 1. Read the README.md for detailed instructions" -ForegroundColor White
Write-Host " 2. cd challenge" -ForegroundColor White
Write-Host " 3. Start with Checkpoint 1: Branching Basics" -ForegroundColor White
Write-Host " 3. Explore the repository history: git log --oneline --graph --all" -ForegroundColor White
Write-Host " 4. Create your own branches and practice merging!" -ForegroundColor White
Write-Host ""