diff options
| author | danix <danix@danix.xyz> | 2023-04-14 10:45:52 +0200 |
|---|---|---|
| committer | danix <danix@danix.xyz> | 2023-04-14 10:45:52 +0200 |
| commit | cf6d89bcf906ba72560847cb804646b9cd8d99b4 (patch) | |
| tree | 6289ed3edb8a5813395ec1f6d04bc51a81f3a7ff /SOURCE/CORE/git.sh | |
| parent | b1e2a0183a9b5b587968f2ab77ac5952331d1972 (diff) | |
| download | bash-notes-cf6d89bcf906ba72560847cb804646b9cd8d99b4.tar.gz bash-notes-cf6d89bcf906ba72560847cb804646b9cd8d99b4.zip | |
sync operations now check for last sync before running again. It's possible to set a delay between sync operations.
Diffstat (limited to 'SOURCE/CORE/git.sh')
| -rw-r--r-- | SOURCE/CORE/git.sh | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/SOURCE/CORE/git.sh b/SOURCE/CORE/git.sh index d37fe72..8edfc1f 100644 --- a/SOURCE/CORE/git.sh +++ b/SOURCE/CORE/git.sh @@ -13,9 +13,21 @@ is_git_repo() { # sync local repository to remote gitsync() { - echo "Syncing notes with git on remote \"$GITREMOTE\"" - cd $BASEDIR - $GIT pull + 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. + $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 } # check for USEGIT and subsequent variables |
