initial setup of git functionality. The program can now initalize a local repo and...
[bash-notes.git] / SOURCE / CORE / git.sh
1 # returns true if the argument provided directory is a git repository
2 is_git_repo() {
3 DIR=$1
4 if [[ -d $DIR ]]; then
5 cd $DIR
6 if git rev-parse 2>/dev/null; then
7 true
8 else
9 false
10 fi
11 fi
12 }
13
14 # sync local repository to remote
15 gitsync() {
16 echo "Syncing notes with git on remote \"$GITREMOTE\""
17 cd $BASEDIR
18 $GIT pull
19 }
20
21 # check for USEGIT and subsequent variables
22 if [[ $USEGIT && -n $GITREMOTE ]]; then
23 # GIT is a go.
24 if ! is_git_repo $BASEDIR; then
25 # initializing git repository
26 cd $BASEDIR
27 $GIT init
28 echo "adding all files to git"
29 $GIT add .
30 $GIT commit -m "$(basename $0) - initial commit"
31 $GIT remote add origin $GITREMOTE
32 $GIT push -u origin master
33 fi
34 elif [[ $USEGIT && -z $GITREMOTE ]]; then
35 echo "GITREMOTE variable not set. reverting USEGIT to false"
36 USEGIT=false
37 fi
38