fix: simplify verification for module 1

This commit is contained in:
Bjarke Sporring
2026-01-04 15:25:52 +01:00
parent 2b3ea7ed36
commit 4a47d8b36e
2 changed files with 51 additions and 54 deletions

View File

@@ -24,15 +24,19 @@ This will create a directory called `challenge` with some files that need to be
### Your Task ### Your Task
Your goal is to commit both `welcome.txt` and `instructions.txt` to a git repository. Here's a suggested approach:
1. Navigate into the `challenge` directory: `cd challenge` 1. Navigate into the `challenge` directory: `cd challenge`
2. **Initialize a new git repository**: `git init` (this is your first step!) 2. **Initialize a new git repository**: `git init` (this is your first step!)
3. Check the status of your repository: `git status` 3. Check the status of your repository: `git status`
4. Stage the file `welcome.txt`: `git add welcome.txt` 4. Stage the files you want to commit: `git add welcome.txt` (or `git add .` to stage all files)
5. Create a commit with the message "Add welcome file": `git commit -m "Add welcome file"` 5. Create a commit: `git commit -m "Your commit message"`
6. Stage the file `instructions.txt`: `git add instructions.txt` 6. Verify both files are committed: `git ls-tree -r HEAD --name-only`
7. Create a commit with the message "Add instructions": `git commit -m "Add instructions"`
**Note**: The challenge directory is NOT a git repository until you run `git init`. This is intentional - you're learning to start from scratch! **Important Notes**:
- The challenge directory is NOT a git repository until you run `git init`. This is intentional - you're learning to start from scratch!
- You can commit both files together in one commit, or separately in multiple commits - it's up to you!
- The verification script checks that both files are committed, not the specific commit messages or order
### Key Concepts ### Key Concepts
@@ -46,8 +50,11 @@ This will create a directory called `challenge` with some files that need to be
```bash ```bash
git init # Initialize a new git repository git init # Initialize a new git repository
git status # Show the working tree status git status # Show the working tree status
git add <file> # Stage a file for commit git add <file> # Stage a specific file for commit
git add . # Stage all files in current directory
git commit -m "<message>" # Create a commit with a message git commit -m "<message>" # Create a commit with a message
git ls-tree -r HEAD --name-only # List all files in the latest commit
git log # View commit history
``` ```
### Verification ### Verification
@@ -59,3 +66,13 @@ Once you think you've completed the challenge, run:
``` ```
This will check if you've successfully completed all the steps. This will check if you've successfully completed all the steps.
### Need to Start Over?
If you want to reset the challenge and start fresh, run:
```powershell
.\reset.ps1
```
This will remove your challenge directory and set up a new one.

View File

@@ -7,8 +7,8 @@
.DESCRIPTION .DESCRIPTION
Checks if the student has correctly: Checks if the student has correctly:
- Initialized a git repository - Initialized a git repository
- Created two commits with the correct messages - Created at least one commit
- Committed the correct files - Committed both required files (welcome.txt and instructions.txt)
#> #>
Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan
@@ -33,58 +33,38 @@ if (-not (Test-Path ".git")) {
Write-Host "[PASS] Git repository initialized" -ForegroundColor Green Write-Host "[PASS] Git repository initialized" -ForegroundColor Green
# Check number of commits # Check if there are any commits
$commitCount = (git rev-list --all --count 2>$null) $commitCount = (git rev-list --all --count 2>$null)
if ($commitCount -ne 2) { if ($null -eq $commitCount -or $commitCount -eq 0) {
Write-Host "[FAIL] Expected 2 commits, found $commitCount" -ForegroundColor Red Write-Host "[FAIL] No commits found. Have you committed your changes?" -ForegroundColor Red
$allChecksPassed = $false $allChecksPassed = $false
} else { } else {
Write-Host "[PASS] Correct number of commits (2)" -ForegroundColor Green Write-Host "[PASS] Found $commitCount commit(s)" -ForegroundColor Green
} }
# Get commit messages (newest first) # Check if both files are in the git history using git ls-tree
$commits = git log --pretty=format:"%s" --reverse 2>$null if ($commitCount -gt 0) {
$trackedFiles = git ls-tree -r HEAD --name-only 2>$null
if ($commits) { if ($trackedFiles -match "welcome.txt") {
$commitArray = $commits -split "`n" Write-Host "[PASS] welcome.txt is committed" -ForegroundColor Green
# Check first commit
if ($commitArray.Count -ge 1) {
if ($commitArray[0] -eq "Add welcome file") {
Write-Host "[PASS] First commit message correct" -ForegroundColor Green
} else { } else {
Write-Host "[FAIL] First commit message incorrect. Expected 'Add welcome file', got '$($commitArray[0])'" -ForegroundColor Red Write-Host "[FAIL] welcome.txt is not in the commit history" -ForegroundColor Red
$allChecksPassed = $false $allChecksPassed = $false
} }
# Check files in first commit if ($trackedFiles -match "instructions.txt") {
$filesInFirstCommit = git diff-tree --no-commit-id --name-only -r HEAD~1 2>$null Write-Host "[PASS] instructions.txt is committed" -ForegroundColor Green
if ($filesInFirstCommit -match "welcome.txt") {
Write-Host "[PASS] First commit contains welcome.txt" -ForegroundColor Green
} else { } else {
Write-Host "[FAIL] First commit should contain welcome.txt" -ForegroundColor Red Write-Host "[FAIL] instructions.txt is not in the commit history" -ForegroundColor Red
$allChecksPassed = $false $allChecksPassed = $false
} }
} }
# Check second commit # Check for uncommitted changes
if ($commitArray.Count -ge 2) { $statusOutput = git status --porcelain 2>$null
if ($commitArray[1] -eq "Add instructions") { if ($statusOutput) {
Write-Host "[PASS] Second commit message correct" -ForegroundColor Green Write-Host "[INFO] You have uncommitted changes. This is OK, but make sure all required files are committed." -ForegroundColor Yellow
} else {
Write-Host "[FAIL] Second commit message incorrect. Expected 'Add instructions', got '$($commitArray[1])'" -ForegroundColor Red
$allChecksPassed = $false
}
# Check files in second commit
$filesInSecondCommit = git diff-tree --no-commit-id --name-only -r HEAD 2>$null
if ($filesInSecondCommit -match "instructions.txt") {
Write-Host "[PASS] Second commit contains instructions.txt" -ForegroundColor Green
} else {
Write-Host "[FAIL] Second commit should contain instructions.txt" -ForegroundColor Red
$allChecksPassed = $false
}
}
} }
Set-Location ".." Set-Location ".."