Skip to content

Commit fc9ec21

Browse files
committed
adjusted syntax in git-up
1 parent f9e6ac8 commit fc9ec21

7 files changed

+47
-42
lines changed

.gitignore

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
2-
.dccache
2+
.dccache
3+
*.log

.prettierignore

100644100755
File mode changed.

README.md

100644100755
File mode changed.

git-lc

100644100755
File mode changed.

git-up

100644100755
+45-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
print_usage(){
1+
print_usage() {
22
echo 'Usage: git-up [-flags] <remote-branch-name> "commit message"\n' 2>&1
33
echo ' git-up - add all files, commit with a meassage and push the current branch to a <remote-branch-name>.'
44
echo ' "commit message" - message assigned to the commit'
@@ -17,58 +17,63 @@ debugginMode='OFF'
1717

1818
while getopts ':hpsd' flag; do
1919
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
3428
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
3540
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+
;;
5257
esac
5358
done
5459

5560
if [[ $isFlagged == 'true' ]]; then
5661
shift
5762
fi
5863

59-
if [ ${#} -lt 1 -a $isFlagged == 'false' ]; then
64+
if [[ ${#} -lt 1 && $isFlagged == 'false' ]]; then
6065
echo "Error: must specify flags/arguments.\n" >&2
6166
print_usage
6267
return 1
6368
fi
6469

65-
if [ $isFlagged == 'false' -a ${#} -lt 2 ]; then
70+
if [[ ${#} -lt 2 && $isFlagged == 'false' ]]; then
6671
echo 'Error: must provide <remote-branch-name> and "message".\n'
6772
print_usage
6873
return 1
6974
fi
7075

71-
if [ $isFlagged == 'false' -a ${#} -eq 2 ]; then
76+
if [[ $isFlagged == 'false' && ${#} -eq 2 ]]; then
7277
remoteBranchName=${1}
7378
message=${2}
7479
fi
@@ -87,13 +92,12 @@ if [[ $debugginMode == 'ON' ]]; then
8792
fi
8893

8994
git add . -v
90-
if [ $useLastCommit == 'false' ]; then
95+
if [[ $useLastCommit == 'false' ]]; then
9196
git commit -m "$message"
9297
fi
9398

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

scaffold-js-practice

100644100755
File mode changed.

upgrade-all

100644100755
File mode changed.

0 commit comments

Comments
 (0)