Diferență între revizuiri ale paginii „SDPT Lab 1”

De la WikiLabs
Jump to navigationJump to search
(Pagină nouă: = Lab 1: Foundation of Process - Git and GitLab Basics = == Introduction == Welcome to the first lab of Software Development Process and Testing (SDPT). In our lecture, we discuss...)
 
 
(Nu s-au afișat 2 versiuni intermediare efectuate de același utilizator)
Linia 5: Linia 5:
  
 
Today, we put theory into practice. By the end of this 2-hour lab, you will have:
 
Today, we put theory into practice. By the end of this 2-hour lab, you will have:
# Created a project repository on GitLab.
+
# Configured secure SSH authentication with your GitLab server.
# Created your first tracked Issue.
+
# Created a project repository and your first tracked Issue.
 
# Configured Git on your local machine.
 
# Configured Git on your local machine.
 
# Moved a C++ source file through the Three States of Git.
 
# Moved a C++ source file through the Three States of Git.
# Pushed your local history to the remote GitLab server and automatically closed your Issue.
+
# Prevented binary files from entering your repository using <code>.gitignore</code>.
 +
# Pushed your local history to the remote GitLab server to automatically close your Issue.
  
 
'''Note:''' Do not rush. The goal is to understand ''where'' your files are in the Git graph at any given moment. Run <code>git status</code> frequently!
 
'''Note:''' Do not rush. The goal is to understand ''where'' your files are in the Git graph at any given moment. Run <code>git status</code> frequently!
  
---
+
== Part 1: Secure Authentication (SSH Keys) ==
 +
Modern code repositories do not allow you to push code using your standard web password. We must set up a secure cryptographic key pair.
  
== Part 1: Setting Up the Remote (GitLab) ==
+
=== 1. Generate an SSH Key Pair ===
Before we touch the terminal, we need to set up our remote infrastructure and document the work we intend to do.
+
Open your terminal (Linux/macOS) or Git Bash (Windows) and type:
 +
<syntaxhighlight lang="bash">
 +
ssh-keygen -t ed25519 -C "your.university.email@stud.####.upb.ro"
 +
</syntaxhighlight>
 +
* Press '''Enter''' to accept the default file location.
 +
* Press '''Enter''' twice to skip creating a passphrase (for the sake of this lab environment).
 +
 
 +
This generated two files: a private key (never share this!) and a public key.
 +
 
 +
=== 2. Add the Public Key to GitLab ===
 +
Display your public key in the terminal and copy the output exactly:
 +
<syntaxhighlight lang="bash">
 +
cat ~/.ssh/id_ed25519.pub
 +
</syntaxhighlight>
 +
* Log into your university GitLab account in your browser.
 +
* Click your profile avatar (top right) -> '''Edit profile''' -> '''SSH Keys''' (on the left sidebar).
 +
* Click '''Add new key'''. Paste your copied key into the "Key" box. Title it "My Lab Laptop" and click '''Add key'''.
 +
 
 +
== Part 2: Setting Up the Remote (GitLab) ==
 +
Before we write code, we document our work.
  
 
=== 1. Create a New Repository ===
 
=== 1. Create a New Repository ===
* Log into your university GitLab account.
+
* Go to the GitLab homepage. Click '''New Project''' -> '''Create blank project'''.
* Click '''New Project''' -> '''Create blank project'''.
 
 
* '''Project Name:''' <code>sdpt-rfid-access</code>
 
