Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
# exercises

## Git-Mastery exercise structure

When you download an exercise, you will get the following folder structure:


## `.gitmastery-exercise.json`

Configuration fields for each exercise:

1. `exercise_name`: name of exercise
2. `tags`: list of tags for exercise
3. `requires_git`: downloading the exercise will check that Git is installed and that `git config` is already done
4. `requires_github`: downloading the exercise will check that Github and Github CLI is installed
5. `base_files`: provides the files to be included outside of the repository, along with `.gitmastery-exercise.json` and `README.md`, most often used for `answers.txt`
6. `exercise_repo`: configuration for what the exercise repository would look like
1. `repo_type`: `local` (creates and initializes the folder as a Git repository) or `remote` (reference a repository on Github)
2. `repo_name`: name of repository during cloning
3. `repo_title`: (only read if `link` is present) link of repository on Github
4. `create_fork`: (only read if `link` is present) flag to determine if we need to fork the repository to the student's machine, otherwise it just clones the repository
5. `init`: (only read if `custom` is present) flag to determine if we will call `git init` on the exercise repository (useful if we don't want to start out with a Git repository)


## TODOs

- [X] Add validation for exercise configuration (e.g. cannot fork + not require Github) - to run as CI
For more details, refer to the official developer documentation: https://git-mastery.github.io/developers
37 changes: 37 additions & 0 deletions hands_on/add_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

from exercise_utils.git import add, init, commit
from exercise_utils.file import create_or_update_file, append_to_file

__requires_git__ = True
__requires_github__ = False


def download(verbose: bool):
os.makedirs("things")
os.chdir("things")
init(verbose)
create_or_update_file(
"fruits.txt",
"""
apples
bananas
cherries
dragon fruits
figs
""",
)
add(["fruits.txt"], verbose)
append_to_file("fruits.txt", "figs")
add(["fruits.txt"], verbose)
commit("Insert figs into fruits.txt", verbose)
create_or_update_file("colours.txt", """
a file for colours
""",
)
create_or_update_file("shapes.txt", """
a file for shapes
""",
)
add(["colours.txt", "shapes.txt"], verbose)
commit("Add colours.txt, shapes.txt", verbose)
27 changes: 27 additions & 0 deletions hands_on/list_commits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from exercise_utils.file import append_to_file, create_or_update_file
from exercise_utils.git import add, commit, init

__requires_git__ = True
__requires_github__ = False


def download(verbose: bool):
os.makedirs("things")
os.chdir("things")

init(verbose)

create_or_update_file(
"fruits.txt",
"""
apples
bananas
cherries
dragon fruits
"""
)

add(["fruits.txt"], verbose)
commit("Add fruits.txt", verbose)
51 changes: 51 additions & 0 deletions hands_on/update_remote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import subprocess

from exercise_utils.cli import run_command
from exercise_utils.file import create_or_update_file, append_to_file
from exercise_utils.git import add, init, commit

__requires_git__ = True
__requires_github__ = True

REPO_NAME = "gitmastery-things"

def download(verbose: bool):
username = run_command(["gh", "api", "user", "-q", ".login"], verbose).strip()
os.makedirs("things")
os.chdir("things")
init(verbose)
create_or_update_file("fruits.txt", """
apples
bananas
cherries
dragon fruits
""",
)
add(["fruits.txt"], verbose)
append_to_file("fruits.txt", "figs")
add(["fruits.txt"], verbose)
commit("Insert figs into fruits.txt", verbose)
create_or_update_file("colours.txt", """
a file for colours
""",
)
create_or_update_file("shapes.txt", """
a file for shapes
""",
)
add(["colours.txt", "shapes.txt"], verbose)
commit("Add colours.txt, shapes.txt", verbose)
repo_check = subprocess.run(
["gh", "repo", "view", f"{username}/{REPO_NAME}"],
capture_output=True,
text=True
)

if repo_check.returncode == 0:
run_command(["gh", "repo", "delete", REPO_NAME, "--yes"], verbose)

run_command(["gh", "repo", "create", REPO_NAME, "--public"], verbose)
run_command(["git", "remote", "add", "origin", f"https://github.com/{username}/{REPO_NAME}"], verbose)

run_command(["git", "push", "-u", "origin", "main"], verbose)
13 changes: 12 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash
set -e

source venv/bin/activate
if [ -f "venv/bin/activate" ]; then
# Linux / macOS
source venv/bin/activate
elif [ -f "venv/Scripts/activate" ]; then
# Windows (Git Bash, Cygwin, or WSL)
source venv/Scripts/activate
else
echo "Error: Could not find Python virtual environment activation script."
echo "Please create one with: python -m venv venv"
exit 1
fi

python -m pytest $1/tests/test_verify.py -s -vv