Skip to content

Commit 6dedd96

Browse files
author
Akansh
committed
feat(install.sh): Script to install git commit-semantics aliases
0 parents  commit 6dedd96

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<p align="center">
2+
<a href="https://github.com/akanshgulati/commit-semantics" align="center">
3+
<img src="commit-semantics-banner.jpg" alt="commit-semantics" align="center" />
4+
</a>
5+
</p>
6+
7+
# Commit-Semantics
8+
9+
Inspired by Angular JS's committing style as on [github](https://github.com/angular/angular/commits/master), this project installs git aliases of various commit message type and helps in creating a standard of committing format.
10+
11+
## Introduction
12+
These are **custom git commands** that encourages the git user to write formatted git commit messages. These aliases will standardised git commits.
13+
14+
e.g. ```git feat install.sh 'Added commit semantics aliases'``` -> ```git commit -m 'feat(install.sh): Added commit semantics aliases'```
15+
16+
More shorter way possible now:
17+
18+
e.g. ```gf feat install.sh 'Added commit semantics aliases'``` -> ```git commit -m 'feat(install.sh): Added commit semantics aliases'```
19+
## Installation
20+
21+
1. Clone this repo, preferably in your $HOME directory. ```git clone [email protected]:akanshgulati/commit-semantics.git
22+
~/.commit-semantics```
23+
24+
25+
2. Install it as git aliases:
26+
```cd ~/.commit-semantics && chmod 755 install.sh && ./install.sh```
27+
28+
Tip: You can check if aliases are created in `~/.gitconfig` file respectively. Aliases will be created only if no respective alias is present in `~/.gitconfig` file
29+
30+
3. Ready to use.
31+
32+
## Usage
33+
34+
Once you install, you can have 10 git aliases.
35+
36+
Git alias -> Actual command
37+
38+
* ```git feat <scope> "commit-message-here"``` -> ```git commit -m 'feat(<scope>): commit-message-here'```
39+
* ```git docs <scope> "commit-message-here"``` -> ```git commit -m 'docs(<scope>): commit-message-here'```
40+
* ```git chore <scope> "commit-message-here"``` -> ```git commit -m 'chore(<scope>): commit-message-here'```
41+
* ```git fix <scope> "commit-message-here"``` -> ```git commit -m 'fix(<scope>): commit-message-here'```
42+
* ```git refactor <scope> "commit-message-here"``` -> ```git commit -m 'refactor(<scope>): commit-message-here'```
43+
* ```git style <scope> "commit-message-here"``` -> ```git commit -m 'style(<scope>): commit-message-here'```
44+
* ```git test <scope> "commit-message-here"``` -> ```git commit -m 'test(<scope>): commit-message-here'```
45+
* ```git perf <scope> "commit-message-here"``` -> ```git commit -m 'perf(<scope>): commit-message-here'```
46+
* ```git cleanup <scope> "commit-message-here"``` -> ```git commit -m 'cleanup(<scope>): commit-message-here'```
47+
* ```git tracking <scope> "commit-message-here"``` -> ```git commit -m 'tracking(<scope>): commit-message-here'```
48+
49+
## Guidelines
50+
### Selecting `type`
51+
Different types of `type` are there according to make sure one can get idea about the core reason of commit message. Current script supports following types of commits.
52+
53+
* **feat**: Commits related to a new feature developed
54+
* **fix**: Commits related a bug fix
55+
* **style**: Commits related to styling in .css, .scss, .etc files.
56+
* **cleanup**: Commits related to changes that do not affect the logic of the code (white-space, formatting, missing
57+
semi-colons, dead code removal, etc.)
58+
* **refactor**: Commits related to changes that neither fixes a bug nor adds a feature but is used for restructuring the code
59+
* **perf**: Commits related to changes that improves performance
60+
* **test**: Commits related to adding missing tests or fixing them
61+
* **chore**: Commits related to changes in build process, auxiliary tools and libraries such as documentation
62+
generation
63+
* **tracking**: Commits related to any kind of tracking which includes bug tracking, user tracking, analytics, etc.
64+
* **docs**: Commits related to documentation changes, such as Readme.md file
65+
66+
### Selecting `scope`
67+
68+
The scope in commit message could be anything specifying context of the commit change. A scope context can be a `module`,
69+
`fileName`, `serviceName`, `directiveName`, `functionName` , `impactArea`, etc.
70+
71+
## Example
72+
73+
##### **Command**:
74+
git refactor header 'change z-index'
75+
##### **Output**:
76+
git commit -m "refactor(header): change z-index"
77+
78+

commit-semantics-banner.jpg

118 KB
Loading

install.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Register semantic commits git aliases
4+
#
5+
# $1 — git alias and semantic message prefix
6+
# [$2] — (optional) custom semantic message prefix
7+
function make_git_alias {
8+
if ! git config --global --get-all alias.$1 &>/dev/null; then
9+
if [[ -z $2 ]]; then
10+
git config --global alias.$1 '!f() { [[ -z "$GIT_PREFIX" ]] || cd "$GIT_PREFIX" && if [[ -z $1 ]] && [[-z $2]]; then git commit -m "'$1' " -e; else git commit -m "'$1'($1): $2"; fi }; f'
11+
else
12+
git config --global alias.$1 '!f() { [[ -z "$GIT_PREFIX" ]] || cd "$GIT_PREFIX" && if [[ -z $1 ]]; then git commit -m "'$2': " -e; else git commit -m "'$2': $1"; fi }; f'
13+
fi
14+
fi
15+
}
16+
# Register aliases
17+
echo 'Installing git aliases…'
18+
19+
semantic_aliases=( 'feat' 'fix' 'style' 'cleanup' 'refactor' 'perf' 'test' 'chore' 'tracking' 'docs' )
20+
21+
for semantic_alias in "${semantic_aliases[@]}"; do
22+
echo 'Installing git alias ' $semantic_alias
23+
make_git_alias $semantic_alias
24+
done

0 commit comments

Comments
 (0)