1
- print_usage(){
1
+ print_usage() {
2
2
echo 'Usage: git-up [-flags] <remote-branch-name> "commit message"\n' 2>&1
3
3
echo ' git-up - add all files, commit with a meassage and push the current branch to a <remote-branch-name>.'
4
4
echo ' "commit message" - message assigned to the commit'
@@ -17,58 +17,63 @@ debugginMode='OFF'
17
17
18
18
while getopts ':hpsd' flag; do
19
19
case "${flag}" in
20
- h)
21
- print_usage
22
- return 0;;
23
- p)
24
- isFlagged='true'
25
- useLastCommit='true'
26
- if [[ ${1} =~ 's' ]]; then
27
- remoteBranchName=$(git branch | awk '$0 ~ /\*/ { print $2}')
28
- else
29
- remoteBranchName=${2}
30
- fi;;
31
- s)
32
- isFlagged='true'
33
- sameBranch='true'
20
+ h)
21
+ print_usage
22
+ return 0
23
+ ;;
24
+ p)
25
+ isFlagged='true'
26
+ useLastCommit='true'
27
+ if [[ ${1} =~ 's' ]]; then
34
28
remoteBranchName=$(git branch | awk '$0 ~ /\*/ { print $2}')
29
+ else
30
+ remoteBranchName=${2}
31
+ fi
32
+ ;;
33
+ s)
34
+ isFlagged='true'
35
+ sameBranch='true'
36
+ remoteBranchName=$(git branch | awk '$0 ~ /\*/ { print $2}')
37
+ if [[ ${1} =~ 'p' ]]; then
38
+ useLastCommit='true'
39
+ else
35
40
message=${2}
36
- if [[ ${1} =~ 'p' ]];then
37
- useLastCommit='true'
38
- fi
39
- if [ ${#} -lt 2 -a $useLastCommit == 'false' ];
40
- then
41
- echo "Error: $1 flag must have a 'commit message' or use with -p flag" >&2
42
- message=
43
- return 1
44
- fi;;
45
- d)
46
- isFlagged='true'
47
- debugginMode='ON';;
48
- *)
49
- printf "Invalid option: -${OPTARG}.\n\n" >&2
50
- print_usage
51
- return 1 ;;
41
+ fi
42
+ if [[ ${#} -lt 2 && $ useLastCommit == 'false' ]]; then
43
+ echo "Error: $1 flag must have a 'commit message' or use with -p flag" >&2
44
+ message=
45
+ return 1
46
+ fi
47
+ ;;
48
+ d)
49
+ isFlagged='true'
50
+ debugginMode='ON'
51
+ ;;
52
+ *)
53
+ printf "Invalid option: -${OPTARG}.\n\n" >&2
54
+ print_usage
55
+ return 1
56
+ ;;
52
57
esac
53
58
done
54
59
55
60
if [[ $isFlagged == 'true' ]]; then
56
61
shift
57
62
fi
58
63
59
- if [ ${#} -lt 1 -a $isFlagged == 'false' ]; then
64
+ if [[ ${#} -lt 1 && $isFlagged == 'false' ] ]; then
60
65
echo "Error: must specify flags/arguments.\n" >&2
61
66
print_usage
62
67
return 1
63
68
fi
64
69
65
- if [ $isFlagged == 'false' -a $ {#} -lt 2 ]; then
70
+ if [[ $ {#} -lt 2 && $isFlagged == 'false' ] ]; then
66
71
echo 'Error: must provide <remote-branch-name> and "message".\n'
67
72
print_usage
68
73
return 1
69
74
fi
70
75
71
- if [ $isFlagged == 'false' -a ${#} -eq 2 ]; then
76
+ if [[ $isFlagged == 'false' && ${#} -eq 2 ] ]; then
72
77
remoteBranchName=${1}
73
78
message=${2}
74
79
fi
@@ -87,13 +92,12 @@ if [[ $debugginMode == 'ON' ]]; then
87
92
fi
88
93
89
94
git add . -v
90
- if [ $useLastCommit == 'false' ]; then
95
+ if [[ $useLastCommit == 'false' ] ]; then
91
96
git commit -m "$message"
92
97
fi
93
98
94
- if [[ $sameBranch == 'true' ]];
95
- then
96
- git push origin $remoteBranchName:$remoteBranchName
97
- else
98
- git push origin `git branch | awk '{print $2}'`:$remoteBranchName
99
- fi
99
+ if [[ $sameBranch == 'true' ]]; then
100
+ git push origin $remoteBranchName:$remoteBranchName
101
+ else
102
+ git push origin $(git branch | awk '{print $2}'):$remoteBranchName
103
+ fi
0 commit comments