DEV Community

Vivian
Vivian

Posted on

OSD600 - Working In Multiple Branches

1. Lab3 requirements

In this lab, I am going to make some changes to my repo, they are listed below:

As this week I am learning about git merge <commit> command so I am going to work on a different branch for each change.

2. Modifications

  • Modification for the first change - working on branch issue-19: Implementing the specifying language feature is quite easy since I used the create-html package to generate HTML files.

First of all, I add an option for user to specify the language they want to use then create a global variable to store argv.lang value, this value will be passed to other modules and be used in generateHTML.

In index.js

 .option("l", {
    alias: "lang",
    describe: "language used in HTML",
    default: "en-CA",
    type: "string",
    demandOption: false,
  })
Enter fullscreen mode Exit fullscreen mode

Then, in the generateHTML.js module, I set up the value of lang to language(or argv.lang).

 const html = createHTML({
    title: `${title}`,
    head: `<meta name="viewport" content="width=device-width, initial-scale=1">`,
    body: `${body}`,
    css: `${cssLink}`,
    lang: `${language}`,
  });
Enter fullscreen mode Exit fullscreen mode

By doing so, now user can specify the language in which they want the created HTML document used.

  • Modification for the second change - working on branch issue-20: Adding support for Markdown file is much easier cause I just need to use appropriate regex inside a replace function then it will do the rest for me.

In readMDFile.js

      .replace(/`([^`].*?)`/gim, "<code>$1</code>") // Search for all occurences of Inline code and replace them with the corresponding <code> tags.
      .replace(/---\r?\n/gim, "<hr>") // Search for all occurences of horizontal rules and replace them with the corresponding <hr> tag.


Enter fullscreen mode Exit fullscreen mode

3. Merging branches

  • First commit 8a6bbe using git merge issue19
  • Second commit 159b3d using git merge issue20

Fortunately, there was no conflict between two commits so merging them to the main branch was totally smooth.

4. Overall

This lab is a good practice for me to work on different branches. Sometimes, when coding a project I forget to check which branch I am currently in. As a result, I usually messed up my code and that's terrible. Besides, working with merging was a truly interesting experience.

All in all, thank for spending time reading this post.
Happy coding!

Top comments (0)