My repo has branches...and their branches have branches.
Tags: opensource
Published: 2021-10-01 18:58:08

#### 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](https://github.com/AndreWillomitzer/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](https://github.com/AndreWillomitzer/textToHTML_V2/issues/13)
[Error Messaging](https://github.com/AndreWillomitzer/textToHTML_V2/issues/4)
* Allow the user to specify a "lang" attribute for the HTML tag from the CLI using --lang or -l.
[Lang Issue](https://github.com/AndreWillomitzer/textToHTML_V2/issues/12)

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](https://github.com/AndreWillomitzer/textToHTML_V2/commit/a29de75d9b266bfc4af5ba8915d1cef493e01c28)
```
`<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>`;
```

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](https://github.com/AndreWillomitzer/textToHTML_V2/commit/5537676dcd2c77972ce1e901242dcf0b12819a6c)

#### 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!