134 lines
4.2 KiB
PowerShell
134 lines
4.2 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the interactive rebase challenge environment.
|
|
|
|
.DESCRIPTION
|
|
Creates a Git repository with messy commit history that needs to be
|
|
cleaned up using reset and recommit techniques.
|
|
#>
|
|
|
|
# Remove existing challenge directory if present
|
|
if (Test-Path "challenge") {
|
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
|
Remove-Item -Path "challenge" -Recurse -Force
|
|
}
|
|
|
|
# Create challenge directory
|
|
Write-Host "Creating challenge environment..." -ForegroundColor Cyan
|
|
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
|
Set-Location "challenge"
|
|
|
|
# Initialize git repository
|
|
git init | Out-Null
|
|
git config user.name "Workshop User" | Out-Null
|
|
git config user.email "user@workshop.local" | Out-Null
|
|
|
|
# Create initial commit
|
|
$readme = @"
|
|
# User Management System
|
|
|
|
A simple user management application.
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $readme
|
|
git add README.md
|
|
git commit -m "Initial commit" | Out-Null
|
|
|
|
# Create messy commits that should be squashed
|
|
|
|
# Commit 1: WIP user profile
|
|
$userProfile = @"
|
|
class UserProfile:
|
|
def __init__(self, name, email):
|
|
self.name = name
|
|
self.email = email
|
|
"@
|
|
|
|
Set-Content -Path "user_profile.py" -Value $userProfile
|
|
git add user_profile.py
|
|
git commit -m "WIP: user profile" | Out-Null
|
|
|
|
# Commit 2: Add validation (typo in message)
|
|
$userProfileWithValidation = @"
|
|
class UserProfile:
|
|
def __init__(self, name, email):
|
|
self.name = name
|
|
self.email = email
|
|
|
|
def validate(self):
|
|
if not self.name or not self.email:
|
|
raise ValueError('Name and email are required')
|
|
return True
|
|
"@
|
|
|
|
Set-Content -Path "user_profile.py" -Value $userProfileWithValidation
|
|
git add user_profile.py
|
|
git commit -m "add validaton" | Out-Null # Intentional typo
|
|
|
|
# Commit 3: Fix validation
|
|
$userProfileFixed = @"
|
|
class UserProfile:
|
|
def __init__(self, name, email):
|
|
self.name = name
|
|
self.email = email
|
|
|
|
def validate(self):
|
|
if not self.name or not self.email:
|
|
raise ValueError('Name and email are required')
|
|
if '@' not in self.email:
|
|
raise ValueError('Invalid email format')
|
|
return True
|
|
"@
|
|
|
|
Set-Content -Path "user_profile.py" -Value $userProfileFixed
|
|
git add user_profile.py
|
|
git commit -m "fix validation bug" | Out-Null
|
|
|
|
# Commit 4: Add tests (another WIP commit)
|
|
$tests = @"
|
|
import unittest
|
|
from user_profile import UserProfile
|
|
|
|
class TestUserProfile(unittest.TestCase):
|
|
def test_validate_correct_user_data(self):
|
|
user = UserProfile('John', 'john@example.com')
|
|
self.assertTrue(user.validate())
|
|
|
|
def test_reject_missing_name(self):
|
|
user = UserProfile('', 'john@example.com')
|
|
with self.assertRaises(ValueError):
|
|
user.validate()
|
|
|
|
def test_reject_invalid_email(self):
|
|
user = UserProfile('John', 'invalid-email')
|
|
with self.assertRaises(ValueError):
|
|
user.validate()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|
|
"@
|
|
|
|
Set-Content -Path "test_user_profile.py" -Value $tests
|
|
git add test_user_profile.py
|
|
git commit -m "WIP tests" | Out-Null
|
|
|
|
# Return to module directory
|
|
Set-Location ..
|
|
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "Challenge environment created!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "`nYou have a repository with messy commit history:" -ForegroundColor Cyan
|
|
Write-Host "- WIP commits" -ForegroundColor Yellow
|
|
Write-Host "- Typos in commit messages" -ForegroundColor Yellow
|
|
Write-Host "- Multiple commits that should be combined" -ForegroundColor Yellow
|
|
Write-Host "`nYour task:" -ForegroundColor Yellow
|
|
Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundColor White
|
|
Write-Host "2. View the messy history: git log --oneline" -ForegroundColor White
|
|
Write-Host "3. Use 'git reset --soft HEAD~4' to uncommit the last 4 commits" -ForegroundColor White
|
|
Write-Host "4. Create a single clean commit with a descriptive message" -ForegroundColor White
|
|
Write-Host " Example: git commit -m 'Add user profile feature with validation'" -ForegroundColor White
|
|
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan
|