Skip to content

Commit 25269f9

Browse files
authored
Merge pull request #2 from justcoded/develop
First release
2 parents ce5767b + 6b57fe8 commit 25269f9

15 files changed

+511
-1
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
# tabs 4 spaces for makefiles
15+
[Makefile]
16+
indent_size = 4
17+
indent_style = tab
18+
[*.mk]
19+
indent_size = 4
20+
indent_style = tab

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# phpstorm/netbeans/eclipse project files
2+
.idea
3+
.vscode
4+
nbproject
5+
.buildpath
6+
.project
7+
.settings
8+
9+
# windows/Mac thumbnail cache
10+
Thumbs.db
11+
.DS_Store

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--- BEGIN HEADER -->
2+
# Changelog
3+
4+
All notable changes to this project will be documented in this file.
5+
6+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8+
9+
---
10+
<!--- END HEADER -->
11+
12+
## [1.0.0]() (2022-05-09)
13+
### Features
14+
15+
* `browse` command
16+
* `jc-config` command
17+
* `jc-feature` command
18+
* `jc-hotfix` command
19+
* `lk-feature` command
20+
* `lk-epic` command
21+
* `lk-hotfix` command

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.PHONY: default install
2+
3+
default:
4+
@echo 'Git extras installation helper from JustCoded'
5+
6+
install:
7+
sudo cp -f ./bin/* /usr/local/bin/
8+
sudo chmod +x /usr/local/bin/git-*

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# git-extras
1+
# Custom git commands
2+
3+
## Requirements
4+
5+
* make utility
6+
* sudo access to be able to complete the installation
7+
8+
## Installation
9+
10+
* Clone the repository to some folder
11+
* To install/update git extra commands just run
12+
13+
```bash
14+
make install
15+
```
16+
17+
## Commands reference
18+
19+
| Command | Description |
20+
|-------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
21+
| `git browse` | Opens remote repository URL in browser. Taken from [git-extras](https://github.com/tj/git-extras). |
22+
| `git jc-config` | Configures repository with default global filemode (or 'false' by default) and push strategy. |
23+
| `git jc-gitflow` | Creates if not exists `develop`/`release` branches or sync them. |
24+
| `git jc-feature <shortDescription>` | Defines git branching flow ("gitflow" or "feature branch") and creates Feature branch from the right branch (develop or main/master) |
25+
| `git jc-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
26+
| `git lk-feature <shortDescription>` | Creates Feature branch from `release`. |
27+
| `git lk-epic <shortDescription>` | Creates Epic branch from `release`. |
28+
| `git lk-hotfix <shortDescription>` | Creates Hotfix branch from `main`/`master` branch. |
29+

bin/git-browse

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $1 == "" ]]
4+
then
5+
branch=$(git rev-parse --abbrev-ref HEAD 2&> /dev/null)
6+
remote=$(git config branch."${branch}".remote || echo "origin")
7+
else
8+
remote=$1
9+
fi
10+
11+
if [[ $remote == "" ]]
12+
then
13+
echo "Remote not found"
14+
exit 1
15+
fi
16+
17+
remote_url=$(git remote get-url $remote)
18+
19+
if [[ $? -ne 0 ]]
20+
then
21+
exit $?
22+
fi
23+
24+
if [[ $remote_url = git@* ]]
25+
then
26+
url=$(echo $remote_url | sed -E -e 's/:/\//' -e 's/\.git$//' -e 's/.*@(.*)/http:\/\/\1/')
27+
elif [[ $remote_url = http* ]]
28+
then
29+
url=${remote_url%.git}
30+
fi
31+
32+
case "$OSTYPE" in
33+
darwin*)
34+
# MacOS
35+
open $url
36+
;;
37+
msys)
38+
# Git-Bash on Windows
39+
start $url
40+
;;
41+
linux*)
42+
# Handle WSL on Windows
43+
if uname -a | grep -i -q Microsoft && command -v powershell.exe
44+
then
45+
powershell.exe -NoProfile start $url
46+
else
47+
xdg-open $url
48+
fi
49+
;;
50+
*)
51+
# fall back to xdg-open for BSDs, etc.
52+
xdg-open $url
53+
;;
54+
esac

bin/git-jc-branch

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
3+
function safeExit() {
4+
exit 0
5+
}
6+
7+
function error() {
8+
exit 1;
9+
}
10+
11+
############## Default values ###################
12+
scriptName="git jc-branch"
13+
scriptArgs="<shortDescription>"
14+
namePrefix=feature/
15+
parentBranch=develop
16+
args=()
17+
18+
19+
############## Main Script Here ###################
20+
21+
function handle() {
22+
23+
if [ -z "${args[0]}" ]
24+
then
25+
echo -e 'ERROR! Issue short description is missing.\n';
26+
usage;
27+
error;
28+
fi;
29+
30+
echo 'Fetching remote changes...';
31+
git fetch;
32+
33+
branchName="${namePrefix}${args[0]}";
34+
35+
echo '---------------------------------------';
36+
echo "Creating [${branchName}] branch of [origin/${parentBranch}]...";
37+
git switch -c ${branchName} origin/${parentBranch};
38+
39+
echo '---------------------------------------';
40+
echo 'Push and set it upstream...';
41+
git push --set-upstream origin ${branchName};
42+
43+
}
44+
45+
############## Begin Options and Usage ###################
46+
47+
# Print usage
48+
usage() {
49+
echo -n "${scriptName} [OPTIONS] ${scriptArgs}
50+
51+
Creates feature branch off of origin/develop.
52+
53+
Options:
54+
-h, --help Display this help and exit
55+
-p, --prefix Branch name prefix, default 'feature/'
56+
-s, --src Parent branch
57+
"
58+
}
59+
60+
# Iterate over options breaking -ab into -a -b when needed and --foo=bar into
61+
# --foo bar
62+
optstring=h
63+
unset options
64+
while (($#)); do
65+
case $1 in
66+
# If option is of type -ab
67+
-[!-]?*)
68+
# Loop over each character starting with the second
69+
for ((i=1; i < ${#1}; i++)); do
70+
c=${1:i:1}
71+
72+
# Add current char to options
73+
options+=("-$c")
74+
75+
# If option takes a required argument, and it's not the last char make
76+
# the rest of the string its argument
77+
if [[ $optstring = *"$c:"* && ${1:i+1} ]]; then
78+
options+=("${1:i+1}")
79+
break
80+
fi
81+
done
82+
;;
83+
84+
# If option is of type --foo=bar
85+
--?*=*) options+=("${1%%=*}" "${1#*=}") ;;
86+
# add --endopts for --
87+
--) options+=(--endopts) ;;
88+
# Otherwise, nothing special
89+
*) options+=("$1") ;;
90+
esac
91+
shift
92+
done
93+
set -- "${options[@]}"
94+
unset options
95+
96+
# Print help if no arguments were passed.
97+
# Uncomment to force arguments when invoking the script
98+
# [[ $# -eq 0 ]] && set -- "--help"
99+
100+
# Read the options and set stuff
101+
while [[ $1 = -?* ]]; do
102+
case $1 in
103+
-h|--help) usage >&2; safeExit ;;
104+
-p|--prefix) shift; namePrefix=${1} ;;
105+
-s|--src) shift; parentBranch=${1} ;;
106+
--endopts) shift; break ;;
107+
*) die "invalid option: '$1'." ;;
108+
esac
109+
shift
110+
done
111+
112+
# Store the remaining part as arguments.
113+
args+=("$@")
114+
115+
############## End Options and Usage ###################
116+
117+
118+
############## Script Run Code ###################
119+
120+
# Set IFS to preferred implementation
121+
IFS=$'\n\t'
122+
123+
# Exit on error. Append '||true' when you run the script if you expect an error.
124+
set -o errexit
125+
126+
# Bash will remember & return the highest exitcode in a chain of pipes.
127+
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`, for example.
128+
set -o pipefail
129+
130+
# Run your script
131+
handle
132+
133+
# Exit cleanly
134+
safeExit

bin/git-jc-config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
echo 'Updating git configurations...';
4+
5+
# get global defined config
6+
filemode=$(git config --global core.filemode)
7+
# set default as 'false' if not defined.
8+
if [ -z "${filemode}" ]
9+
then
10+
filemode='false'
11+
fi;
12+
git config core.filemode ${filemode};
13+
echo " set tracking filemode changes to [${filemode}]";
14+
15+
git config push.default simple;
16+
echo " set simple push strategy";
17+
18+
echo "Done.";

bin/git-jc-feature

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
devBranchSearch=$(git branch -r | grep origin/develop)
4+
if [ -n "${devBranchSearch}" ]
5+
then
6+
echo 'Found [origin/develop] branch, using "Gitflow" workflow!';
7+
echo '---------------------------------------';
8+
git jc-branch -p feature/ -s develop "$@";
9+
exit 0;
10+
fi;
11+
12+
echo 'NOT FOUND [origin/develop] branch, using "Feature branch" workflow!';
13+
echo '---------------------------------------';
14+
15+
# define main branch name: main|master
16+
mainBranch=master
17+
mainBranchSearch=$(cat .git/config | grep "branch\s\"${mainBranch}\"")
18+
19+
if [ -z "${mainBranchSearch}" ]
20+
then
21+
mainBranch=main;
22+
fi;
23+
24+
echo "Found maturity branch [${mainBranch}]";
25+
echo '---------------------------------------';
26+
27+
git jc-branch -p feature/ -s ${mainBranch} "$@";
28+
exit 0;

bin/git-jc-gitflow

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
3+
git fetch;
4+
5+
echo 'Initializing gitflow long-live branches...';
6+
7+
# define main branch name: main|master
8+
mainBranch=master
9+
mainBranchSearch=$(cat .git/config | grep "branch\s\"${mainBranch}\"")
10+
11+
if [ -z "${mainBranchSearch}" ]
12+
then
13+
mainBranch=main;
14+
fi;
15+
16+
echo " find maturity branch [${mainBranch}]";
17+
18+
# find develop branch
19+
echo '-----------------------------------------------';
20+
echo 'Checking develop branch...';
21+
22+
devBranchSearch=$(git branch -r | grep origin/develop)
23+
if [ -z "${devBranchSearch}" ]
24+
then
25+
git switch -c develop origin/${mainBranch};
26+
git push --set-upstream origin develop
27+
echo ' created integration branch [develop]';
28+
else
29+
echo ' found integration branch [origin/develop], syncing...';
30+
git switch develop;
31+
git pull;
32+
fi;
33+
34+
# find release branch
35+
echo '-----------------------------------------------';
36+
echo 'Checking release branch...';
37+
38+
rcBranchSearch=$(git branch -r | grep origin/release)
39+
if [ -z "${rcBranchSearch}" ]
40+
then
41+
git switch -c release origin/develop;
42+
git push --set-upstream origin release
43+
echo ' created release candidate branch [release]';
44+
else
45+
echo ' found release candidate branch [origin/release], syncing...';
46+
git switch release;
47+
git pull;
48+
fi;
49+
50+
# switch to develop
51+
echo '-----------------------------------------------';
52+
echo 'Finalizing...';
53+
54+
echo ' switching to develop.';
55+
git switch develop;
56+
57+
echo 'Done.';

0 commit comments

Comments
 (0)