Skip to content

feat: make download comment idempotent and add --force flag - #155

Merged
jiaxinnns merged 3 commits into
mainfrom
feat/download-command-fixes
Aug 29, 2026
Merged

feat: make download comment idempotent and add --force flag#155
jiaxinnns merged 3 commits into
mainfrom
feat/download-command-fixes

Conversation

@jiaxinnns

@jiaxinnns jiaxinnns commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Make download refuse to overwrite an existing exercise

Why

gitmastery download <exercise> was silently destructive. If the folder already
existed it printed a warn() — which only echoes, it doesn't prompt or exit — and
then rmtree'd the folder. A student re-running gitmastery d under-control out of
habit lost their work with no consent and no recovery (rmtree takes a backup but
deletes it on success).

For remote + create_fork exercises the damage wasn't only local: the re-download
also closed the student's open PRs and deleted their GitHub fork.

gitmastery progress reset already exists as the sanctioned "start over" path, so
download had no reason to also be one.

What changed

  • download now blocks when the target folder exists: it reports that nothing was
    downloaded and points at progress reset (to start over) or --force (to wipe).
    Exits 1. The guard runs before any network work, so it's instant.
  • New --force / -f flag opts into the old behaviour. Covers both exercises and
    hands-on practices, and works in the REPL (/download <name> --force).
  • The Git/GitHub requirement checks now run before the folder is removed.
    Previously --force deleted first and rolled back by deleting again — so a failed
    check left the student with nothing. The base files are staged in a temp dir, the
    checks run, and only then is the existing folder replaced.
  • Fixed a crash: --force over a folder with no valid .gitmastery-exercise.json
    (a partial download, or a folder the student made) raised an unhandled
    FileNotFoundError. Now handled via _read_existing_config.

Before / after

# before                                                                                                
$ gitmastery download under-control
 WARN  You already have under-control, removing it to download again
 ...                                          # work gone, exit 0

# after
$ gitmastery download under-control
 ERROR  You already have under-control downloaded at under-control/. Nothing was downloaded.
        To start the exercise over, run gitmastery progress reset from inside it.
        To delete the folder, along with any work in it, and download it again, run
        gitmastery download under-control --force.
                                              # exit 1, work intact

Note

Behaviour change for anyone scripting a re-download — they'll need --force.
Suggest labelling bump:minor.

@jiaxinnns
jiaxinnns merged commit d688f09 into main Aug 29, 2026
3 of 6 checks passed
@jiaxinnns
jiaxinnns deleted the feat/download-command-fixes branch August 29, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants