summaryrefslogtreecommitdiffstats
path: root/SOURCE/CORE
diff options
context:
space:
mode:
authordanix <danix@danix.xyz>2023-04-13 15:27:16 +0200
committerdanix <danix@danix.xyz>2023-04-13 15:27:16 +0200
commit4cbcb39e2007338c1c6ec17376c14b841ce6f733 (patch)
tree18593d0254d253bcdd711581465db828f30fadb7 /SOURCE/CORE
parent6a1930959e1cb0ec8739254bedc6b8de2bcc20fd (diff)
downloadbash-notes-4cbcb39e2007338c1c6ec17376c14b841ce6f733.tar.gz
bash-notes-4cbcb39e2007338c1c6ec17376c14b841ce6f733.zip
initial setup of git functionality. The program can now initalize a local repo and add a remote.
Diffstat (limited to 'SOURCE/CORE')
-rw-r--r--SOURCE/CORE/git.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/SOURCE/CORE/git.sh b/SOURCE/CORE/git.sh
new file mode 100644
index 0000000..d37fe72
--- /dev/null
+++ b/SOURCE/CORE/git.sh
@@ -0,0 +1,38 @@
+# returns true if the argument provided directory is a git repository
+is_git_repo() {
+ DIR=$1
+ if [[ -d $DIR ]]; then
+ cd $DIR
+ if git rev-parse 2>/dev/null; then
+ true
+ else
+ false
+ fi
+ fi
+}
+
+# sync local repository to remote
+gitsync() {
+ echo "Syncing notes with git on remote \"$GITREMOTE\""
+ cd $BASEDIR
+ $GIT pull
+}
+
+# check for USEGIT and subsequent variables
+if [[ $USEGIT && -n $GITREMOTE ]]; then
+ # GIT is a go.
+ if ! is_git_repo $BASEDIR; then
+ # initializing git repository
+ cd $BASEDIR
+ $GIT init
+ echo "adding all files to git"
+ $GIT add .
+ $GIT commit -m "$(basename $0) - initial commit"
+ $GIT remote add origin $GITREMOTE
+ $GIT push -u origin master
+ fi
+elif [[ $USEGIT && -z $GITREMOTE ]]; then
+ echo "GITREMOTE variable not set. reverting USEGIT to false"
+ USEGIT=false
+fi
+