2025-05-12 (3 VO): C++ “Door” Exercise Recap, Some Git

Recap Of Door Exercise

Notes

  • .h vs .cpp: where to put implementation?

  • Ownership (why do we pass pointers into Door ctor?)

C++ Material

Some Git

Add/Commit

  • View changes

    Current working directory somewhere inside the tree,

    $ git status
    ...
    
  • git add changes: stage for next commit

    $ git add file.h file.cpp
    ...
    

    Review repo situation

    $ git status
    ...
    
  • git commit what you staged

    Either non-interactive (giving the commit message as a commandline parameter)

    $ git commit -m 'frobozz the foobar'
    

    Or letting git pop up your favorite $EDITOR

    $ git commit
    

Access Github Over SSH Not HTTPS

This is simpler. HTTPS requires two factor auth and jumping through hoops.

Deploy SSH public on GH ⟶ homework. On Github, You -> Settings -> SSH and GPG Keys. Paste your public key.

Change Upstream, And Push

../../../../../../../_images/git-workflow.jpg
  • Fork old upstream into something where you have write access; say, https://github.com/you/FH-STECE2023.git. On Github, press the “Fork” button and follow the instructions.

  • Change upstream of your clone to be your fork

    $ git remote set-url origin git@github.com:you/FH-STECE2023.git
    

    Note the SSH URL, starting with git@github.com:.

  • Pull changes that you don’t have. Reason: between the time you cloned your repo (remember, from https://github.com/jfasch/FH-STECE2023), and the time you created the fork, some commits have been pushed to https://github.com/jfasch/FH-STECE2023.

    $ git pull
    ... an editor will pop up. accept the prefilled "this is a merge commit" message ...
    
  • Push your repo; this will now go into your new repo git@github.com:you/FH-STECE2023.git

    $ git push
    

Homework

Local C++ Transformation

  • Complete the C++ transformation according to the example in lib/push-button.h and lib/push-button.cpp

    See door sketch in Door Exercise. For all the components in your exercise/firstname.lastname/lib directory, change its implementation from C struct to C++ class.

    • PushButton

    • LightBarrier

    • Motor

    • Door (the C struct has pointer members, and this does not change in the C++ class)

  • Make sure the tests still run

  • Make clean commits in your local repo that you cloned from https://github.com/jfasch/FH-STECE2023.git the other day

Fork on Github, And Change Your Upstream

Following the procedure outlined in Change Upstream, And Push,

  • Create a fork of our project

  • In your clone from earlier days, change upstream to that fork.

  • Push your repo to the new upstream

Submission: Pull Request

To submit, send me a pull request.