Diferență între revizuiri ale paginii „SDPT Lab 1”
(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: | ||
| − | # | + | # 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 | + | # 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. Generate an SSH Key Pair === |
| − | Before we | + | 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 === | ||
| − | * | + | * Go to the GitLab homepage. 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 | + | * '''Visibility Level:''' Private (or Internal). |
| − | * '''Important:''' Uncheck "Initialize repository with a README". We want an entirely empty repository | + | * '''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 === | ||
| − | |||
* 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>). |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | == Part 3: Initializing the Local Environment == | ||
=== 1. Configure Your Identity === | === 1. Configure Your Identity === | ||
| − | Git embeds | + | 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> | ||
| − | + | == 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 | + | == 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 === | === 1. The Working Directory === | ||
| − | Create | + | Create your C++ file: |
| − | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
touch main.cpp | touch main.cpp | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | Open <code>main.cpp</code> | + | 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> | ||
| − | + | Check your radar: | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
git status | git status | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | ''Notice | + | ''Notice <code>main.cpp</code> is red. It is Untracked.'' |
=== 2. The Staging Area (Index) === | === 2. The Staging Area (Index) === | ||
| − | Tell Git | + | 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> | ||
| − | '' | + | ''It is now green. It is Staged.'' |
| − | === 3. | + | === 3. Time Travel and Diffs === |
| − | + | 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> | ||
| − | |||
| − | + | == 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 | ||
| − | Your code is safe locally, but the "Bus Factor" is still 1 | ||
=== 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 | + | 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 === | ||
| − | + | 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 | ||
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
// TODO: Implement SPI communication with RC522 module | // TODO: Implement SPI communication with RC522 module | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | 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> | ||
| − | + | 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 | + | ''(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 === | ||
| − | + | Refresh your GitLab project page in your browser: | |
| − | * Your <code>main.cpp</code> | + | * 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'''. | + | * 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> | + | # 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 | + | # 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:
- Configured secure SSH authentication with your GitLab server.
- Created a project repository and your first tracked Issue.
- Configured Git on your local machine.
- Moved a C++ source file through the Three States of Git.
- Prevented binary files from entering your repository using
.gitignore. - 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.cppand.gitignorefiles 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:
- Your GitLab repository showing the code and the
.gitignorefile. - Your GitLab Issue board showing Issue #1 as Closed.
- Your terminal showing the output of the
git log --onelinecommand, displaying your three commits.