Skip to content

Commit c9cfd19

Browse files
author
Dexter Industries
authored
Merge pull request #7 from CleoQc/master
new fct: change_branch() and a fix in file_exists_in_folder()
2 parents 7b1155c + 51db635 commit c9cfd19

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

functions_library.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ feedback() {
3737
echo -e "$(tput setaf 3)$1$(tput sgr0)"
3838
}
3939

40+
# Function checks out branch if BRANCH is defined.
41+
change_branch() {
42+
# first and only parameter is the branch to checkout
43+
44+
# -z tests for zero length.
45+
if [ -z ${1+x} ]; then
46+
echo "Working from main branch.";
47+
else
48+
echo "Working from $1 branch";
49+
# sudo git checkout -b $BRANCH
50+
# the -b creates a branch if it doesn't exist
51+
# this leads to a fatal error msg being displayed to the user
52+
# is there any case where we can to create the branch here???
53+
# https://github.com/tldr-pages/tldr/blob/master/pages/common/git-checkout.md
54+
sudo git checkout $1
55+
fi
56+
}
57+
4058
#########################################################################
4159
#
4260
# FILE EDITION
@@ -135,9 +153,9 @@ file_exists_in_folder(){
135153
# can only be run using bash, not sh
136154
# first argument: file to look for
137155
# second argument: folder path
138-
pushd $2
139-
status = file_exists
140-
popd
156+
pushd $2 > /dev/null
157+
status = file_exists $1
158+
popd > /dev/null
141159
return status
142160
}
143161

0 commit comments

Comments
 (0)