Skip to content

Commit 24b291d

Browse files
authored
✨ added better logic checks for handling adding remotes and stashes (#7)
This is related to issue improvement: more logic checks for skipping steps #4 This PR mostly focuses on removing error messages from action happenig that didn't neeed to. I started with focusing on stash and add/remove of remote devops This fixes #5 improvement: organize reduce add/removes of remote
1 parent 8569a85 commit 24b291d

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

wp-git-sync.sh

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,94 @@ set_defaults() {
1616
fi
1717
}
1818

19+
is_stashes() {
20+
output=$(git stash list )
21+
case $1 in
22+
check) stashes=0;;
23+
esac
24+
case $output in
25+
*+"stash"*)
26+
stashes=1;;
27+
esac
28+
}
29+
1930
rm_devops_remote() {
2031
git remote rm devops 2>&1
2132
print_status_msg "Remote devops removed"
2233
git remote -v 2>&1
23-
echo "end rm_devops_remote"
2434
}
2535

2636
add_devops_remote() {
27-
rm_devops_remote
2837
git remote add devops "https://${TOKENUSER}:${TOKEN}@${GITREPO}" 2>&1
2938
print_status_msg "Remote devops addded"
3039
git remote -v 2>&1
3140
}
3241

42+
add_or_remove_devops() {
43+
output=$(git remote )
44+
case $output in
45+
*+devops*)
46+
remoteAdded=0;;
47+
*)
48+
remoteAdded=1;;
49+
esac
50+
case $1 in
51+
add)
52+
if [ $remoteAdded -eq 0 ] ; then
53+
add_devops_remote
54+
fi;;
55+
rm)
56+
if [ $remoteAdded -eq 0 ] ; then
57+
rm_devops_remote
58+
fi;;
59+
esac
60+
}
61+
62+
git_stash() {
63+
is_stashes "check"
64+
if [ "$stashes" -eq 1 ] ; then
65+
case $1 in
66+
clear)
67+
git stash clear 2>&1;;
68+
pop)
69+
git stash pop 2>&1;;
70+
u)
71+
git stash -u 2>&1;;
72+
*)
73+
git stash 2>&1;;
74+
esac
75+
fi
76+
return
77+
}
78+
3379
merge_from_devops() {
3480
git merge "${DEVBRANCH}" 2>&1
3581
git branch -D "${DEVBRANCH}" 2>&1
3682
}
3783

3884
pull_from_devops() {
39-
add_devops_remote
40-
git stash clear 2>&1
41-
git stash -u 2>&1
85+
add_or_remove_devops "add"
86+
git_stash "clear"
87+
git_stash "u"
4288
git remote update 2>&1
4389
git checkout "${DEVBRANCH}" 2>&1
4490
git pull devops "${DEVBRANCH}" 2>&1
4591
git checkout "${BRANCH}" 2>&1
4692
git pull devops "${BRANCH}" 2>&1
4793
merge_from_devops
48-
git stash pop 2>&1
94+
git_stash "pop"
4995
commit_git
50-
rm_devops_remote
96+
add_or_remove_devops "rm"
5197
print_status_msg "pull_from_dev function was executed successfully."
5298
}
5399

54100
push_to_devops() {
55101
# code
56102
pull_from_devops
57-
add_devops_remote
103+
add_or_remove_devops "add"
58104
git push devops "$BRANCH" 2>&1
59105
print_status_msg "push_to_dev function was executed successfully."
60-
rm_devops_remote
106+
add_or_remove_devops "rm"
61107
}
62108

63109
print_status_msg() {

0 commit comments

Comments
 (0)