This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions-git
executable file
·90 lines (78 loc) · 2.8 KB
/
functions-git
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
############
# GIT HELPER FUNCTIONS
# dependencies:
# -- REPOS variable; from bash_profile
# an array of valid project repositories
# -- getMaster function required; from bash_profile
# returns repo-specific master branch
# -- getRepo function required; from functions-dev
# returns name of current repository
# -- getIndex function required; from functions-dev
# returns index of the provided search string in passed array
############
# Check for dependencies
test -f git-completion && . $_
test -f functions-dev && . $_
function currbranch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
# Add and stash any WIP
function gitclean {
git add . && git stash
}
# Get the branch name from function input or prompt
function getBranch {
[[ $# > 0 ]] && branch=$1 || read -p "Branch name: " branch
echo $branch
}
# Checkout an existing branch
function co {
branch=$(getBranch $1)
gitclean && git checkout $(getMaster) && git fetch && git pull origin $(getMaster)
git checkout $branch && git pull origin $branch
}
# Get the branch name from function input or prompt
function rmbranch {
for var in "$@"; do
echoCmd echo "Kill branch local and remote: $var" && git branch -D $var && git push origin :$var
done
}
function push {
# save the commit message if passed in
msg="${*}"
repo=$(getRepo)
# Check if there are changes to commit
#[[ ! $(git status | grep "Changes") ]] && echo "No commit changes to push." && git push && return
proj=
old=$IFS
while IFS='-' read -a seg; do
# grep for task/story/incident info
if [[ $(getIndex $repo ${REPOS[@]}) -gt -1 ]]; then
[[ $seg =~ (US|TASK|INC)[[:digit:]]+ ]] && proj="$seg" || read -e -p "Please enter the user story if available: " proj || proj="dev"
proj="[${proj}]: "
fi
done <<< $(currbranch)
IFS=$old
if [[ $( pwd | grep -i "webux" ) || $( pwd | grep -i "webrh" ) ]]; then
grunt lint && [ -z $msg ] && read -e -p "Describe commit - ${proj}" msg && git commit -a -m "${proj}${msg}" && git push origin $(currbranch)
else
[ -z $msg ] && read -e -p "Describe commit - ${proj}" msg && git commit -a -m "${proj}${msg}" && git push origin $(currbranch)
fi
}
function fork {
# Clean current branch then get the latest version
git pull origin $(currbranch)
# Get branch name
branch=$(getBranch $1)
# Create the new branch and tracking branch against origin
git checkout -b $branch && git push -u origin $branch
}
function newbranch {
# Clean current branch, then checkout master and get latest
gitclean && git checkout $(getMaster) && git pull origin $(getMaster)
# Get branch name
branch=$(getBranch $1)
# Create the new branch and tracking branch against origin
git checkout -b $branch && git push -u origin $branch
}