144 lines
4.1 KiB
PowerShell
144 lines
4.1 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 {
|
|
constructor(name, email) {
|
|
this.name = name;
|
|
this.email = email;
|
|
}
|
|
}
|
|
"@
|
|
|
|
Set-Content -Path "user-profile.js" -Value $userProfile
|
|
git add user-profile.js
|
|
git commit -m "WIP: user profile" | Out-Null
|
|
|
|
# Commit 2: Add validation (typo in message)
|
|
$userProfileWithValidation = @"
|
|
class UserProfile {
|
|
constructor(name, email) {
|
|
this.name = name;
|
|
this.email = email;
|
|
}
|
|
|
|
validate() {
|
|
if (!this.name || !this.email) {
|
|
throw new Error('Name and email are required');
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
"@
|
|
|
|
Set-Content -Path "user-profile.js" -Value $userProfileWithValidation
|
|
git add user-profile.js
|
|
git commit -m "add validaton" | Out-Null # Intentional typo
|
|
|
|
# Commit 3: Fix validation
|
|
$userProfileFixed = @"
|
|
class UserProfile {
|
|
constructor(name, email) {
|
|
this.name = name;
|
|
this.email = email;
|
|
}
|
|
|
|
validate() {
|
|
if (!this.name || !this.email) {
|
|
throw new Error('Name and email are required');
|
|
}
|
|
if (!this.email.includes('@')) {
|
|
throw new Error('Invalid email format');
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
"@
|
|
|
|
Set-Content -Path "user-profile.js" -Value $userProfileFixed
|
|
git add user-profile.js
|
|
git commit -m "fix validation bug" | Out-Null
|
|
|
|
# Commit 4: Add tests (another WIP commit)
|
|
$tests = @"
|
|
const assert = require('assert');
|
|
const UserProfile = require('./user-profile');
|
|
|
|
describe('UserProfile', () => {
|
|
it('should validate correct user data', () => {
|
|
const user = new UserProfile('John', 'john@example.com');
|
|
assert.strictEqual(user.validate(), true);
|
|
});
|
|
|
|
it('should reject missing name', () => {
|
|
const user = new UserProfile('', 'john@example.com');
|
|
assert.throws(() => user.validate());
|
|
});
|
|
|
|
it('should reject invalid email', () => {
|
|
const user = new UserProfile('John', 'invalid-email');
|
|
assert.throws(() => user.validate());
|
|
});
|
|
});
|
|
"@
|
|
|
|
Set-Content -Path "user-profile.test.js" -Value $tests
|
|
git add user-profile.test.js
|
|
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
|