diff options
| author | danix <danix@danix.xyz> | 2023-04-18 07:10:03 +0200 |
|---|---|---|
| committer | danix <danix@danix.xyz> | 2023-04-18 07:10:03 +0200 |
| commit | 1f4d77422386502ce5a67b101be6d6f16eff2175 (patch) | |
| tree | 493fc8964eb93331951f81af5c797988cc1a325d /SOURCE/CORE/git.sh | |
| parent | bba0734fdb0ddeea845a8534b24daf13cbda9d1d (diff) | |
| download | bash-notes-1f4d77422386502ce5a67b101be6d6f16eff2175.tar.gz bash-notes-1f4d77422386502ce5a67b101be6d6f16eff2175.zip | |
added showconf option. Fixed bug that prevented the rc file from being correctly sourced for GIT variables.
Diffstat (limited to 'SOURCE/CORE/git.sh')
| -rw-r--r-- | SOURCE/CORE/git.sh | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/SOURCE/CORE/git.sh b/SOURCE/CORE/git.sh index 8841521..bb51dc7 100644 --- a/SOURCE/CORE/git.sh +++ b/SOURCE/CORE/git.sh @@ -1,5 +1,5 @@ # check if GITCLIENT has been set or set it to the output of hostname -if [ -z $GITCLIENT ]; then +if [ -z "$GITCLIENT" ]; then GITCLIENT=$( hostname ) fi # returns true if the argument provided directory is a git repository @@ -16,22 +16,31 @@ is_git_repo() { } # sync local repository to remote +# accepts -f parameter to skip last sync check gitsync() { + FORCE=$1 if [[ $USEGIT && -n $GITREMOTE ]]; then - NOWSYNC=$(date +%s) - # LASTSYNC is the last time we synced to the remote, or 0 if it's the first time. - LASTSYNC=$($JQ -r '.git["lastpull"] // 0' "$DB") [ $PLAIN == false ] && echo "Syncing notes with git on remote \"$GITREMOTE\"" - SYNCDIFF=$(( ${NOWSYNC} - ${LASTSYNC} )) - if (( $SYNCDIFF > $GITSYNCDELAY )); then - #more than our delay time has passed. We can sync again. + NOWSYNC=$(date +%s) + if [[ $FORCE == "-f" ]]; then $JQ --arg n "$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB mv $TMPDB $DB cd $BASEDIR $GIT pull else - # Last synced less than $GITSYNCDELAY seconds ago. We shall wait - [ $PLAIN == false ] && echo "Last synced less than $GITSYNCDELAY seconds ago. We shall wait" + # LASTSYNC is the last time we synced to the remote, or 0 if it's the first time. + LASTSYNC=$($JQ -r '.git["lastpull"] // 0' "$DB") + SYNCDIFF=$(( ${NOWSYNC} - ${LASTSYNC} )) + if (( $SYNCDIFF > $GITSYNCDELAY )); then + #more than our delay time has passed. We can sync again. + $JQ --arg n "$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB + mv $TMPDB $DB + cd $BASEDIR + $GIT pull + else + # Last synced less than $GITSYNCDELAY seconds ago. We shall wait + [ $PLAIN == false ] && echo "Last synced less than $GITSYNCDELAY seconds ago. We shall wait" + fi fi else # no git, so we just keep going |
