refactor: move modules into levels
This commit is contained in:
111
01_essentials/01-basics/README.md
Normal file
111
01_essentials/01-basics/README.md
Normal file
@@ -0,0 +1,111 @@
|
||||
# Module 01: Git Basics
|
||||
|
||||
## Learning Objectives
|
||||
|
||||
- Understand what a git repository is
|
||||
- Learn the basic git workflow: modify → stage → commit
|
||||
- Use `git status` to check repository state
|
||||
- Use `git add` to stage changes
|
||||
- Use `git commit` to save changes
|
||||
|
||||
## Challenge
|
||||
|
||||
In this challenge, you'll learn the fundamental git workflow.
|
||||
|
||||
### Setup
|
||||
|
||||
Run the setup script to prepare the challenge:
|
||||
|
||||
```powershell
|
||||
.\setup.ps1
|
||||
```
|
||||
|
||||
This will create a directory called `challenge` with some files that need to be committed.
|
||||
|
||||
### 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`
|
||||
2. **Initialize a new git repository**: `git init` (this is your first step!)
|
||||
3. Check the status of your repository: `git status`
|
||||
4. Stage the files you want to commit: `git add welcome.txt` (or `git add .` to stage all files)
|
||||
5. Create a commit: `git commit -m "Your commit message"`
|
||||
6. Verify both files are committed: `git ls-tree -r HEAD --name-only`
|
||||
|
||||
**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
|
||||
|
||||
- **Repository**: A directory tracked by git, containing your project files and their history
|
||||
- **Working Directory**: The files you see and edit
|
||||
- **Staging Area (Index)**: A preparation area for your next commit
|
||||
- **Commit**: A snapshot of your staged changes
|
||||
|
||||
### Useful Commands
|
||||
|
||||
```bash
|
||||
git init # Initialize a new git repository
|
||||
git status # Show the working tree status
|
||||
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 ls-tree -r HEAD --name-only # List all files in the latest commit
|
||||
git log # View commit history
|
||||
```
|
||||
|
||||
### Verification
|
||||
|
||||
Once you think you've completed the challenge, run the verification script.
|
||||
|
||||
**Important:** Run this from the **module directory**, not the challenge directory.
|
||||
|
||||
```powershell
|
||||
# If you're in the challenge directory, go back up:
|
||||
cd ..
|
||||
|
||||
# Then verify:
|
||||
.\verify.ps1
|
||||
```
|
||||
|
||||
This will check if you've successfully completed all the steps.
|
||||
|
||||
### Troubleshooting
|
||||
|
||||
**Error: "fatal: unable to auto-detect email address"**
|
||||
|
||||
This means Git doesn't know who you are yet. You need to configure your name and email:
|
||||
|
||||
```powershell
|
||||
git config user.name "Your Name"
|
||||
git config user.email "your.email@example.com"
|
||||
```
|
||||
|
||||
Then try your commit again. For more details, see the "Requirements" section in the main README.md.
|
||||
|
||||
**Error: "Not a git repository"**
|
||||
|
||||
Make sure you ran `git init` in the challenge directory. This creates a hidden `.git` folder that tracks your project.
|
||||
|
||||
**Can't find the challenge directory?**
|
||||
|
||||
Make sure you ran `.\setup.ps1` first from the module directory. This creates the `challenge/` folder.
|
||||
|
||||
**Where am I?**
|
||||
|
||||
Use `pwd` (Print Working Directory) to see your current location:
|
||||
- If you're in something like `.../module-01-basics/challenge`, you're in the challenge directory
|
||||
- If you're in something like `.../module-01-basics`, you're in the module directory
|
||||
|
||||
### 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.
|
||||
29
01_essentials/01-basics/reset.ps1
Normal file
29
01_essentials/01-basics/reset.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Resets the Module 01 challenge environment.
|
||||
|
||||
.DESCRIPTION
|
||||
Removes the existing challenge directory and runs setup.ps1 to create a fresh challenge.
|
||||
This is useful if you want to start over from scratch.
|
||||
#>
|
||||
|
||||
Write-Host "Resetting Module 01: Git Basics Challenge..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Remove existing challenge directory if it exists
|
||||
if (Test-Path "challenge") {
|
||||
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
||||
Remove-Item -Path "challenge" -Recurse -Force
|
||||
Write-Host "[SUCCESS] Challenge directory removed" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[INFO] No existing challenge directory found" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Running setup script..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Run the setup script
|
||||
& "$PSScriptRoot/setup.ps1"
|
||||
64
01_essentials/01-basics/setup.ps1
Normal file
64
01_essentials/01-basics/setup.ps1
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets up the Module 01 challenge environment.
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a challenge directory with files that need to be committed to git.
|
||||
The student will need to initialize the repository and make commits.
|
||||
#>
|
||||
|
||||
Write-Host "Setting up Module 01: Git Basics Challenge..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Remove existing challenge directory if it exists
|
||||
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 directory..." -ForegroundColor Green
|
||||
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
||||
|
||||
# Create welcome.txt
|
||||
$welcomeContent = @"
|
||||
Welcome to Git Workshop!
|
||||
|
||||
This is your first challenge. You'll learn the basics of git:
|
||||
- Initializing a repository
|
||||
- Staging changes
|
||||
- Creating commits
|
||||
|
||||
Good luck!
|
||||
"@
|
||||
|
||||
Set-Content -Path "challenge/welcome.txt" -Value $welcomeContent
|
||||
|
||||
# Create instructions.txt
|
||||
$instructionsContent = @"
|
||||
Git Basics Instructions
|
||||
========================
|
||||
|
||||
The basic git workflow follows these steps:
|
||||
|
||||
1. Make changes to files in your working directory
|
||||
2. Stage the changes you want to commit (git add)
|
||||
3. Commit the staged changes with a message (git commit)
|
||||
|
||||
This workflow allows you to carefully select which changes
|
||||
to include in each commit, making your history clean and meaningful.
|
||||
"@
|
||||
|
||||
Set-Content -Path "challenge/instructions.txt" -Value $instructionsContent
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Setup complete!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Next steps:" -ForegroundColor Cyan
|
||||
Write-Host " 1. cd challenge"
|
||||
Write-Host " 2. Read the README.md in the parent directory"
|
||||
Write-Host " 3. Complete the challenge"
|
||||
Write-Host " 4. Run ../verify.ps1 to check your solution"
|
||||
Write-Host ""
|
||||
90
01_essentials/01-basics/verify.ps1
Normal file
90
01_essentials/01-basics/verify.ps1
Normal file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Verifies the Module 01 challenge solution.
|
||||
|
||||
.DESCRIPTION
|
||||
Checks if the student has correctly:
|
||||
- Initialized a git repository
|
||||
- Created at least one commit
|
||||
- Committed both required files (welcome.txt and instructions.txt)
|
||||
#>
|
||||
|
||||
Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
$allChecksPassed = $true
|
||||
|
||||
# Check if challenge directory exists
|
||||
if (-not (Test-Path "challenge")) {
|
||||
Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
Set-Location "challenge"
|
||||
|
||||
# Check if git repository exists
|
||||
if (-not (Test-Path ".git")) {
|
||||
Write-Host "[FAIL] No git repository found. Did you run 'git init'?" -ForegroundColor Red
|
||||
Set-Location ".."
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "[PASS] Git repository initialized" -ForegroundColor Green
|
||||
|
||||
# Check if there are any commits
|
||||
$commitCount = (git rev-list --all --count 2>$null)
|
||||
if ($null -eq $commitCount -or $commitCount -eq 0) {
|
||||
Write-Host "[FAIL] No commits found. Have you committed your changes?" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
} else {
|
||||
Write-Host "[PASS] Found $commitCount commit(s)" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Check if both files are in the git history using git ls-tree
|
||||
if ($commitCount -gt 0) {
|
||||
$trackedFiles = git ls-tree -r HEAD --name-only 2>$null
|
||||
|
||||
if ($trackedFiles -match "welcome.txt") {
|
||||
Write-Host "[PASS] welcome.txt is committed" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] welcome.txt is not in the commit history" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
|
||||
if ($trackedFiles -match "instructions.txt") {
|
||||
Write-Host "[PASS] instructions.txt is committed" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "[FAIL] instructions.txt is not in the commit history" -ForegroundColor Red
|
||||
$allChecksPassed = $false
|
||||
}
|
||||
}
|
||||
|
||||
# Check for uncommitted changes
|
||||
$statusOutput = git status --porcelain 2>$null
|
||||
if ($statusOutput) {
|
||||
Write-Host "[INFO] You have uncommitted changes. This is OK, but make sure all required files are committed." -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Set-Location ".."
|
||||
|
||||
Write-Host ""
|
||||
if ($allChecksPassed) {
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host " CONGRATULATIONS! Challenge Complete! " -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "You've mastered the basics of git!" -ForegroundColor Cyan
|
||||
Write-Host "You can now move on to Module 02." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
} else {
|
||||
Write-Host "========================================" -ForegroundColor Red
|
||||
Write-Host " Challenge Not Complete - Try Again! " -ForegroundColor Red
|
||||
Write-Host "========================================" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Write-Host "Review the errors above and try again." -ForegroundColor Yellow
|
||||
Write-Host "Hint: Check 'git log' and 'git status' to see what you've done." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user