lab 4 - humphd/topics-in-open-source-2024 GitHub Wiki

Lab 4

Due Date

Friday Oct 4th by Midnight.

Overview

This week we are going to practice using git remotes and merges to collaborate with our peers on some code changes.

To accomplish this we'll once again add a new feature to our 0.1 Release app repos. This lab will help you practice the following:

  • creating branches to work on new features and fix bugs
  • working on a more complex code change in another project you didn't write
  • working with and parsing TOML files
  • using git remote and sharing commits, branches
  • using tracking branches
  • understanding the difference between git push, git pull, and git fetch
  • working with Draft Pull Requests on GitHub
  • reviewing and testing a branch from another repo locally
  • using git merge
  • using git push to update a remote repo
  • manually closing pull requests by merging/pushing

NOTE: it is highly recommended that you watch this week's video on git remotes before you start this lab. We're going to use a number of features of git that are important to understand going forward, so please ask questions if you get stuck.

New Feature: Support using a TOML "dotfile" config file in the user's homedir

Description

Users want to be able to specify all of their options to your tool in a TOML formatted configuration file that they store in their home directory, instead of having to pass them all as command line arguments every time. For example, consider the following config file, ~/.your-toolname-config.toml:

model = "gpt-4o"
api_key = "sk-...."
# etc...

Then, when the user runs your tool, it will search for a config file in the home dir and use those values. Or, if the user specifies values via args, those will override the default ones in the config.

NOTE: there are many open source TOML implementations you can use to parse the config file. Don't write the parser yourself, pick a well maintained library instead.

Requirements

  1. The tool should look in the home dir for a "dotfile" TOML config (i.e., a file that starts with . and contains default options in TOML format)
  2. If the file is missing, ignore this
  3. If the file is present but can't be parsed as TOML, exit with an appropriate error message.
  4. If the file exists and no command line args override any values, the values in the config file should be used (e.g., use the model in the config)
  5. The program should ignore any options in the config file it doesn't recognize.

Step 1. Pick a Repo to Work in and File an Issue

You are asked to add this new config file feature to another student's repo. Pick a new repo from the 0.1 Submissions list, ideally one that you have NOT worked on before. You may NOT add it to your own repo. Only one student can add the feature per repo. You don't need to work as partners on each other's repos, but you can if you like.

Before you begin, check to see if an Issue is already filed for this feature. If it is, move on to another repo. If not, file a new Issue, letting the owner know what you intend to do, and start talking to them about how you should do it via Slack or in comments in the Issue on GitHub.

NOTE: if you notice two people filing the same issue in your repo, make sure you close the second one as a duplicate of the first.

Step 2. Create and Work on a Topic Branch

Fork and clone your partner's repo to begin your work.

Create a new topic branch for this work. If you filed Issue 6, consider naming your branch issue-6. You could also name it config-file, the naming is up to you.

Do all of your work on this branch, committing every significant change as you go.

You should also git push your branch to your fork on a regular basis. To do so (substitute your branch name for issue-6):

$ git push origin issue-6

The origin remote is the repo from which you cloned, and is automatically created when you clone a repo.

You can find your work on GitHub using the appropriate URL for your branch, for example:

https://github.com/{your-username}/{your-fork-repo-name}/tree/{your-branch-name}

Step 3. Collaborate with the Repo Owner

Create a Draft Pull Request at the start of the week and continually add more commits to it as you do your work over the week. A Draft PR is a work-in-progress, and you can keep updating it until it's ready for review, at which point you can change its status to "Ready for review".

Throughout the week, as you work on the config file feature, keep in regular contact with the owner of the repo. Don't wait until things are finished to get in touch. You are likely going to run into problems, have questions, or need advice on how they want something handled. Work in the open and force yourself to communicate and help one another.

Step 4. Complete the Feature

When you have completed the feature, commit and push all the changes on your branch to your fork:

$ git checkout issue-6
$ git push origin issue-6

Let the other student know that you're done in the GitHub Issue. Mark your Draft PR to "Ready for review", and ask the owner of the repo to review and test your code.

Step 5. Reviewing and Testing via Remotes

When you are reviewing and testing a PR, you often need to both read the code and also test the functionality locally. We know how to clone a repo, but how do we work with a different repo that we didn't clone? The answer is to add a git remote.

If your repo is being worked on by another student, get the name of their fork and the name of the branch they are working on. Next, add them as a remote to your local repo:

$ git remote add <name-of-student> <https://git-url-of-other-studnet-fork.git>

The https://...git URL is the same one you'd use to clone this repo (i.e., it is NOT the web URL you use in a browser, notice the .git extension). You can name the remote anything you like. Just remember what you called it. You can use git remote to list your remotes later, if you forget.

Next, git fetch their work into your local repo:

$ git fetch <name-of-student>

