refactor: rename 01_essentials to 01-essentials
This commit is contained in:
225
01-essentials/02-history/README.md
Normal file
225
01-essentials/02-history/README.md
Normal file
@@ -0,0 +1,225 @@
|
||||
# Module 02: Viewing History
|
||||
|
||||
## Learning Objectives
|
||||
|
||||
In this module, you will:
|
||||
- Understand commit history and how to navigate it
|
||||
- Use `git log` to view commit history with various formats
|
||||
- Use `git show` to view specific commit details
|
||||
- Use `git diff` to compare changes between commits
|
||||
- Use `git diff --staged` to view changes ready to be committed
|
||||
- Understand commit hashes and references
|
||||
- Discover how `git diff` reveals changes not visible in current files
|
||||
|
||||
## Challenge
|
||||
|
||||
### Setup
|
||||
|
||||
Run the setup script to create your challenge environment:
|
||||
|
||||
```powershell
|
||||
.\setup.ps1
|
||||
```
|
||||
|
||||
This will create a `challenge/` directory with a Git repository that already has some commit history.
|
||||
|
||||
### Your Task
|
||||
|
||||
You'll explore an existing Git repository that contains multiple commits. Your goal is to use Git commands to discover information about the repository's history, including:
|
||||
- Viewing commit history
|
||||
- Examining changes between specific commits
|
||||
- Understanding staged changes
|
||||
- **Finding a secret code hidden in the commit history!** (Only discoverable by using `git diff`)
|
||||
|
||||
The setup script will create an `answers.md` file in the challenge directory with questions for you to answer. Fill in your answers directly in that file.
|
||||
|
||||
**Suggested Approach:**
|
||||
|
||||
1. Navigate to the challenge directory: `cd challenge`
|
||||
2. Open `answers.md` to see the questions
|
||||
3. View the commit history: `git log` or `git log --oneline`
|
||||
4. Check repository status: `git status`
|
||||
5. View staged changes: `git diff --staged`
|
||||
6. Try different log formats: `git log --stat`, `git log --graph`
|
||||
7. View specific commits: `git show <commit-hash>`
|
||||
8. Compare specific commits: `git diff <commit1> <commit2> <file>`
|
||||
9. Fill in your answers in `answers.md`
|
||||
|
||||
> **Important Notes:**
|
||||
> - You can use any Git commands you like to explore the repository
|
||||
> - Fill in your answers directly in the `answers.md` file (there are placeholder sections for each answer)
|
||||
> - Commit hashes can be referenced by their full hash or just the first 7 characters
|
||||
> - Notice that one file is already staged - use `git diff --staged` to see what it contains
|
||||
|
||||
## Key Concepts
|
||||
|
||||
- **Commit Hash**: A unique identifier (SHA-1 hash) for each commit. You can use the full hash or just the first few characters.
|
||||
- **Commit Message**: A description of what changed in that commit, written by the author.
|
||||
- **Commit History**: The chronological record of all changes made to a repository.
|
||||
- **HEAD**: A pointer to the current commit you're working from.
|
||||
- **Diff**: A view showing the differences between two versions of files.
|
||||
- **Staging Area**: Where changes wait before being committed. Use `git diff --staged` to see what's ready to commit.
|
||||
- **Working Directory vs Staged vs Committed**:
|
||||
- Working Directory: Files you're currently editing
|
||||
- Staged (Index): Changes marked for the next commit (via `git add`)
|
||||
- Committed: Changes permanently saved in history
|
||||
|
||||
## Understanding Diff Output
|
||||
|
||||
When you run `git diff` between commits, the output can look confusing at first. Here's how to read it:
|
||||
|
||||
### Example Diff Output
|
||||
|
||||
```diff
|
||||
diff --git a/app.py b/app.py
|
||||
index 1a2b3c4..5d6e7f8 100644
|
||||
--- a/app.py
|
||||
+++ b/app.py
|
||||
@@ -1,5 +1,7 @@
|
||||
# app.py - Main application file
|
||||
+from auth import login, logout
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
- # Application initialization code here
|
||||
+ login("user", "password")
|
||||
pass
|
||||
```
|
||||
|
||||
### Breaking It Down
|
||||
|
||||
**1. File Header**
|
||||
```diff
|
||||
diff --git a/app.py b/app.py
|
||||
```
|
||||
- Shows which file is being compared
|
||||
- `a/app.py` = old version (before)
|
||||
- `b/app.py` = new version (after)
|
||||
|
||||
**2. Metadata**
|
||||
```diff
|
||||
index 1a2b3c4..5d6e7f8 100644
|
||||
--- a/app.py
|
||||
+++ b/app.py
|
||||
```
|
||||
- `---` indicates the old version
|
||||
- `+++` indicates the new version
|
||||
- The hashes (1a2b3c4, 5d6e7f8) are internal Git identifiers
|
||||
|
||||
**3. Change Location (Hunk Header)**
|
||||
```diff
|
||||
@@ -1,5 +1,7 @@
|
||||
```
|
||||
- `@@ -1,5 +1,7 @@` tells you where changes occurred
|
||||
- `-1,5` = in the old file, starting at line 1, showing 5 lines
|
||||
- `+1,7` = in the new file, starting at line 1, showing 7 lines
|
||||
- The file grew by 2 lines (from 5 to 7)
|
||||
|
||||
**4. The Actual Changes**
|
||||
|
||||
Lines are prefixed with symbols:
|
||||
- ` ` (space) = unchanged line (context)
|
||||
- `-` (minus) = line removed from old version (shown in red in terminal)
|
||||
- `+` (plus) = line added in new version (shown in green in terminal)
|
||||
|
||||
In our example:
|
||||
```diff
|
||||
# app.py - Main application file ← unchanged
|
||||
+from auth import login, logout ← added (new)
|
||||
|
||||
def main(): ← unchanged
|
||||
print("Welcome to My App!") ← unchanged
|
||||
- # Application initialization code here ← removed (old)
|
||||
+ login("user", "password") ← added (new)
|
||||
pass ← unchanged
|
||||
```
|
||||
|
||||
### Reading Multiple Files
|
||||
|
||||
If multiple files changed, you'll see multiple diff sections:
|
||||
|
||||
```diff
|
||||
diff --git a/app.py b/app.py
|
||||
[changes to app.py]
|
||||
|
||||
diff --git a/auth.py b/auth.py
|
||||
[changes to auth.py]
|
||||
```
|
||||
|
||||
### Pro Tips
|
||||
|
||||
- **Context lines**: Unchanged lines around changes help you understand where the change happened
|
||||
- **Color coding**: In your terminal, deletions are usually red, additions are green
|
||||
- **No newline warning**: If you see `\ No newline at end of file`, it means the file doesn't end with a newline character (usually not important for beginners)
|
||||
- **Binary files**: For images or other binary files, Git just says "Binary files differ"
|
||||
|
||||
### Try It Yourself
|
||||
|
||||
In this module's challenge, you'll use:
|
||||
```bash
|
||||
# See what's staged for the next commit
|
||||
git diff --staged
|
||||
|
||||
# Compare changes between specific commits
|
||||
git diff <commit2> <commit4> app.py
|
||||
```
|
||||
|
||||
Pay attention to:
|
||||
- Which lines were added (green, with `+`)
|
||||
- Which lines were removed (red, with `-`)
|
||||
- The surrounding context (white, with space)
|
||||
- How `git diff --staged` shows only changes ready to commit
|
||||
|
||||
## Useful Commands
|
||||
|
||||
### Viewing History
|
||||
|
||||
```bash
|
||||
git log # View commit history
|
||||
git log --oneline # Compact one-line format
|
||||
git log --stat # Show files changed in each commit
|
||||
git log --graph # Show branch graph (more useful with branches)
|
||||
git show <commit> # View specific commit details
|
||||
git show <commit>:<file> # View a file from a specific commit
|
||||
```
|
||||
|
||||
### Comparing Changes with git diff
|
||||
|
||||
```bash
|
||||
# Compare commits
|
||||
git diff <commit1> <commit2> # Compare two commits
|
||||
git diff <commit1> <commit2> <file> # Compare specific file between commits
|
||||
git diff <commit> # Compare commit with current working directory
|
||||
|
||||
# Compare staged changes
|
||||
git diff --staged # Show changes in staging area (ready to commit)
|
||||
git diff --cached # Same as --staged (alternative syntax)
|
||||
git diff # Show unstaged changes in working directory
|
||||
git diff HEAD # Show all changes (staged + unstaged) vs last commit
|
||||
```
|
||||
|
||||
**When to use each `git diff` variant:**
|
||||
- `git diff` - See what you've changed but haven't staged yet
|
||||
- `git diff --staged` - Review what you're about to commit
|
||||
- `git diff HEAD` - See all your changes since the last commit
|
||||
- `git diff <commit1> <commit2>` - Compare any two points in history
|
||||
|
||||
## Verification
|
||||
|
||||
Once you've filled in your answers in `answers.md`, verify your solution:
|
||||
|
||||
```powershell
|
||||
.\verify.ps1
|
||||
```
|
||||
|
||||
The verification script will check that your answers contain the expected information.
|
||||
|
||||
## Need to Start Over?
|
||||
|
||||
If you want to reset the challenge and start fresh:
|
||||
|
||||
```powershell
|
||||
.\reset.ps1
|
||||
```
|
||||
|
||||
This will remove the challenge directory and run the setup script again, giving you a clean slate.
|
||||
26
01-essentials/02-history/reset.ps1
Normal file
26
01-essentials/02-history/reset.ps1
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Resets the Module 02 challenge environment.
|
||||
|
||||
.DESCRIPTION
|
||||
This script removes the existing challenge directory and runs
|
||||
the setup script again to create a fresh challenge environment.
|
||||
#>
|
||||
|
||||
Write-Host "`n=== Resetting Module 02 Challenge ===" -ForegroundColor Cyan
|
||||
|
||||
# Remove existing challenge directory if it exists
|
||||
if (Test-Path "challenge") {
|
||||
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
||||
Remove-Item -Recurse -Force "challenge"
|
||||
} else {
|
||||
Write-Host "No existing challenge directory found." -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "----------------------------------------" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Run setup script
|
||||
& "$PSScriptRoot\setup.ps1"
|
||||
367
01-essentials/02-history/setup.ps1
Normal file
367
01-essentials/02-history/setup.ps1
Normal file
@@ -0,0 +1,367 @@
|
||||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets up the Module 02 challenge environment with commit history.
|
||||
|
||||
.DESCRIPTION
|
||||
This script creates a challenge directory with a Git repository that
|
||||
contains multiple commits for students to explore using git log and git diff.
|
||||
#>
|
||||
|
||||
Write-Host "`n=== Setting up Module 02 Challenge ===" -ForegroundColor Cyan
|
||||
|
||||
# Remove existing challenge directory if it exists
|
||||
if (Test-Path "challenge") {
|
||||
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
||||
Remove-Item -Recurse -Force "challenge"
|
||||
}
|
||||
|
||||
# Create fresh challenge directory
|
||||
Write-Host "Creating challenge directory..." -ForegroundColor Green
|
||||
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
||||
Set-Location "challenge"
|
||||
|
||||
# Initialize Git repository
|
||||
Write-Host "Initializing Git repository..." -ForegroundColor Green
|
||||
git init | Out-Null
|
||||
|
||||
# Configure git for this repository
|
||||
git config user.name "Workshop Student"
|
||||
git config user.email "student@example.com"
|
||||
|
||||
# Commit 1: Initial project structure
|
||||
Write-Host "Creating initial project structure..." -ForegroundColor Green
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
# Application initialization code here
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Initial project structure" | Out-Null
|
||||
|
||||
# Commit 2: Add user authentication
|
||||
Write-Host "Adding user authentication..." -ForegroundColor Green
|
||||
$authContent = @"
|
||||
# auth.py - Authentication module
|
||||
|
||||
def login(username, password):
|
||||
# Authenticate user
|
||||
print(f"Logging in user: {username}")
|
||||
return True
|
||||
|
||||
def logout(username):
|
||||
# Log out user
|
||||
print(f"Logging out user: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "auth.py" -Value $authContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
# Application initialization code here
|
||||
login("user", "password")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add user authentication" | Out-Null
|
||||
|
||||
# Commit 3: Add database connection
|
||||
Write-Host "Adding database connection..." -ForegroundColor Green
|
||||
$databaseContent = @"
|
||||
# database.py - Database connection module
|
||||
# SECRET_CODE: UNICORN
|
||||
|
||||
def connect():
|
||||
# Connect to database
|
||||
print("Connecting to database...")
|
||||
return True
|
||||
|
||||
def disconnect():
|
||||
# Disconnect from database
|
||||
print("Disconnecting from database...")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "database.py" -Value $databaseContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
from database import connect, disconnect
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
connect()
|
||||
# Application initialization code here
|
||||
login("user", "password")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add database connection" | Out-Null
|
||||
|
||||
# Commit 4: Fix authentication bug
|
||||
Write-Host "Fixing authentication bug..." -ForegroundColor Green
|
||||
$authContent = @"
|
||||
# auth.py - Authentication module
|
||||
|
||||
def login(username, password):
|
||||
# Authenticate user
|
||||
if not username or not password:
|
||||
print("Error: Username and password required")
|
||||
return False
|
||||
print(f"Logging in user: {username}")
|
||||
return True
|
||||
|
||||
def logout(username):
|
||||
# Log out user
|
||||
print(f"Logging out user: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "auth.py" -Value $authContent
|
||||
|
||||
# Remove the secret code from database.py
|
||||
$databaseContent = @"
|
||||
# database.py - Database connection module
|
||||
|
||||
def connect():
|
||||
# Connect to database
|
||||
print("Connecting to database...")
|
||||
return True
|
||||
|
||||
def disconnect():
|
||||
# Disconnect from database
|
||||
print("Disconnecting from database...")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "database.py" -Value $databaseContent
|
||||
|
||||
git add .
|
||||
git commit -m "Fix authentication bug" | Out-Null
|
||||
|
||||
# Commit 5: Add user profile feature
|
||||
Write-Host "Adding user profile feature..." -ForegroundColor Green
|
||||
$profileContent = @"
|
||||
# profile.py - User profile module
|
||||
|
||||
def get_profile(username):
|
||||
# Get user profile
|
||||
print(f"Fetching profile for: {username}")
|
||||
return {"username": username, "email": f"{username}@example.com"}
|
||||
|
||||
def update_profile(username, data):
|
||||
# Update user profile
|
||||
print(f"Updating profile for: {username}")
|
||||
return True
|
||||
"@
|
||||
Set-Content -Path "profile.py" -Value $profileContent
|
||||
|
||||
$appContent = @"
|
||||
# app.py - Main application file
|
||||
from auth import login, logout
|
||||
from database import connect, disconnect
|
||||
from profile import get_profile
|
||||
|
||||
def main():
|
||||
print("Welcome to My App!")
|
||||
connect()
|
||||
# Application initialization code here
|
||||
if login("user", "password"):
|
||||
profile = get_profile("user")
|
||||
print(f"User profile: {profile}")
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
"@
|
||||
Set-Content -Path "app.py" -Value $appContent
|
||||
|
||||
git add .
|
||||
git commit -m "Add user profile feature" | Out-Null
|
||||
|
||||
# Create a staged change scenario
|
||||
Write-Host "Creating staged changes for exploration..." -ForegroundColor Green
|
||||
$configContent = @"
|
||||
# config.py - Configuration settings
|
||||
|
||||
DEBUG_MODE = False
|
||||
DATABASE_URL = "sqlite:///app.db"
|
||||
"@
|
||||
Set-Content -Path "config.py" -Value $configContent
|
||||
git add config.py
|
||||
|
||||
# Create answers.md template
|
||||
Write-Host "Creating answers.md template..." -ForegroundColor Green
|
||||
$answersTemplate = @"
|
||||
# Git History Exploration - Answers
|
||||
|
||||
Welcome! Answer the following questions by exploring the Git repository history using Git commands.
|
||||
|
||||
**Instructions:**
|
||||
- Replace the "Write your answer here" comments with your actual answers
|
||||
- You can use any Git commands to explore the repository
|
||||
- The hints section at the bottom provides helpful commands
|
||||
|
||||
---
|
||||
|
||||
## Question 1: How many commits are in the repository?
|
||||
|
||||
**Suggested commands:**
|
||||
``````bash
|
||||
git log --oneline
|
||||
# Or count them with:
|
||||
git rev-list --count HEAD
|
||||
``````
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
---
|
||||
|
||||
## Question 2: What was the commit message for the third commit?
|
||||
|
||||
**Note:** Count from the first/oldest commit (the one at the bottom of `git log`)
|
||||
|
||||
**Suggested commands:**
|
||||
``````bash
|
||||
git log --oneline --reverse # Shows oldest first
|
||||
git log # Shows newest first
|
||||
``````
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
---
|
||||
|
||||
## Question 3: Which files were modified in the "Fix authentication bug" commit?
|
||||
|
||||
**Note:** There are multiple files - list all of them!
|
||||
|
||||
**Suggested commands:**
|
||||
``````bash
|
||||
git log --stat # Shows files changed in each commit
|
||||
git show <commit-hash> --name-only # Shows only filenames for a commit
|
||||
``````
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here (list all files) -->
|
||||
|
||||
---
|
||||
|
||||
## Question 4: What new file is currently staged (ready to be committed)?
|
||||
|
||||
**Suggested commands:**
|
||||
``````bash
|
||||
git status # Shows staged, unstaged, and untracked files
|
||||
git diff --staged # Shows content of staged changes
|
||||
``````
|
||||
|
||||
**Your Answer:**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
---
|
||||
|
||||
## Question 5: Find the secret code hidden in the commit history! 🔍
|
||||
|
||||
**The Challenge:**
|
||||
A secret code was added in one commit and then removed in a later commit. It doesn't exist in the current files - you can ONLY find it by comparing commits with `git diff`.
|
||||
|
||||
**Hint:** The secret code is in `database.py` and exists in the third commit but was removed in the fourth commit.
|
||||
|
||||
**Suggested commands:**
|
||||
``````bash
|
||||
# First, get the commit hashes
|
||||
git log --oneline
|
||||
|
||||
# Then compare the third and fourth commits
|
||||
git diff <commit3-hash> <commit4-hash> database.py
|
||||
# Look for lines that were removed (marked with - in red)
|
||||
``````
|
||||
|
||||
**Your Answer (what is the secret code?):**
|
||||
|
||||
<!-- Write your answer here -->
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference - Useful Commands
|
||||
|
||||
**Viewing History:**
|
||||
``````bash
|
||||
git log # View commit history (newest first)
|
||||
git log --oneline # Compact one-line format
|
||||
git log --reverse # Show oldest commits first
|
||||
git log --stat # Show files changed in each commit
|
||||
git log --graph --all # Visual branch graph
|
||||
``````
|
||||
|
||||
**Viewing Specific Commits:**
|
||||
``````bash
|
||||
git show <commit-hash> # View commit details
|
||||
git show <commit-hash> --stat # Show files changed
|
||||
git show <commit-hash>:file.txt # View file from specific commit
|
||||
``````
|
||||
|
||||
**Comparing Changes:**
|
||||
``````bash
|
||||
git diff <commit1> <commit2> # Compare two commits
|
||||
git diff <commit1> <commit2> file # Compare specific file
|
||||
git diff --staged # Show staged changes
|
||||
git diff # Show unstaged changes
|
||||
git diff HEAD # Show all changes since last commit
|
||||
``````
|
||||
|
||||
**Repository Status:**
|
||||
``````bash
|
||||
git status # Show working tree status
|
||||
git ls-files # List all tracked files
|
||||
``````
|
||||
|
||||
**Pro Tip:** You can use just the first 7 characters of a commit hash (e.g., `a1b2c3d` instead of the full hash)
|
||||
|
||||
---
|
||||
|
||||
When you're done, run ``..\verify.ps1`` to check your answers!
|
||||
"@
|
||||
|
||||
Set-Content -Path "answers.md" -Value $answersTemplate
|
||||
|
||||
# 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 "`nNext steps:" -ForegroundColor Cyan
|
||||
Write-Host " 1. cd challenge" -ForegroundColor White
|
||||
Write-Host " 2. Open 'answers.md' to see the questions" -ForegroundColor White
|
||||
Write-Host " 3. Explore the commit history using 'git log'" -ForegroundColor White
|
||||
Write-Host " 4. Fill in your answers in 'answers.md'" -ForegroundColor White
|
||||
Write-Host " 5. Run '..\verify.ps1' to check your answers" -ForegroundColor White
|
||||
Write-Host ""
|
||||
120
01-essentials/02-history/verify.ps1
Normal file
120
01-essentials/02-history/verify.ps1
Normal file
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env pwsh
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Verifies the Module 02 challenge solution.
|
||||
|
||||
.DESCRIPTION
|
||||
This script checks that:
|
||||
- The challenge directory exists
|
||||
- A Git repository exists
|
||||
- answers.txt exists with correct information about commit history
|
||||
#>
|
||||
|
||||
Write-Host "`n=== Verifying Module 02 Solution ===" -ForegroundColor Cyan
|
||||
|
||||
$allChecksPassed = $true
|
||||
|
||||
# Check if challenge directory exists
|
||||
if (-not (Test-Path "challenge")) {
|
||||
Write-Host "[FAIL] Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Set-Location "challenge"
|
||||
|
||||
# Check if git repository exists
|
||||
if (-not (Test-Path ".git")) {
|
||||
Write-Host "[FAIL] Not a git repository. Did you run setup.ps1?" -ForegroundColor Red
|
||||
Set-Location ..
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Check if answers.md exists
|
||||
if (-not (Test-Path "answers.md")) {
|
||||
Write-Host "[FAIL] answers.md not found. Did you run setup.ps1?" -ForegroundColor Red
|
||||
Write-Host "[HINT] The setup script should have created answers.md for you" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
} else {
|
||||
Write-Host "[PASS] answers.md exists" -ForegroundColor Green
|
||||
|
||||
# Read the answers file
|
||||
$answers = Get-Content "answers.md" -Raw
|
||||
$answersLower = $answers.ToLower()
|
||||
|
||||
# Check 1: Contains "5" or "five" for commit count
|
||||
if ($answersLower -match "5|five") {
|
||||
Write-Host "[PASS] Correct commit count found" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check 2: Contains "database" keyword for third commit
|
||||
if ($answersLower -match "database") {
|
||||
Write-Host "[PASS] Third commit message identified" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] Third commit message not found" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use 'git log' to see commit messages in order" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check 3: Contains both "auth" and "database" keywords for files modified in bug fix
|
||||
$hasAuth = $answersLower -match "auth"
|
||||
$hasDatabase = $answersLower -match "database"
|
||||
|
||||
if ($hasAuth -and $hasDatabase) {
|
||||
Write-Host "[PASS] Both files identified for bug fix commit" -ForegroundColor Green
|
||||
} elseif ($hasAuth -or $hasDatabase) {
|
||||
Write-Host "[PARTIAL] Only one file found - there are TWO files modified in this commit" -ForegroundColor Yellow
|
||||
Write-Host "[HINT] Use 'git log --stat' or 'git show <commit-hash> --name-only' to see ALL files changed" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
} else {
|
||||
Write-Host "[FAIL] Files modified in bug fix commit not found" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check 4: Contains "config" keyword for staged file
|
||||
if ($answersLower -match "config") {
|
||||
Write-Host "[PASS] Staged file identified" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] Staged file not identified" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
# Check 5: Contains "unicorn" for the secret code
|
||||
if ($answersLower -match "unicorn") {
|
||||
Write-Host "[PASS] Secret code found!" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] Secret code not found" -ForegroundColor Red
|
||||
Write-Host "[HINT] Use 'git diff <commit3> <commit4> database.py' to find the secret code" -ForegroundColor Yellow
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Set-Location ..
|
||||
|
||||
# Final summary
|
||||
if ($allChecksPassed) {
|
||||
Write-Host "`n" -NoNewline
|
||||
Write-Host "=====================================" -ForegroundColor Green
|
||||
Write-Host " CONGRATULATIONS! CHALLENGE PASSED!" -ForegroundColor Green
|
||||
Write-Host "=====================================" -ForegroundColor Green
|
||||
Write-Host "`nYou've successfully explored Git commit history!" -ForegroundColor Cyan
|
||||
Write-Host "You now know how to:" -ForegroundColor Cyan
|
||||
Write-Host " - View commit history with git log" -ForegroundColor White
|
||||
Write-Host " - Find specific commits and their messages" -ForegroundColor White
|
||||
Write-Host " - See which files changed in commits" -ForegroundColor White
|
||||
Write-Host " - Check staged changes with git diff --staged" -ForegroundColor White
|
||||
Write-Host " - Compare changes between specific commits with git diff" -ForegroundColor White
|
||||
Write-Host "`nReady for the next module!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} else {
|
||||
Write-Host "`n[SUMMARY] Some checks failed. Review the hints above and try again." -ForegroundColor Red
|
||||
Write-Host "[INFO] You can run this verification script as many times as needed." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user