175 lines
6.5 KiB
PowerShell
175 lines
6.5 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Verifies the remotes challenge solution.
|
|
|
|
.DESCRIPTION
|
|
Checks that the user successfully cloned the repository, worked with
|
|
remotes, pushed branches, and synchronized changes.
|
|
#>
|
|
|
|
Set-Location "challenge" -ErrorAction SilentlyContinue
|
|
|
|
# Check if challenge directory exists
|
|
if (-not (Test-Path "../verify.ps1")) {
|
|
Write-Host "Error: Please run this script from the module directory" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
if (-not (Test-Path ".")) {
|
|
Write-Host "Error: Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
|
Set-Location ..
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "Verifying your solution..." -ForegroundColor Cyan
|
|
|
|
# Check if local-repo exists
|
|
if (-not (Test-Path "local-repo")) {
|
|
Write-Host "[FAIL] local-repo directory not found." -ForegroundColor Red
|
|
Write-Host "Hint: Clone the remote repository with: git clone remote-repo local-repo" -ForegroundColor Yellow
|
|
Set-Location ..
|
|
exit 1
|
|
}
|
|
|
|
Set-Location "local-repo"
|
|
|
|
# Check if it's a git repository
|
|
if (-not (Test-Path ".git")) {
|
|
Write-Host "[FAIL] local-repo is not a git repository." -ForegroundColor Red
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
# Check if remote 'origin' is configured
|
|
$remotes = git remote 2>$null
|
|
if ($remotes -notcontains "origin") {
|
|
Write-Host "[FAIL] No remote named 'origin' found." -ForegroundColor Red
|
|
Write-Host "Hint: Cloning should automatically set up 'origin' as the remote" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
# Check if origin points to the remote-repo
|
|
$originUrl = git remote get-url origin 2>$null
|
|
if ($originUrl -notmatch "remote-repo") {
|
|
Write-Host "[FAIL] Origin remote does not point to remote-repo." -ForegroundColor Red
|
|
Write-Host "Origin URL: $originUrl" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "[PASS] Repository cloned correctly with origin remote!" -ForegroundColor Green
|
|
|
|
# Check if add-feature branch exists locally
|
|
$branches = git branch 2>$null
|
|
if ($branches -notmatch "add-feature") {
|
|
Write-Host "[FAIL] add-feature branch not found locally." -ForegroundColor Red
|
|
Write-Host "Hint: Create the branch with: git checkout -b add-feature" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
# Switch to add-feature branch
|
|
git checkout add-feature 2>$null | Out-Null
|
|
|
|
# Check if there are commits on add-feature beyond the initial commits
|
|
$featureCommitCount = (git rev-list --count add-feature 2>$null)
|
|
$mainCommitCount = (git rev-list --count main 2>$null)
|
|
|
|
if ($featureCommitCount -le $mainCommitCount) {
|
|
Write-Host "[FAIL] add-feature branch has no new commits." -ForegroundColor Red
|
|
Write-Host "Hint: Make changes to app.py and commit them on the add-feature branch" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "[PASS] Feature branch created with commits!" -ForegroundColor Green
|
|
|
|
# Check if add-feature branch was pushed to remote
|
|
Set-Location ..
|
|
Set-Location remote-repo
|
|
|
|
$remoteBranches = git branch 2>$null
|
|
if ($remoteBranches -notmatch "add-feature") {
|
|
Write-Host "[FAIL] add-feature branch not found on remote." -ForegroundColor Red
|
|
Write-Host "Hint: Push your branch with: git push -u origin add-feature" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "[PASS] Feature branch pushed to remote!" -ForegroundColor Green
|
|
|
|
Set-Location ../local-repo
|
|
|
|
# Check if app.py has been modified
|
|
if (-not (Test-Path "app.py")) {
|
|
Write-Host "[FAIL] app.py not found." -ForegroundColor Red
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
$appContent = Get-Content "app.py" -Raw
|
|
|
|
# Check for user's changes (should have added something)
|
|
$featureCommits = git log --pretty=format:"%s" add-feature 2>$null
|
|
if (-not ($featureCommits -match "stop|feature|add" -or $appContent -match "stop")) {
|
|
Write-Host "[FAIL] No new feature detected in app.py." -ForegroundColor Red
|
|
Write-Host "Hint: Add a new method (like 'stop') to app.py and commit it" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
# Check if teammate changes were fetched and merged
|
|
# The teammate's change adds an 'initialize' method
|
|
if ($appContent -notmatch "initialize") {
|
|
Write-Host "[FAIL] Teammate's changes not merged into your branch." -ForegroundColor Red
|
|
Write-Host "Hint: Did you run the simulate-teammate.ps1 script?" -ForegroundColor Yellow
|
|
Write-Host " Then: git fetch origin" -ForegroundColor Yellow
|
|
Write-Host " git merge origin/main" -ForegroundColor Yellow
|
|
Set-Location ../..
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "[PASS] Remote changes fetched and merged!" -ForegroundColor Green
|
|
|
|
# Check that the branch has both sets of changes
|
|
$allCommits = git log --all --pretty=format:"%s" 2>$null
|
|
$hasUserCommit = $allCommits -match "stop|feature|add"
|
|
$hasTeammateCommit = $allCommits -match "initialization|initialize"
|
|
|
|
if (-not $hasTeammateCommit) {
|
|
Write-Host "[WARNING] Teammate commit not found in history." -ForegroundColor Yellow
|
|
Write-Host "Make sure you ran simulate-teammate.ps1 and fetched the changes" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Check for remote tracking
|
|
$tracking = git branch -vv 2>$null
|
|
if ($tracking -notmatch "origin/add-feature") {
|
|
Write-Host "[WARNING] add-feature branch may not be tracking origin/add-feature" -ForegroundColor Yellow
|
|
Write-Host "Hint: Use 'git push -u origin add-feature' to set up tracking" -ForegroundColor Yellow
|
|
}
|
|
|
|
# Success!
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "SUCCESS! Challenge completed!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "`nYou have successfully:" -ForegroundColor Cyan
|
|
Write-Host "- Cloned the remote repository" -ForegroundColor White
|
|
Write-Host "- Created a feature branch" -ForegroundColor White
|
|
Write-Host "- Made commits to your branch" -ForegroundColor White
|
|
Write-Host "- Pushed your branch to the remote" -ForegroundColor White
|
|
Write-Host "- Fetched changes from the remote" -ForegroundColor White
|
|
Write-Host "- Merged remote changes into your branch" -ForegroundColor White
|
|
Write-Host "`nYou now understand how to work with Git remotes!" -ForegroundColor Green
|
|
Write-Host "`nKey takeaways:" -ForegroundColor Yellow
|
|
Write-Host "- Clone creates a local copy linked to the remote" -ForegroundColor White
|
|
Write-Host "- Push uploads your commits to the remote" -ForegroundColor White
|
|
Write-Host "- Fetch downloads remote changes without merging" -ForegroundColor White
|
|
Write-Host "- Pull = Fetch + Merge" -ForegroundColor White
|
|
Write-Host "`nThese skills are essential for team collaboration!`n" -ForegroundColor Green
|
|
|
|
Set-Location ../..
|
|
exit 0
|