Using git fetch will download all the commits and branches in the remote repo to your local repo, but NOT merge anything (i.e., it's safe to do on any current branch). Everything they have in their repo is now copied to your git repo.

Next set up a tracking branch in your local repo, so you can track the work on their branch (substitute the name of the student and branch):

$ git checkout -b <branch-name> <name-of-student>/<branch-name>

This will create a branch in your repo that points to the same commit as the other student's repo and branch.

Use this branch to review and test their work. If you notice any issues, or something doesn't work, make comments in the pull request. Ask the author to fix their work.

NOTE: if you ever need to update your local tracking branch to see new changes that the other student has pushed to their fork, you can do that with git pull (assuming tracking branch is called issue-6):

$ git checkout issue-6
$ git pull <name-of-student> issue-6

If you have any trouble working with git during this process, make sure you ask for help in Slack. It is important that you understand how these commands work, so don't skip anything, and don't give up if you're confused!

Step 6. Merge the Feature When Ready

For the owner of the original repo: once you are satisfied that the feature is complete, and the pull request is done, try merging it manually and pushing to your repo:

$ git fetch <name-of-student>
$ git checkout main
$ git merge <student-name>/issue-6
$ git push origin main

Merging the work and pushing to the main branch should automatically close the pull request.

Step 7. Write a Blog Post

Write a blog post about the process of working on this new feature using remotes. First, how did the code itself go? Did you run into any problems? How did you tackle the work? Second, how did it go using git? Did you find any of it difficult? How did you get around this? What would you do differently next time? What did you learn from the experience?

Submission

When you have completed all the requirements above, please add your details to the table below.

Name Blog Post (URL) Issue URL PR URL Merge Commit URL on upstream default branch
Abdullah Al Mamun Fahim https://dev.to/aamfahim/another-week-another-feature-2e6k 13 14 49deaf30
Peter Wan https://dev.to/peterdanwan/toml-for-lazy-developers-3be9 19 20 764bf99
Bregwin Jogi https://dev.to/bregwin/learning-more-about-git-merges-and-remotes-2ld4 17 18 7133bc1
Majd Al Mnayer https://dev.to/majd_almnayer_2101/contributing-a-larger-feature-to-an-open-source-project-oo8 28 29 49deaf3
Vinh Nhan https://dev.to/vinhyan/collab-with-git-remotes-adding-toml-config-support-feature-jod 8 9 8ce26
Anh Chien Vu https://dev.to/anhchienvu/first-time-working-with-git-remote-5dbl 17 18 54ce75b
Henrique Sagara https://dev.to/htsagara/my-experience-with-virtual-environments-docker-and-shell-scripts-3k9i 12 13 e5d7a33
Nonthachai plodthong New Feature .toml for gimme-readme IS-33 PR-34 5a3982
Fahad Ali Khan github-echo 46 PR 4064ccd
Huynjin Shin https://dev.to/jinger-ale/osd600-lab-04-4fl1 issue9 17 e5d7a33
Cleo Buenaventura https://dev.to/cleobnvntra/working-with-git-remote-and-toml-files-4o9m 16 17 34c8093
Aryan Khurana https://aryank1511.hashnode.dev/understanding-remotes-and-pr-reviews #21 #22 6461cbf
Harshil Patel https://dev.to/harshil_patel/learning-git-fetch-pull-and-remotes-while-adding-a-feature-to-open-source-project-1730 #35 #36 983882c
Mayank Kumar https://dev.to/mayankpareek/tracking-and-testing-remote-branches-3n3f #18 #19 979da13
Lily Huang https://vriskaserket2.wordpress.com/2024/10/04/git-stuff/ #11 #12 6893a97
Uday Rana https://dev.to/udayrana/parsing-some-toml-12n8 #8 #9 TBD
Arina Kolodeznikova Using Gite Remotes for Collaboration #24 #25 04e10fb
Ajo George Blog #8 PR 10 0baac50
Rong Chen https://dev.to/elisassa/osd-lab4-adding-toml-support-to-a-github-project-3kml #15 PR 16 8f8d858
Kannav Sethi https://dev.to/kannav02/a-practical-approach-to-toml-files-and-remote-branch-management-hh8 #8 PR 9 15481f0
Amir Mullagaliev Follow my journey #18 PR 19 8549cbe
Andrii Sych Blog #1 PR 2 8118e1
Adam Davis https://dev.to/add00_3/adding-a-toml-file-config-1ibi 35 36 176c570
Aldrin Fernandez https://dev.to/aldrin312/lab-4-remote-git-and-toml-2gmm 8 9 77cd694
Liam Hutchinson https://dev.to/mpalhutchinson/week-4-lab-4-toml-file-support-17o 13 14 a25dc43
Christian Duarte https://dev.to/cduarte3/week-5-lab-4-239p 11 12 9f3a5c4
Theo https://dev.to/theoforger/working-with-config-files-4n06 #9 #10 c67ff3b
Tasbi Tasbi https://dev.to/tasbi03/-how-i-made-your-life-easier-with-toml-configs-in-an-open-source-project-32n1 10 11 f58b875
Madhur Saluja https://dev.to/msaluja/blog-post-diving-into-someone-elses-code-the-tale-of-a-toml-fix-25bm 11 12 6777001
Krinskumar My Blog My Issue My PR Merge in progress
Inderpreet Singh Parmar Blog My Issue My PR Merge in progress