* '''Project Name:''' <code>sdpt-rfid-access</code>
* '''Visibility Level:''' Private (or Internal, depending on your professor's instructions).
+
* '''Visibility Level:''' Private (or Internal).
* '''Important:''' Uncheck "Initialize repository with a README". We want an entirely empty repository to practice pushing from our local machine.
+
* '''Important:''' Uncheck "Initialize repository with a README". We want an entirely empty repository.
 
* Click '''Create project'''.
 
* Click '''Create project'''.
  
 
=== 2. Create Your First Issue ===
 
=== 2. Create Your First Issue ===
We need a business requirement before we write code.
 
 
* On the left sidebar of your new project, navigate to '''Plan''' -> '''Issues'''.
 
* On the left sidebar of your new project, navigate to '''Plan''' -> '''Issues'''.
 
* Click '''New issue'''.
 
* Click '''New issue'''.
 
* '''Title:''' <code>Create initial RFID reader driver skeleton</code>
 
* '''Title:''' <code>Create initial RFID reader driver skeleton</code>
 
* '''Description:''' <code>Need a basic main.cpp file that will eventually hold the SPI communication logic for the RFID module.</code>
 
* '''Description:''' <code>Need a basic main.cpp file that will eventually hold the SPI communication logic for the RFID module.</code>
* Click '''Create issue'''.
+
* Click '''Create issue'''. Take note of the '''Issue Number''' (e.g., <code>#1</code>).
* Take note of the '''Issue Number''' (e.g., <code>#1</code>) generated next to the title. You will need this later!
 
 
 
---
 
 
 
== Part 2: Initializing the Local Environment ==
 
Now, open your terminal (Linux/macOS) or Git Bash (Windows).  
 
  
 +
== Part 3: Initializing the Local Environment ==
 
=== 1. Configure Your Identity ===
 
=== 1. Configure Your Identity ===
Git embeds the author's name and email into every commit permanently. You only need to run these commands once per computer.
+
Git embeds your name and email into every commit permanently. Run these once:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git config --global user.name "Your First and Last Name"
 
git config --global user.name "Your First and Last Name"
Linia 50: Linia 63:
 
=== 2. Create Your Local Workspace ===
 
=== 2. Create Your Local Workspace ===
 
Create a folder for your project and initialize it as a Git repository.
 
Create a folder for your project and initialize it as a Git repository.
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
mkdir sdpt-rfid-access
 
mkdir sdpt-rfid-access
Linia 57: Linia 69:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Notice the output: <code>Initialized empty Git repository</code>. A hidden <code>.git</code> folder has been created. This is your database.
+
== Part 4: Ignoring the Noise (.gitignore) ==
 +
In C/C++, compiling creates binary files (like <code>.o</code>, <code>.out</code>, or <code>.exe</code>). We '''never''' track compiled binaries in Git—we only track human-readable source code!
 +
 
 +
Let's tell Git to permanently ignore build files.
 +
Create a file named exactly <code>.gitignore</code>:
 +
<syntaxhighlight lang="bash">
 +
touch .gitignore
 +
</syntaxhighlight>
 +
 
 +
Open it in your editor and add these lines:
 +
<syntaxhighlight lang="text">
 +
# Ignore compiled binaries
 +
*.o
 +
*.out
 +
*.exe
 +
# Ignore IDE folders
 +
.vscode/
 +
.idea/
 +
</syntaxhighlight>
  
---
+
Save the file. Let's stage and commit our configuration:
 +
<syntaxhighlight lang="bash">
 +
git add .gitignore
 +
git commit -m "Add .gitignore for C++ project"
 +
</syntaxhighlight>
  
== Part 3: The Three States in Practice ==
+
== Part 5: The Three States in Practice ==
Remember the three states from the lecture: Working Directory, Staging Area, and Repository. Let's move a file through them.  
+
Let's move our actual source code through the Working Directory, Staging Area, and Repository.  
  
 
=== 1. The Working Directory ===
 
=== 1. The Working Directory ===
Create a new C++ file. This represents writing your initial code.
+
Create your C++ file:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
touch main.cpp
 
touch main.cpp
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Open <code>main.cpp</code> in your favorite text editor (nano, vim, VS Code) and add a basic skeleton:
+
Open <code>main.cpp</code> and add a basic skeleton:
 
 
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
#include <iostream>
 
#include <iostream>
Linia 82: Linia 114:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now, check your radar:
+
Check your radar:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git status
 
git status
 
</syntaxhighlight>
 
</syntaxhighlight>
''Notice that <code>main.cpp</code> is red and listed under "Untracked files". Git sees the file in your Working Directory, but is not managing it yet.''
+
''Notice <code>main.cpp</code> is red. It is Untracked.''
  
 
=== 2. The Staging Area (Index) ===
 
=== 2. The Staging Area (Index) ===
Tell Git you want to include this file in your next commit snapshot.
+
Tell Git to include this in the next snapshot.
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git add main.cpp
 
git add main.cpp
 
git status
 
git status
 
</syntaxhighlight>
 
</syntaxhighlight>
''Notice the file is now green and under "Changes to be committed". It is in the Staging Area.''
+
''It is now green. It is Staged.''
  
=== 3. The Repository (Commit) ===
+
=== 3. Time Travel and Diffs ===
Save the snapshot permanently into your local Git database.
+
Wait! Before committing, what exactly did we just stage? It's good practice to review your code.
 +
<syntaxhighlight lang="bash">
 +
git diff --staged
 +
</syntaxhighlight>
 +
This shows you the exact lines of C++ you are about to commit. Press <code>q</code> to exit the diff view if it pauses.
  
 +
=== 4. The Repository (Commit) ===
 +
Save the snapshot permanently.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git commit -m "Add initial RFID system skeleton"
 
git commit -m "Add initial RFID system skeleton"
 
git status
 
git status
 
</syntaxhighlight>
 
</syntaxhighlight>
''Your working tree is now clean. The snapshot is stored as a node in your local Git graph.''
 
  
---
+
== Part 6: Connecting Local to Remote and Closing Issues ==
 
+
Your code is safe locally, but the "Bus Factor" is still 1. We must push to GitLab using the SSH key we created earlier.
== Part 4: Connecting Local to Remote and Closing Issues ==
 
Your code is safe locally, but the "Bus Factor" is still 1. If your laptop crashes, the code is gone. We must push to GitLab.
 
  
 
=== 1. Link the Remote Server ===
 
=== 1. Link the Remote Server ===
Go back to your GitLab project page. Under "Push an existing Git repository", copy the <code>git remote add origin...</code> command. It will look like this:
+
Go back to your GitLab project page. Under "Push an existing Git repository", click the '''SSH''' button (not HTTPS) and copy the <code>git remote add origin...</code> command. It will look like this:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
git remote add origin https://gitlab.com/your-username/sdpt-rfid-access.git
+
git remote add origin git@gitlab.com:your-username/sdpt-rfid-access.git
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Paste and run that in your terminal.
  
 
=== 2. Push and Close the Issue ===
 
=== 2. Push and Close the Issue ===
We want to push our code AND tell GitLab that this code fulfills the requirement we documented in Part 1. We do this by making a new commit that references the Issue number.
+
Let's make one final change to fulfill our Issue requirement and close it automatically.
 
+
Open <code>main.cpp</code> and add a comment:
Let's make a small change to <code>main.cpp</code>. Open it and add a comment:
 
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
 
// TODO: Implement SPI communication with RC522 module
 
// TODO: Implement SPI communication with RC522 module
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Now, stage and commit this change, using a special keyword (<code>Closes #1</code>) in the commit message:
+
Stage and commit this change, using the special keyword (<code>Closes #1</code>) in your commit message:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git add main.cpp
 
git add main.cpp
Linia 133: Linia 165:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Finally, push your local graph to the remote server:
+
Push your local graph to the remote server:
 
 
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
git push -u origin main
 
git push -u origin main
 
</syntaxhighlight>
 
</syntaxhighlight>
''(Note: If your default branch is 'master' instead of 'main', use <code>git push -u origin master</code>)''
+
''(Note: If Git complains about 'main', try <code>git push -u origin master</code>, or ask your professor how to rename your default branch).''
 +
 
 +
When prompted "Are you sure you want to continue connecting?", type <code>yes</code> and press Enter.
  
 
=== 3. Verify the Magic ===
 
=== 3. Verify the Magic ===
Go back to your browser and refresh your GitLab project page:
+
Refresh your GitLab project page in your browser:
* Your <code>main.cpp</code> file is now visible on the server!
+
* Your <code>main.cpp</code> and <code>.gitignore</code> files are visible!
* Go to '''Plan''' -> '''Issues'''. Notice that Issue #1 is now automatically marked as '''Closed'''. Git and GitLab worked together to link your code directly to the business requirement.
+
* Go to '''Plan''' -> '''Issues'''. Notice that Issue #1 is now automatically marked as '''Closed'''.  
 
 
---
 
  
 
== Lab Deliverable ==
 
== Lab Deliverable ==
 
To receive full credit for this week's lab, call the professor or teaching assistant over to your workstation and demonstrate:
 
To receive full credit for this week's lab, call the professor or teaching assistant over to your workstation and demonstrate:
# Your GitLab repository showing the <code>main.cpp</code> file.
+
# Your GitLab repository showing the code and the <code>.gitignore</code> file.
 
# Your GitLab Issue board showing Issue #1 as Closed.
 
# Your GitLab Issue board showing Issue #1 as Closed.
# Your terminal showing the output of the <code>git log</code> command, displaying your two commits.
+
# Your terminal showing the output of the <code>git log --oneline</code> command, displaying your three commits.

Versiunea curentă din 23 februarie 2026 00:41

Lab 1: Foundation of Process - Git and GitLab Basics

Introduction

Welcome to the first lab of Software Development Process and Testing (SDPT). In our lecture, we discussed why treating software like a physical breadboard leads to failure in complex systems. We introduced the Software Development Life Cycle (SDLC), Issue Tracking, and the underlying graph model of Git.

Today, we put theory into practice. By the end of this 2-hour lab, you will have:

  1. Configured secure SSH authentication with your GitLab server.
  2. Created a project repository and your first tracked Issue.
  3. Configured Git on your local machine.
  4. Moved a C++ source file through the Three States of Git.
  5. Prevented binary files from entering your repository using .gitignore.
  6. Pushed your local history to the remote GitLab server to automatically close your Issue.

Note: Do not rush. The goal is to understand where your files are in the Git graph at any given moment. Run git status frequently!

Part 1: Secure Authentication (SSH Keys)

Modern code repositories do not allow you to push code using your standard web password. We must set up a secure cryptographic key pair.

1. Generate an SSH Key Pair

Open your terminal (Linux/macOS) or Git Bash (Windows) and type:

ssh-keygen -t ed25519 -C "your.university.email@stud.####.upb.ro"
  • Press Enter to accept the default file location.
  • Press Enter twice to skip creating a passphrase (for the sake of this lab environment).

This generated two files: a private key (never share this!) and a public key.

2. Add the Public Key to GitLab

Display your public key in the terminal and copy the output exactly:

cat ~/.ssh/id_ed25519.pub
  • Log into your university GitLab account in your browser.
  • Click your profile avatar (top right) -> Edit profile -> SSH Keys (on the left sidebar).
  • Click Add new key. Paste your copied key into the "Key" box. Title it "My Lab Laptop" and click Add key.

Part 2: Setting Up the Remote (GitLab)

Before we write code, we document our work.

1. Create a New Repository

  • Go to the GitLab homepage. Click New Project -> Create blank project.
  • Project Name: sdpt-rfid-access
  • Visibility Level: Private (or Internal).
  • Important: Uncheck "Initialize repository with a README". We want an entirely empty repository.
  • Click Create project.

2. Create Your First Issue

  • On the left sidebar of your new project, navigate to Plan -> Issues.
  • Click New issue.
  • Title: Create initial RFID reader driver skeleton
  • Description: Need a basic main.cpp file that will eventually hold the SPI communication logic for the RFID module.
  • Click Create issue. Take note of the Issue Number (e.g., #1).

Part 3: Initializing the Local Environment

1. Configure Your Identity

Git embeds your name and email into every commit permanently. Run these once:

git config --global user.name "Your First and Last Name"
git config --global user.email "your.university.email@domain.edu"

2. Create Your Local Workspace

Create a folder for your project and initialize it as a Git repository.

mkdir sdpt-rfid-access
cd sdpt-rfid-access
git init

Part 4: Ignoring the Noise (.gitignore)

In C/C++, compiling creates binary files (like .o, .out, or .exe). We never track compiled binaries in Git—we only track human-readable source code!

Let's tell Git to permanently ignore build files. Create a file named exactly .gitignore:

touch .gitignore

Open it in your editor and add these lines:

# Ignore compiled binaries
*.o
*.out
*.exe
# Ignore IDE folders
.vscode/
.idea/

Save the file. Let's stage and commit our configuration:

git add .gitignore
git commit -m "Add .gitignore for C++ project"

Part 5: The Three States in Practice

Let's move our actual source code through the Working Directory, Staging Area, and Repository.

1. The Working Directory

Create your C++ file:

touch main.cpp

Open main.cpp and add a basic skeleton:

#include <iostream>

int main() {
    std::cout << "RFID Access Control System Initialized" << std::endl;
    return 0;
}

Check your radar:

git status

Notice main.cpp is red. It is Untracked.

2. The Staging Area (Index)

Tell Git to include this in the next snapshot.

git add main.cpp
git status

It is now green. It is Staged.

3. Time Travel and Diffs

Wait! Before committing, what exactly did we just stage? It's good practice to review your code.

git diff --staged

This shows you the exact lines of C++ you are about to commit. Press q to exit the diff view if it pauses.

4. The Repository (Commit)

Save the snapshot permanently.

git commit -m "Add initial RFID system skeleton"
git status

Part 6: Connecting Local to Remote and Closing Issues

Your code is safe locally, but the "Bus Factor" is still 1. We must push to GitLab using the SSH key we created earlier.

1. Link the Remote Server

Go back to your GitLab project page. Under "Push an existing Git repository", click the SSH button (not HTTPS) and copy the git remote add origin... command. It will look like this:

git remote add origin git@gitlab.com:your-username/sdpt-rfid-access.git

Paste and run that in your terminal.

2. Push and Close the Issue

Let's make one final change to fulfill our Issue requirement and close it automatically. Open main.cpp and add a comment:

// TODO: Implement SPI communication with RC522 module

Stage and commit this change, using the special keyword (Closes #1) in your commit message:

git add main.cpp
git commit -m "Add SPI TODO comment. Closes #1"

Push your local graph to the remote server:

git push -u origin main

(Note: If Git complains about 'main', try git push -u origin master, or ask your professor how to rename your default branch).

When prompted "Are you sure you want to continue connecting?", type yes and press Enter.

3. Verify the Magic

Refresh your GitLab project page in your browser:

  • Your main.cpp and .gitignore files are visible!
  • Go to Plan -> Issues. Notice that Issue #1 is now automatically marked as Closed.

Lab Deliverable

To receive full credit for this week's lab, call the professor or teaching assistant over to your workstation and demonstrate:

  1. Your GitLab repository showing the code and the .gitignore file.
  2. Your GitLab Issue board showing Issue #1 as Closed.
  3. Your terminal showing the output of the git log --oneline command, displaying your three commits.