DEV Community

Cover image for My repo has branches...and their branches have branches.
Andre Willomitzer
Andre Willomitzer

Posted on

My repo has branches...and their branches have branches.

git -b branchesAhoy

This week in OSD600 we went back to contributing to our own Static Site Generators. We had to pick 2 additional features to implement. For my repository textToHTML_V2 I decided to pick:

  • Make sure the program exits with proper exit codes in all cases. An additional issue I fixed while doing so is my error messages are more descriptive instead of "throw error". Exit Codes Error Messaging
  • Allow the user to specify a "lang" attribute for the HTML tag from the CLI using --lang or -l. Lang Issue

As the heading suggests, to do these updates I made 2 separate feature branches using

git -b <branchname>.

Once all the changes on a branch were finished I would git add/commit.

The first feature I implemented was the --lang option for the CLI. If the user specifies --lang fr it will generate the HTML document with an html tag "lang" attribute of "fr" for French. The default is en_CA which is Canadian English.

How I did this was using a ternary expression to see if the user had added --lang flag. This is done by Yargs ".option()" method. If they do, I change my HTML markup to use the ${argv.lang} value in the "lang" attribute. Otherwise, use en-CA which could be switched for another default.
--Lang Commit

`<html lang="${argv.l ? argv.l : "en-CA"}">\n
<head> \n
<meta charset="utf-8">\n
<meta name="viewport" content="width=device-width, initial-scale=1">` 
+ `\n</head>\n<body>` 
+ `${html}` 
+ `\n</body>\n</html>`;
Enter fullscreen mode Exit fullscreen mode

The second feature I decided to implement was mostly because it helps clean up my code via better error messages and exit codes. This will help with debugging since I will know which part of the program triggered the error.

I did this by changing the error messages from "throw error" to console.log("Unable to read directory"), and other messages. At the same time, I added process.exitCode = -1; to my error catching so that the terminal would print out the exit code using process.on('exit') at the end of my program. By doing this I added more helpful messaging for users and exit codes for my own benefit later on.
Error/ExitCode Commit

git merge

After the branches were done and both were committed, I merged them. Luckily, because my program is structured well I did not have to change anything in the same places in both branches. So when the time came to commit I didn't have any merge conflicts.

git push origin main

Since the merges were successful and I tested the options afterwards I pushed to the main repo.

In this lab I learned about merging multiple branches for different features. Because of that I did a lot of reading about what could cause a merge conflict in case I ran across one. In the future I can see this knowledge being very useful and so I wouldn't do anything different this time around!

Discussion (0)