CSCI 161 Lab 1: section S26N01

See the main lab page for submission deadlines and late penalties.

It is assumed you are keeping up to date with the lectures and labs.
Some additional git information is available through the git quick notes, git project/lab submission, and lecture resources pages.

This lab focuses on introducing our use of git for obtaining and submitting this year's labs and project, and also as a refresher on basic C++ programming.

In lab 1, you'll be following the lab instructions to:

  1. create the markable (server-side) copy of the lab1 repository,
  2. clone that to create your own local working copy,
  3. compile the skeleton lab1 code using a provided makefile,
  4. revise, compile, and test your C++ code for lab1
  5. push your work back to the git server for marking

For this to work correctly, you will need to follow the lab instructions carefully and in the sequence given.

When doing the lab, take some time to ensure you understand what each command is supposed to do before you run it.

After running each command take some time to ensure you understand what actually did happen. (In the great scheme of things, it doesn't do anyone much good if you're just typing commands without understanding them.)


Lab instructions

Again, these must be done in sequence, and each set of instructions must complete successfully before you move on to the next.
If you've taken 161 in the past then you probably already have a csci161 directory. You're not going to want to mix up this year's 161 stuff with the old stuff, so before you mkdir csci161 I'd suggest doing something like
mv csci161 old161


0. double-check that the instructor has posted the repo
Run the command below, and check to make sure that the csci 161 lab1 repository appears in the list (if it isn't posted yet then don't proceed yet)
ssh -x csci info

This lists all the repositories you currently have access to, and the one you're specifically looking for will look like csci161/lab1.

A WARNING AGAINST TRYING THE REMAINING STEPS BEFORE YOUR LAB SESSION:
none of the remaining lab instructions will work correctly until the repository has been set up by the instructor, which may not happen until the day of the lab


1. create the server-side copy of the repo
To do this, enter the following command:
ssh -x csci fork csci161-01/lab1 csci161-01/$USER/lab1
(actually type $USER, as it is a pre-existing variable that contains your linux userid)

You can check if this worked correctly by running the ssh -x csci info command again, and it should now show an additional repository:
csci161-01/yourusername/lab1


2. clone your own local working copy
If you haven't previously done so, you'll want to create a csci161 directory in your home directory, i.e.
cd
mkdir csci161
cd csci161

now clone your server-side copy, creating a working lab1 repository here
git clone csci:csci161-01/$USER/lab1 lab1

We can check if this has been successful by entering our lab1 directory and checking which files are present:

cd lab1
ls
This should show lab1.cpp, lab1.h, ranking.h, ranking.cpp, makefile, and README


3. compile/run the skeleton, and try a git push
We'll use the supplied makefile to compile the files and create a lab1x executable:
make

That will thow a lot of warnings about unused parameters (since the functions are mostly empty so far), but it should compile and create a lab1x executable. You can check that using ls, then try running it:
./lab1x

At this point it doesn't do much but print Welcome!

We'll try submitting your repository, just to make sure everything has been set up correctly:

git add lab1.cpp
git add ranking.cpp
git add lab1.h
git add ranking.h
git add lab1x
git commit -m "compiled the original lab1"
git push
(The commit will produce a couple of lines of messages about how many files were changed leading up to the commit and the create mode for lab1x.
The push will produce 10-15 lines of output regarding compressing/writing objects, information about the remote in use, and ending with a large hexadecimal commit id and "master -> master".)

This will have copied your work back to the server where the instructor can access/mark it. You can repeat this cycle as often as you like, each time it sends the updated content. (Thus the instructor will always have your most up to date version for marking.)

If anything goes wrong see step 5 at the bottom of this page for some basic trouble-shooting, and if that doesn't solve the problem then talk to your instructor for help.


4. complete the lab1.cpp and ranking.cpp files as per specifications
Now we finally get into the actual programming details for lab1.

The specifications for lab1.cpp are as follows:

Be sure you read, understand, and follow the code standards for CSCI 161, as they will most likely be different than the standards you were given in your CSCI 159/160 course. Marks will be deducted for failing to follow standards.

I also strongly recommend that after each successful modification of your ranking.cpp you perform the following two commands:

   git add ranking.cpp
   git commit -m "some message uniquely describing the changes you just made"
These use git to take and store a snapshot of your latest set of changes, which will subsequently allow you to roll back to the current state of your code if you ever need to (e.g. if you accidentally trash your lab1.cpp file later, or make changes you wish to undo).

A sample run of the program is shown below. (For the sake of clarity in the example, user input is shown in bold italics - this is of course not something your program actually could/would do.)

DETAILS TBA


5. add, commit, and push your finished lab back to the git server
We'll perform two git adds to ensure git has tracked your changes to lab1.cpp and lab1x, and a git commit to take a snapshot of the current repository state:

git add ranking.cpp
git add lab1x
git commit -m "lab1 complete"
Finally we need to push all your updates to the server for marking:
git push

Note that if you forget any of those steps (the adds, commit, or push) then the changes you made will not reach the instructor for marking.

If you're ever in doubt about the current state of your repository you can run the command git status, which should eventually give a message like "up-to-date with origin master". Here are the most common other messages it may give you:

What to do if, on a push, you get an error like this:

FATAL: W any csci161-01/lab1 yourusername DENIED by fallthru
(or you mis-spelled the reponame)
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Note the push should be trying to go to "csci161-01/yourusername/lab1", not to "csci161-01/lab1" (which is the instructor repo), so this error message suggests that in step 2 you may have cloned the wrong repo, e.g. you may have done git clone csci:csci161-01/lab1
instead of the correct git clone csci:csci161-01/$USER/lab1
thus now in step 5 when you push it's trying to overwrite the instructor's version, so is giving you that permission error.

It's not an uncommon mistake, and easily fixed. We need your lab1 repo to think it was cloned from *your* space on the git server, not from the instructor's, so we'll reset where your repository thinks it came from using the following command:
git remote set-url origin csci:csci161-01/$USER/lab1

After that, you should be able to push normally.


If you ever want to completely start over:

  • you can get rid of your server-side repo with the command
    ssh csci D trash csci161-01/$USER/lab1
  • you can get rid of your local copy using the command sequence
    cd
    cd csci161
    rm -rf lab1