seed: curriculum content
This commit is contained in:
40
1.solar-system/1.welcome/14.the-historian/index.md
Normal file
40
1.solar-system/1.welcome/14.the-historian/index.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
type: challenge
|
||||
title: "The Historian"
|
||||
xp: 75
|
||||
duration: 25
|
||||
difficulty: 3
|
||||
---
|
||||
|
||||
# The Historian
|
||||
|
||||
> **[INCOMING — Mission Control, Earth]**
|
||||
>
|
||||
> Cadet, the repo in your working directory contains five commits
|
||||
> from a previous mission. We need a historian's eye on it.
|
||||
>
|
||||
> Two commands today:
|
||||
>
|
||||
> - `git log --oneline` — compact one-line-per-commit history
|
||||
> - `git show <hash>` — show what a commit changed
|
||||
>
|
||||
> Your script must produce two files:
|
||||
>
|
||||
> 1. `log.txt` — full one-line log
|
||||
> 2. `breach-commit.txt` — short hash of the commit whose message
|
||||
> mentions `BREACH`
|
||||
>
|
||||
> Hint: pipe the log through `grep BREACH | awk '{print $1}'` to
|
||||
> extract the short hash from the matching line.
|
||||
>
|
||||
> [END TRANSMISSION]
|
||||
|
||||
## Your Task
|
||||
|
||||
In `starter/starter.sh`, capture the full log and the breach commit's
|
||||
short hash.
|
||||
|
||||
## Objectives
|
||||
|
||||
- `log.txt` lists all 5 commits, one per line
|
||||
- `breach-commit.txt` contains the short hash of the BREACH commit
|
||||
15
1.solar-system/1.welcome/14.the-historian/starter/starter.sh
Normal file
15
1.solar-system/1.welcome/14.the-historian/starter/starter.sh
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
# The Historian — read git history.
|
||||
#
|
||||
# When this script runs, the current Git repo already has 5 commits
|
||||
# from a prior mission. One of them mentions BREACH.
|
||||
#
|
||||
# Your script must produce two files:
|
||||
# - log.txt — `git log --oneline` output (one line per commit)
|
||||
# - breach-commit.txt — the short hash of the BREACH commit
|
||||
#
|
||||
# Hint: `git log --oneline | grep BREACH | awk '{print $1}'`
|
||||
# pipes the matching log line and prints the leftmost column (the
|
||||
# short hash).
|
||||
|
||||
# Your code here.
|
||||
24
1.solar-system/1.welcome/14.the-historian/testing/test.sh
Normal file
24
1.solar-system/1.welcome/14.the-historian/testing/test.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
git init -q -b main
|
||||
git config user.name "Setup"
|
||||
git config user.email "setup@learnroom.local"
|
||||
|
||||
echo "manifest" > manifest.txt; git add manifest.txt; git commit -q -m "add manifest"
|
||||
echo "sensor a online" > sensor-a.txt; git add sensor-a.txt; git commit -q -m "add sensor A"
|
||||
echo "breach details" > breach.txt; git add breach.txt; git commit -q -m "investigate BREACH at sector C"
|
||||
echo "sensor b online" > sensor-b.txt; git add sensor-b.txt; git commit -q -m "add sensor B"
|
||||
echo "resolution applied" > resolution.txt; git add resolution.txt; git commit -q -m "apply resolution"
|
||||
|
||||
bash solution.sh > /dev/null 2>&1
|
||||
|
||||
N=0
|
||||
report() { N=$((N+1)); if [ "$1" = "0" ]; then echo "ok $N - $2"; else echo "not ok $N - $2"; fi; }
|
||||
|
||||
[ -f log.txt ]; report $? "log.txt exists"
|
||||
LINES=$(wc -l < log.txt | tr -d ' ')
|
||||
[ "$LINES" = "5" ]; report $? "log.txt has 5 lines (one per commit)"
|
||||
|
||||
[ -f breach-commit.txt ]; report $? "breach-commit.txt exists"
|
||||
ACTUAL=$(tr -d '[:space:]' < breach-commit.txt 2>/dev/null)
|
||||
EXPECTED=$(git log --grep BREACH --format=%h)
|
||||
[ "$ACTUAL" = "$EXPECTED" ]; report $? "breach-commit.txt contains the BREACH commit's short hash"
|
||||
Reference in New Issue
Block a user