Skip to content
irenejoeunpark edited this page Oct 13, 2021 · 96 revisions

Lab 4

Due Date

Friday Oct 8th 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 continue to add a new feature to our SSG 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
  • 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 SSG Feature: Support --config with Config File

Description

Users want to be able to specify all of their SSG options in a JSON formatted configuration file instead of having to pass them all as command line arguments every time. For example, consider the following config file, ./ssg-config.json:

{
  "input": "./site",
  "output": "./build",
  "stylesheet": "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css",
  "lang": "fr"
}

A user could run the SSG by doing either of the following:

# Option 1: use command line arguments:
ssg --input ./site --output ./build --stylesheet https://cdn.jsdelivr.net/npm/water.css@2/out/water.css --lang fr

# Option 2: use a config file
ssg --config ./ssg-config.json

The config file option means we can have a much shorter command, and instead store our options in a file.

Requirements

  1. The -c or --config flags accept a file path to a JSON config file.
  2. If the file is missing, or can't be parsed as JSON, exit with an appropriate error message.
  3. If the -c or --config option is provided, ignore all other options (i.e., a config file overrides other options on the command line).
  4. The program should ignore any options in the config file it doesn't recognize. For example, if the SSG doesn't support stylesheets, ignore a stylesheet property.
  5. If the config file is missing any options, assume the usual defaults. For example, use dist/ as the output directory if it isn't specified.

Here are some valid config files to try:

{}
{
  "input": "./docs"
}
{
  "input": "./docs",
  "output": "./web"
}
{
  "input": "./docs",
  "output": "./web",
  "future-feature": "should be ignored for now"
}

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 SSG repo. Pick a new repo from the 0.1 Submissions list, ideally one that you haven't worked on before. You may NOT add it to your own repo. Only one student can add the feature per repo.

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

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.

To do so, you are encouraged to create a Draft Pull Request at the start of the week and continually add more commits to it as you do your work. 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".

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. 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>

This 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>
# substitute master for main if that is your default branch
$ 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
Example Name https://example.com/blog/1 10 12 ddeaf180
Roman Rezinkin https://dev.to/romanrezinkin/dps909-lab-4-22eh Issue #10 Link PR Link Merge Commit URL
Japneet Kalra https://dev.to/japneetsingh035/new-ssg-feature-support-config-file-13dl 13 14 861a016
Tue Nguyen https://dev.to/tuenguyen2911_67/a-way-to-review-a-pull-request-1hpl 19 20 2fbd0b
Tuan Thanh Tan https://dev.to/tuanthanh2067/adding-new-feature-for-a-static-site-generator-written-in-javascript-4mhb 21 22 c235807
Minh Quan Nguyen https://dev.to/mqnguyen/a-different-way-of-reviewing-pull-requests-3fog 12 13 026cf7a
Minsu Kim https://dev.to/mkim219/adding-new-ssg-feature-hg9 20 21 6460384
Eugene Chung https://ycechung-opensource.blogspot.com/2021/10/osd600-lab-4-git-remote.html 16 17 2e8ddd9
Kunwarvir Dhillon https://dev.to/dhillonks/working-with-remotes-lmf #31 pr #32 68c5881
Andre Willomitzer https://dev.to/andrewillomitzer/git-remote-add-friend-collaborate-git-49l6 14 PR 15 675c6f2
Ahmad Rokay https://dev.to/ar/using-remotes-lab-4-36mg 23 24 fb0fd72
Chi Kien Nguyen https://dev.to/kiennguyenchi/osd600-week-5-lab-4-2h68 Issue #19 PR #20 806de87
Antonio Bennett https://dev.to/antoniobennett/prs-merges-and-json-b9n Issue #15 PR 17
Francesco Menghi https://dev.to/menghif/supporting-json-config-file-156j 15 16 32eed9a
Jia Hua Zou https://medium.com/@jhzou/new-ssg-feature-support-config-file-255f42308f97 #29 #29 7e3cab8a
Gus McCallum Blog 11 12 Merge Commit
Alex Romanova Finally a similar code structure! 19 20 06a00a3
Leyang Yu https://dev.to/lyu4321/working-remotely-in-git-45hb Issue 18 PR 78eedfb
Vivian Vu https://dev.to/vivianvu/osd600-using-git-remote-and-git-merge-for-collaboration-2gid 21 22 963f190
Minh Hang Nguyen https://dev.to/minhhang107/working-with-git-remote-approving-new-feature-3b26 issue 10 PR URL 2f3762
Gustavo Tavares Blog Post 19 20 7fc38538
Tuan Phong Nguyen https://blog.andrewnt.dev/post/osd-600-series-draft-pull 7 8 85b2f8e
Oliver Pham https://dev.to/oliverpham/working-with-remote-branches-4o10 12 13 8f4d10c
Roxanne Lee https://medium.com/@Roxanne.Lee/lab-4-git-remote-bf087345f1bd 13 14 e1d73bf
Trang Nguyen https://tracy016.medium.com/osd600-git-remotes-git-revert-8d1cb6fb70a 11 12 72f154d
Joshua Li https://dev.to/jli/working-on-another-repo-1h0h 12 13 Merge
Jun Song My blog (,, ・∀・)ノ゛ issue-14 PR for issue-14 Merge
Kevan Yang https://dev.to/pandanoxes/lab-4-adding-config-option-for-other-student-repo-44aj issue #15 PR #16 870e5ad
Tengzhen Zhao my blog issue 16 PR 17 Merge
Reza Poursafa https://medium.com/@rezapscodes/osd600-git-remotes-a83b23a0e6fe 17 PR for 17 1741f2c
Xiongye Jiang https://dev.to/derekjxy/new-ssg-feature-478o 35 - Own Repo PR - Own Repo Merge - Own Repo
Luigi Zaccagnini Future Blog 11 12
Thanh Cong Van https://dev.to/tcvan0707/new-feature-for-static-site-generator-in-javascript-4d8 Issue #11 PR #12 bbb930e
Andrei Batomunkuev https://medium.com/@andreibatomunkuev/working-with-git-remote-b38f78ce8bb8 9 10 Merge
Hung Nguyen https://dev.to/nguyenhung15913/new-feature-has-been-added-and-working-via-remotes-14oe Issue-11 PR Issue-14
Jiyun Jung https://dev.to/jjung99/adding-new-feature-using-remotes-598a Issue-24 PR#25 Merge Pending
Diana Belokon blog 15 16 merged
Anatoliy Serputov https://medium.com/@aserputov/osd-lab-4-79b7318be78c Issue-18 PR 05b30eb
Le Minh Pham Lab 4 Blog My Issue My PR Merge commit
Mizuho Okimoto Open Source: git remotes and merges Issue-14 PR 15 04a71d5
Amasia Nalbandian A lil' rusty 10 11 2eff94e
Ritik Bheda Blog post Issue PR merge commit
James Mai Blog post Issue #13 PR #14 merge commit
Emily Phan Blog Issue #8 PR [Merge commit] ()
Gerardo Enrique Arriaga Rendon The Intricacies of Remote Repos Accept a configuration file through --config Add support to read a JSON config file 090f2c8
Duc Bui Manh blog #12 #13 17b11cc
Suhhee Kim Blog Post Issue#10 PR Merge commit (Partner needs to work on it)
Andrew Tassone Blog Post Issue 15 PR Merge commit
Qiwen Yu Blog issue15 PR Merge commit
Irene Park Blog Post Issue21 PR Merge Commits